Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorrachytski <siarhei.rachytski@gmail.com>2012-06-05 01:22:19 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:39:24 +0300
commiteddeffa5b7be4fe562ef0a302989d7af4e386ba6 (patch)
treedf3eaf49f1f6d7bdb266e008346353aa8a1b4284 /gui
parent95c4ede478d673d0feb4fb3b574d95b5adf77b81 (diff)
using TextView inside Button to draw text uniformly.
Diffstat (limited to 'gui')
-rw-r--r--gui/button.cpp80
-rw-r--r--gui/button.hpp28
-rw-r--r--gui/element.hpp4
-rw-r--r--gui/text_view.cpp15
-rw-r--r--gui/text_view.hpp3
5 files changed, 89 insertions, 41 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);
}
}
diff --git a/gui/button.hpp b/gui/button.hpp
index 5c3ec98bc6..5eedad1ad8 100644
--- a/gui/button.hpp
+++ b/gui/button.hpp
@@ -1,9 +1,11 @@
#pragma once
#include "element.hpp"
+#include "text_view.hpp"
#include "../std/function.hpp"
#include "../std/string.hpp"
+#include "../std/scoped_ptr.hpp"
namespace yg
{
@@ -27,18 +29,19 @@ namespace gui
TOnClickListener m_OnClickListener;
- unsigned m_widthInDIP;
- unsigned m_heightInDIP;
+ unsigned m_minWidth;
+ unsigned m_minHeight;
+
+ scoped_ptr<TextView> m_textView;
- string m_text;
mutable vector<m2::AnyRectD> m_boundRects;
public:
struct Params : Element::Params
{
- unsigned m_width;
- unsigned m_height;
+ unsigned m_minWidth;
+ unsigned m_minHeight;
string m_text;
};
@@ -51,19 +54,24 @@ namespace gui
void setOnClickListener(TOnClickListener const & l);
+ void setPivot(m2::PointD const & pv);
+ void setFont(EState state, yg::FontDesc const & font);
+ void setColor(EState state, yg::Color const & c);
+
void setText(string const & text);
string const & text() const;
- void setWidth(unsigned widthInDIP);
- unsigned width() const;
+ void setMinWidth(unsigned minWidthInDIP);
+ unsigned minWidth() const;
+
+ void setMinHeight(unsigned minHeightInDIP);
+ unsigned minHeight() const;
- void setHeight(unsigned heightInDIP);
- unsigned height() const;
+ void setController(Controller * controller);
/// Inherited from OverlayElement
/// @{
- yg::OverlayElement * clone(math::Matrix<double, 3, 3> const & m) const;
vector<m2::AnyRectD> const & boundRects() const;
void draw(yg::gl::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const;
diff --git a/gui/element.hpp b/gui/element.hpp
index 201f3feb61..8efbbae5d3 100644
--- a/gui/element.hpp
+++ b/gui/element.hpp
@@ -52,10 +52,10 @@ namespace gui
void setState(EState state);
EState state() const;
- void setFont(EState state, yg::FontDesc const & font);
+ virtual void setFont(EState state, yg::FontDesc const & font);
yg::FontDesc const & font(EState state) const;
- void setColor(EState state, yg::Color const & c);
+ virtual void setColor(EState state, yg::Color const & c);
yg::Color const & color(EState state) const;
/// Implement this method to handle single tap on the GUI element.
diff --git a/gui/text_view.cpp b/gui/text_view.cpp
index 17f960b9f5..68ec235b3c 100644
--- a/gui/text_view.cpp
+++ b/gui/text_view.cpp
@@ -17,8 +17,12 @@ namespace gui
void TextView::setText(string const & text)
{
- m_text = text;
- setIsDirtyDrawing(true);
+ if (m_text != text)
+ {
+ m_text = text;
+ setIsDirtyDrawing(true);
+ setIsDirtyRect(true);
+ }
}
string const & TextView::text() const
@@ -44,12 +48,7 @@ namespace gui
m_elem.reset(new yg::StraightTextElement(params));
}
- yg::OverlayElement * TextView::clone(math::Matrix<double, 3, 3> const & m) const
- {
- return new TextView(*this);
- }
-
- void TextView::draw(yg::gl::OverlayRenderer *r, const math::Matrix<double, 3, 3> &m)
+ void TextView::draw(yg::gl::OverlayRenderer *r, math::Matrix<double, 3, 3> const & m) const
{
checkDirtyDrawing();
m_elem->draw(r, m);
diff --git a/gui/text_view.hpp b/gui/text_view.hpp
index 9d8fcd7890..459089e7b9 100644
--- a/gui/text_view.hpp
+++ b/gui/text_view.hpp
@@ -35,9 +35,8 @@ namespace gui
void setText(string const & text);
string const & text() const;
- yg::OverlayElement * clone(math::Matrix<double, 3, 3> const & m) const;
vector<m2::AnyRectD> const & boundRects() const;
- void draw(yg::gl::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m);
+ void draw(yg::gl::OverlayRenderer * r, math::Matrix<double, 3, 3> const & m) const;
bool onTapStarted(m2::PointD const & pt);
bool onTapMoved(m2::PointD const & pt);