From: Mikko Rasa Date: Mon, 12 Apr 2010 20:49:41 +0000 (+0000) Subject: Update text information when widget style changes X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=a87d05583cb7dffaf0e0f5eb9f9b2fc0bcf656e1;p=libs%2Fgltk.git Update text information when widget style changes --- diff --git a/source/button.cpp b/source/button.cpp index 91cc88c..292625d 100644 --- a/source/button.cpp +++ b/source/button.cpp @@ -92,6 +92,11 @@ void Button::render_special(const Part &part) const } } +void Button::on_style_change() +{ + text.update_style(); +} + Button::Loader::Loader(Button &btn): Widget::Loader(btn) diff --git a/source/button.h b/source/button.h index 31d87e1..687f5dd 100644 --- a/source/button.h +++ b/source/button.h @@ -48,6 +48,8 @@ public: private: virtual const char *get_class() const { return "button"; } virtual void render_special(const Part &) const; + + virtual void on_style_change(); }; } // namespace GLtk diff --git a/source/entry.cpp b/source/entry.cpp index f503721..496a79d 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -84,6 +84,11 @@ void Entry::render_special(const Part &part) const } } +void Entry::on_style_change() +{ + text.update_style(); +} + Entry::Loader::Loader(Entry &ent): Widget::Loader(ent) diff --git a/source/entry.h b/source/entry.h index b8bae56..7355067 100644 --- a/source/entry.h +++ b/source/entry.h @@ -47,6 +47,8 @@ public: private: virtual const char *get_class() const { return "entry"; } virtual void render_special(const Part &) const; + + virtual void on_style_change(); }; } // namespace GLtk diff --git a/source/label.cpp b/source/label.cpp index 2353385..18bef1a 100644 --- a/source/label.cpp +++ b/source/label.cpp @@ -52,6 +52,11 @@ void Label::render_special(const Part &part) const text.render(part, geom); } +void Label::on_style_change() +{ + text.update_style(); +} + Label::Loader::Loader(Label &l): Widget::Loader(l) diff --git a/source/label.h b/source/label.h index f492006..f157616 100644 --- a/source/label.h +++ b/source/label.h @@ -40,6 +40,8 @@ public: private: virtual const char *get_class() const { return "label"; } virtual void render_special(const Part &) const; + + virtual void on_style_change(); }; } // namespace GLtk diff --git a/source/text.cpp b/source/text.cpp index e33eb80..d48c33f 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -77,6 +77,13 @@ void Text::insert(unsigned pos, const string &s) } } +void Text::update_style() +{ + float font_size=style->get_font()->get_default_size(); + for(vector::iterator i=lines.begin(); i!=lines.end(); ++i) + i->width=static_cast(style->get_font()->get_string_width(text.substr(i->start, i->length))*font_size); +} + void Text::render(const Part &part, const Geometry &geom) const { if(lines.empty()) diff --git a/source/text.h b/source/text.h index 5daeb9b..7be1192 100644 --- a/source/text.h +++ b/source/text.h @@ -41,6 +41,8 @@ public: const std::string &get() const { return text; } unsigned size() const { return text.size(); } + void update_style(); + void render(const Part &, const Geometry &) const; Text &operator=(const std::string &); diff --git a/source/toggle.cpp b/source/toggle.cpp index 550d97a..62f46eb 100644 --- a/source/toggle.cpp +++ b/source/toggle.cpp @@ -85,6 +85,11 @@ void Toggle::exclude_siblings() tgl->set_value(false); } +void Toggle::on_style_change() +{ + text.update_style(); +} + Toggle::Loader::Loader(Toggle &t): Widget::Loader(t) diff --git a/source/toggle.h b/source/toggle.h index f9a32fe..da129be 100644 --- a/source/toggle.h +++ b/source/toggle.h @@ -55,6 +55,8 @@ private: virtual void render_special(const Part &) const; void exclude_siblings(); + + virtual void on_style_change(); }; } // namespace GLtk