Button::Button(const Resources &r, const std::string &t):
Widget(r),
- text(style),
+ text(),
icon(0),
pressed(false)
{
void Button::on_style_change()
{
- text.update_style();
+ text.set_style(style);
}
if(part.get_name()=="text")
{
if(list.get_selected_index()>=0)
- Text(style, list.get_selected()).render(part, geom);
+ Text(*style, list.get_selected()).render(part, geom);
}
else if(part.get_name()=="list" && dropped)
list.render();
Entry::Entry(const Resources &r, const string &t):
Widget(r),
- text(style),
+ text(),
edit_pos(0)
{
update_style();
void Entry::on_style_change()
{
- text.update_style();
+ text.set_style(style);
}
Label::Label(const Resources &r, const string &t):
Widget(r),
- text(style)
+ text()
{
focusable=false;
update_style();
void Label::on_style_change()
{
- text.update_style();
+ text.set_style(style);
}
namespace Msp {
namespace GLtk {
-Text::Text(const Style *const &s):
- style(s)
+Text::Text():
+ style(0)
{ }
-Text::Text(const Style *const &s, const string &t):
- style(s)
+Text::Text(const Style &s, const string &t):
+ style(&s)
{
set(t);
}
+void Text::set_style(const Style *s)
+{
+ style = s;
+
+ float font_size=style->get_font()->get_default_size();
+ for(vector<Line>::iterator i=lines.begin(); i!=lines.end(); ++i)
+ i->width=static_cast<unsigned>(style->get_font()->get_string_width(text.substr(i->start, i->length))*font_size);
+}
+
unsigned Text::get_width() const
{
unsigned width=0;
}
}
-void Text::update_style()
-{
- float font_size=style->get_font()->get_default_size();
- for(vector<Line>::iterator i=lines.begin(); i!=lines.end(); ++i)
- i->width=static_cast<unsigned>(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())
unsigned width;
};
- const Style *const &style;
+ const Style *style;
std::string text;
std::vector<Line> lines;
public:
- Text(const Style *const &);
- Text(const Style *const &, const std::string &);
+ Text();
+ Text(const Style &, const std::string &);
+
+ void set_style(const Style *);
unsigned get_width() const;
unsigned get_height() const;
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 &);
Toggle::Toggle(const Resources &r, const string &t):
Widget(r),
- text(style),
+ text(),
pressed(false),
value(false),
exclusive(false)
void Toggle::on_style_change()
{
- text.update_style();
+ text.set_style(style);
}