diff options
author | rachytski <siarhei.rachytski@gmail.com> | 2012-06-05 01:22:19 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:39:24 +0300 |
commit | eddeffa5b7be4fe562ef0a302989d7af4e386ba6 (patch) | |
tree | df3eaf49f1f6d7bdb266e008346353aa8a1b4284 /gui/button.cpp | |
parent | 95c4ede478d673d0feb4fb3b574d95b5adf77b81 (diff) |
using TextView inside Button to draw text uniformly.
Diffstat (limited to 'gui/button.cpp')
-rw-r--r-- | gui/button.cpp | 80 |
1 files changed, 61 insertions, 19 deletions
diff --git a/gui/button.cpp b/gui/button.cpp index dd1ac461c9..d9b79e9915 100644 --- a/gui/button.cpp +++ b/gui/button.cpp @@ -5,8 +5,17 @@ namespace gui { Button::Button(Params const & p) : Element(p) { - setWidth(p.m_width); - setHeight(p.m_height); + TextView::Params tp; + + tp.m_depth = p.m_depth + 1; + tp.m_pivot = p.m_pivot; + tp.m_position = yg::EPosCenter; + tp.m_text = p.m_text; + + m_textView.reset(new TextView(tp)); + + setMinWidth(p.m_minWidth); + setMinHeight(p.m_minHeight); setText(p.m_text); setFont(EActive, yg::FontDesc(12, yg::Color(0, 0, 0, 255))); @@ -52,39 +61,40 @@ namespace gui void Button::setText(string const & text) { - m_text = text; + m_textView->setText(text); } string const & Button::text() const { - return m_text; + return m_textView->text(); } - void Button::setWidth(unsigned widthInDIP) + void Button::setMinWidth(unsigned minWidth) { - m_widthInDIP = widthInDIP; + m_minWidth = minWidth; invalidate(); } - unsigned Button::width() const + unsigned Button::minWidth() const { - return m_widthInDIP; + return m_minWidth; } - void Button::setHeight(unsigned heightInDIP) + void Button::setMinHeight(unsigned minHeight) { - m_heightInDIP = heightInDIP; + m_minHeight = minHeight; invalidate(); } - unsigned Button::height() const + unsigned Button::minHeight() const { - return m_heightInDIP; + return m_minHeight; } - yg::OverlayElement * Button::clone(math::Matrix<double, 3, 3> const & m) const + void Button::setController(Controller *controller) { - return new Button(*this); + m_textView->setController(controller); + Element::setController(controller); } vector<m2::AnyRectD> const & Button::boundRects() const @@ -93,7 +103,23 @@ namespace gui { m_boundRects.clear(); double k = visualScale(); - m2::RectD rc(0, 0, width() * k, height() * k); + + m2::RectD tr(m_textView->roughBoundRect()); + m2::RectD rc(0, 0, tr.SizeX(), tr.SizeY()); + + rc.Inflate(20 * k, 10 * k); + + double dx = 0; + double dy = 0; + + if (rc.SizeX() < m_minWidth * k) + dx = (m_minWidth * k - rc.SizeX()) / 2; + if (rc.SizeY() < m_minHeight * k) + dy = (m_minHeight * k - rc.SizeY()) / 2; + + rc.Inflate(dx, dy); + rc.Offset(-rc.minX(), -rc.minY()); + rc.Offset(tieRect(rc, math::Identity<double, 3>())); m_boundRects.push_back(m2::AnyRectD(rc)); setIsDirtyRect(false); @@ -109,13 +135,29 @@ namespace gui double k = visualScale(); - m2::RectD rc(0, 0, width() * k, height() * k); - rc.Offset(tieRect(rc, m)); - r->drawRoundedRectangle(rc, 10 * k, color(state()), depth() - 1); + r->drawRoundedRectangle(roughBoundRect(), 10 * k, color(state()), depth()); yg::FontDesc desc = font(state()); desc.m_size *= k; - r->drawText(desc, pivot(), position(), text(), depth(), false, false); + m_textView->draw(r, m); + } + + void Button::setPivot(m2::PointD const &pv) + { + m_textView->setPivot(pv); + Element::setPivot(pv); + } + + void Button::setFont(EState state, yg::FontDesc const & font) + { + m_textView->setFont(state, font); + Element::setFont(state, font); + } + + void Button::setColor(EState state, yg::Color const & c) + { + m_textView->setColor(state, c); + Element::setColor(state, c); } } |