set_text(t);
}
-void Button::autosize()
+void Button::autosize_special(const Part &part, Geometry &ageom)
{
- if(!style)
- return;
-
- Widget::autosize();
-
- if(const Part *text_part = style->get_part("text"))
- {
- const Sides &margin = text_part->get_margin();
- geom.w = max(geom.w, text.get_width()+margin.left+margin.right);
- geom.h = max(geom.h, text.get_height()+margin.top+margin.bottom);
- }
-
- if(icon)
+ if(part.get_name()=="text")
+ text.autosize(part, ageom);
+ else if(part.get_name()=="icon" && icon)
{
- if(const Part *icon_part = style->get_part("icon"))
- {
- const Sides &margin = icon_part->get_margin();
- geom.w = max(geom.w, icon->get_width()+margin.left+margin.right);
- geom.h = max(geom.h, icon->get_height()+margin.top+margin.bottom);
- }
+ const Sides &margin = part.get_margin();
+ ageom.w = max(ageom.w, icon->get_width()+margin.left+margin.right);
+ ageom.h = max(ageom.h, icon->get_height()+margin.top+margin.bottom);
}
-
- rebuild();
}
void Button::set_text(const std::string &t)
virtual const char *get_class() const { return "button"; }
- virtual void autosize();
+private:
+ virtual void autosize_special(const Part &, Geometry &);
+public:
void set_text(const std::string &);
void set_icon(const GL::Texture2D *);
list.signal_autosize_changed.connect(sigc::mem_fun(this, &Dropdown::list_autosize_changed));
}
-void Dropdown::autosize()
+void Dropdown::autosize_special(const Part &part, Geometry &ageom)
{
- if(!style)
- return;
-
- Widget::autosize();
- list.autosize();
- geom.w = max(geom.w, list.get_geometry().w);
-
- if(const Part *text_part = style->get_part("text"))
+ if(part.get_name()=="list")
+ {
+ list.autosize();
+ ageom.w = max(ageom.w, list.get_geometry().w);
+ }
+ else if(part.get_name()=="text")
{
- const Sides &margin = text_part->get_margin();
+ const Sides &margin = part.get_margin();
const GL::Font &font = style->get_font();
float font_size = style->get_font_size();
unsigned w = static_cast<unsigned>(font.get_string_width(data.get_string(i))*font_size);
max_w = max(max_w, w);
}
- geom.w = max(geom.w, max_w+margin.left+margin.right);
+ ageom.w = max(ageom.w, max_w+margin.left+margin.right);
unsigned line_height = static_cast<unsigned>((font.get_ascent()-font.get_descent())*font_size);
- geom.h = max(geom.h, line_height+margin.top+margin.bottom);
+ ageom.h = max(ageom.h, line_height+margin.top+margin.bottom);
}
rebuild();
public:
virtual const char *get_class() const { return "dropdown"; }
- virtual void autosize();
+private:
+ virtual void autosize_special(const Part &, Geometry &);
+public:
void set_data(ListData &d) { list.set_data(d); }
ListData &get_data() { return list.get_data(); }
const ListData &get_data() const { return list.get_data(); }
set_text(t);
}
-void Entry::autosize()
+void Entry::autosize_special(const Part &part, Geometry &ageom)
{
- if(!style)
- return;
-
- Widget::autosize();
-
- if(text_part)
+ if(part.get_name()=="text")
{
- const Sides &margin = text_part->get_margin();
+ const Sides &margin = part.get_margin();
const GL::Font &font = style->get_font();
unsigned en_width = static_cast<unsigned>(font.get_string_width("n")*style->get_font_size());
- geom.w = max(geom.w, edit_width*en_width+margin.left+margin.right);
+ ageom.w = max(ageom.w, edit_width*en_width+margin.left+margin.right);
unsigned line_height = static_cast<unsigned>((font.get_ascent()-font.get_descent())*style->get_font_size());
if(multiline)
{
unsigned line_spacing = style->get_font_size()*6/5;
- geom.h = max(geom.h, line_height+line_spacing*(edit_height-1)+margin.top+margin.bottom);
+ ageom.h = max(ageom.h, line_height+line_spacing*(edit_height-1)+margin.top+margin.bottom);
}
else
- geom.h = max(geom.h, line_height+margin.top+margin.bottom);
+ ageom.h = max(ageom.h, line_height+margin.top+margin.bottom);
}
-
- if(multiline)
+ else if(part.get_name()=="slider" && multiline)
{
- if(const Part *slider_part = style->get_part("slider"))
+ Geometry sgeom = part.get_geometry();
+ if(!sgeom.w || !sgeom.h)
{
- Geometry sgeom = slider_part->get_geometry();
- if(!sgeom.w || !sgeom.h)
- {
- slider->autosize();
- if(!sgeom.w)
- sgeom.w = slider->get_geometry().w;
- if(!sgeom.h)
- sgeom.h = slider->get_geometry().h;
- }
-
- const Sides &margin = slider_part->get_margin();
- geom.w = max(geom.w, sgeom.w+margin.left+margin.right);
- geom.h = max(geom.h, sgeom.h+margin.top+margin.bottom);
-
- reposition_slider();
+ slider->autosize();
+ if(!sgeom.w)
+ sgeom.w = slider->get_geometry().w;
+ if(!sgeom.h)
+ sgeom.h = slider->get_geometry().h;
}
- check_view_range();
+ const Sides &margin = part.get_margin();
+ ageom.w = max(ageom.w, sgeom.w+margin.left+margin.right);
+ ageom.h = max(ageom.h, sgeom.h+margin.top+margin.bottom);
}
-
- rebuild();
}
void Entry::set_text(const string &t)
virtual const char *get_class() const { return "entry"; }
- virtual void autosize();
+private:
+ virtual void autosize_special(const Part &, Geometry &);
+public:
void set_text(const std::string &);
const std::string &get_text() const { return text.get(); }
slider_size(1)
{ }
-void HSlider::autosize()
+void HSlider::autosize_special(const Part &part, Geometry &ageom)
{
- if(!style)
- return;
-
- Widget::autosize();
-
- if(const Part *slider_part = style->get_part("slider"))
+ if(part.get_name()=="slider")
{
- const Sides &margin = slider_part->get_margin();
- const Geometry &pgeom = slider_part->get_geometry();
- geom.w = std::max(geom.w, pgeom.w*3/2+margin.left+margin.right);
- geom.h = std::max(geom.h, pgeom.h+margin.top+margin.bottom);
+ const Sides &margin = part.get_margin();
+ const Geometry &pgeom = part.get_geometry();
+ ageom.w = std::max(ageom.w, pgeom.w*3/2+margin.left+margin.right);
+ ageom.h = std::max(ageom.h, pgeom.h+margin.top+margin.bottom);
}
}
virtual const char *get_class() const { return "hslider"; }
- virtual void autosize();
-
private:
+ virtual void autosize_special(const Part &, Geometry &);
virtual void rebuild_special(const Part &);
public:
focusable = false;
}
-void Image::autosize()
+void Image::autosize_special(const Part &part, Geometry &ageom)
{
- if(!style)
- return;
-
- Widget::autosize();
-
- if(const Part *image_part = style->get_part("image"))
+ if(part.get_name()=="image")
{
- const Sides &margin = image_part->get_margin();
+ const Sides &margin = part.get_margin();
if(image)
{
- geom.w = max(geom.w, image->get_width()+margin.left+margin.right);
- geom.h = max(geom.h, image->get_height()+margin.top+margin.bottom);
+ ageom.w = max(ageom.w, image->get_width()+margin.left+margin.right);
+ ageom.h = max(ageom.h, image->get_height()+margin.top+margin.bottom);
}
else
{
- geom.w = max(geom.w, margin.left+margin.right);
- geom.h = max(geom.h, margin.top+margin.bottom);
+ ageom.w = max(ageom.w, margin.left+margin.right);
+ ageom.h = max(ageom.h, margin.top+margin.bottom);
}
}
-
- rebuild();
}
void Image::set_image(const GL::Texture2D *i)
virtual const char *get_class() const { return "image"; }
- virtual void autosize();
+private:
+ virtual void autosize_special(const Part &, Geometry &);
+public:
void set_image(const GL::Texture2D *);
void set_keep_aspect(bool);
set_text(t);
}
-void Label::autosize()
-{
- if(!style)
- return;
-
- Widget::autosize();
-
- if(const Part *text_part = style->get_part("text"))
- {
- const Sides &margin = text_part->get_margin();
- geom.w = max(geom.w, text.get_width()+margin.left+margin.right);
- geom.h = max(geom.h, text.get_height()+margin.top+margin.bottom);
- }
-
- rebuild();
-}
-
void Label::set_text(const string &t)
{
text = t;
rebuild();
}
+void Label::autosize_special(const Part &part, Geometry &ageom)
+{
+ if(part.get_name()=="text")
+ text.autosize(part, ageom);
+}
+
void Label::rebuild_special(const Part &part)
{
if(part.get_name()=="text")
virtual const char *get_class() const { return "label"; }
- virtual void autosize();
void set_text(const std::string &);
private:
+ virtual void autosize_special(const Part &, Geometry &);
virtual void rebuild_special(const Part &);
virtual void on_style_change();
(*i)->widget.set_geometry((*i)->geom);
}
-void Layout::autosize()
+void Layout::autosize(Geometry &geom)
{
solve_constraints(HORIZONTAL, AUTOSIZE);
solve_constraints(VERTICAL, AUTOSIZE);
- container->set_size(autosize_geom.w, autosize_geom.h);
+ geom.w = max(geom.w, autosize_geom.w);
+ geom.h = max(geom.h, autosize_geom.h);
}
void Layout::solve_constraints(int dir, SolveMode mode)
void set_ghost(Widget &, bool);
void update();
- void autosize();
+ void autosize(Geometry &);
private:
void solve_constraints(int, SolveMode);
delete data;
}
-void List::autosize()
+void List::autosize_special(const Part &part, Geometry &ageom)
{
- if(!style)
- return;
-
- Widget::autosize();
-
- if(const Part *items_part = style->get_part("items"))
+ if(part.get_name()=="items")
{
- const Sides &margin = items_part->get_margin();
+ const Sides &margin = part.get_margin();
unsigned max_w = 0;
unsigned total_h = 0;
if(!items.empty() && items.size()<view_size)
total_h = total_h*view_size/items.size();
- geom.w = max(geom.w, max_w+margin.left+margin.right);
- geom.h = max(geom.h, total_h+margin.top+margin.bottom);
+ ageom.w = max(ageom.w, max_w+margin.left+margin.right);
+ ageom.h = max(ageom.h, total_h+margin.top+margin.bottom);
}
-
- check_view_range();
- rebuild();
}
void List::set_data(ListData &d)
}
-void List::Item::autosize()
+void List::Item::autosize_special(const Part &part, Geometry &ageom)
{
- Widget::autosize();
-
- if(const Part *part = style->get_part("children"))
+ if(part.get_name()=="children")
{
- const Sides &margin = part->get_margin();
+ const Sides &margin = part.get_margin();
for(list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
{
const Geometry &cgeom = (*i)->widget->get_geometry();
- geom.w = max(geom.w, cgeom.x+cgeom.w+margin.right);
- geom.h = max(geom.h, cgeom.y+cgeom.h+margin.top);
+ ageom.w = max(ageom.w, cgeom.x+cgeom.w+margin.right);
+ ageom.h = max(ageom.h, cgeom.y+cgeom.h+margin.top);
}
}
}
public:
virtual const char *get_class() const { return "listitem"; }
- virtual void autosize();
+ protected:
+ virtual void autosize_special(const Part &, Geometry &);
+ public:
void set_active(bool);
virtual void render_special(const Part &, GL::Renderer &) const;
virtual const char *get_class() const { return "list"; }
- virtual void autosize();
+private:
+ virtual void autosize_special(const Part &, Geometry &);
+public:
void set_data(ListData &);
ListData &get_data() { return *data; }
const ListData &get_data() const { return *data; }
layout = l;
}
-void Panel::autosize()
+void Panel::autosize_special(const Part &part, Geometry &ageom)
{
- if(layout)
- layout->autosize();
+ if(part.get_name()=="children" && layout)
+ layout->autosize(ageom);
}
void Panel::render_special(const Part &part, GL::Renderer &renderer) const
virtual const char *get_class() const { return "panel"; }
void set_layout(Layout *);
- virtual void autosize();
protected:
+ virtual void autosize_special(const Part &, Geometry &);
virtual void render_special(const Part &, GL::Renderer &) const;
virtual void on_geometry_change();
return line_height+(lines.size()-1)*line_spacing;
}
+void Text::autosize(const Part &part, Geometry &geom) const
+{
+ const Sides &margin = part.get_margin();
+ geom.w = max(geom.w, get_width()+margin.left+margin.right);
+ geom.h = max(geom.h, get_height()+margin.top+margin.bottom);
+}
+
void Text::set(const string &t)
{
text = t;
unsigned get_width() const;
unsigned get_height() const;
+ void autosize(const Part &, Geometry &) const;
void set(const std::string &);
void erase(unsigned, unsigned);
set_text(t);
}
-void Toggle::autosize()
+void Toggle::autosize_special(const Part &part, Geometry &ageom)
{
- if(!style)
- return;
-
- Widget::autosize();
-
- if(const Part *text_part = style->get_part("text"))
- {
- const Sides &margin = text_part->get_margin();
- geom.w = max(geom.w, text.get_width()+margin.left+margin.right);
- geom.h = max(geom.h, text.get_height()+margin.top+margin.bottom);
- }
-
- rebuild();
+ if(part.get_name()=="text")
+ text.autosize(part, ageom);
}
void Toggle::set_text(const string &t)
virtual const char *get_class() const { return "toggle"; }
- virtual void autosize();
+private:
+ virtual void autosize_special(const Part &, Geometry &);
+public:
void set_text(const std::string &);
void set_exclusive(bool);
bool get_exclusive() const { return exclusive; }
slider_size(1)
{ }
-void VSlider::autosize()
+void VSlider::autosize_special(const Part &part, Geometry &ageom)
{
- if(!style)
- return;
-
- Widget::autosize();
-
- if(const Part *slider_part = style->get_part("slider"))
+ if(part.get_name()=="slider")
{
- const Sides &margin = slider_part->get_margin();
- const Geometry &pgeom = slider_part->get_geometry();
- geom.w = std::max(geom.w, pgeom.w+margin.left+margin.right);
- geom.h = std::max(geom.h, pgeom.h*3/2+margin.top+margin.bottom);
+ const Sides &margin = part.get_margin();
+ const Geometry &pgeom = part.get_geometry();
+ ageom.w = std::max(ageom.w, pgeom.w+margin.left+margin.right);
+ ageom.h = std::max(ageom.h, pgeom.h*3/2+margin.top+margin.bottom);
}
}
virtual const char *get_class() const { return "vslider"; }
- virtual void autosize();
-
private:
+ virtual void autosize_special(const Part &, Geometry &);
virtual void rebuild_special(const Part &);
public:
if(!style)
return;
- geom.w = 0;
- geom.h = 0;
+ Geometry ageom;
const Style::PartSeq &parts = style->get_parts();
for(Style::PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+ {
if(i->get_name().empty())
{
const Geometry &pgeom = i->get_geometry();
const Sides &pmargin = i->get_margin();
- geom.w = max(geom.w, pgeom.w+pmargin.left+pmargin.right);
- geom.h = max(geom.h, pgeom.h+pmargin.top+pmargin.bottom);
+ ageom.w = max(ageom.w, pgeom.w+pmargin.left+pmargin.right);
+ ageom.h = max(ageom.h, pgeom.h+pmargin.top+pmargin.bottom);
}
+ else
+ autosize_special(*i, ageom);
+ }
+
+ set_geometry(ageom);
}
void Widget::set_geometry(const Geometry &g)
void set_position(int, int);
void set_size(unsigned, unsigned);
- virtual void autosize();
+ void autosize();
+protected:
+ virtual void autosize_special(const Part &, Geometry &) { }
+public:
void set_geometry(const Geometry &);
const Geometry &get_geometry() const { return geom; }