#include "container.h"
+#include "part.h"
using namespace std;
return new Child(*this, wdg);
}
+Geometry Container::determine_child_geometry(const Widget &child, const Part &part) const
+{
+ Geometry pgeom = part.get_geometry();
+ if(!pgeom.w || !pgeom.h)
+ {
+ Geometry cgeom;
+ child.autosize(cgeom);
+ if(!pgeom.w)
+ pgeom.w = cgeom.w;
+ if(!pgeom.h)
+ pgeom.h = cgeom.h;
+ }
+
+ part.get_alignment().apply(pgeom, geom, part.get_margin());
+ return pgeom;
+}
+
+void Container::autosize_child(const Widget &child, const Part &part, Geometry &ageom) const
+{
+ Geometry cgeom = determine_child_geometry(child, part);
+ const Sides &margin = part.get_margin();
+ ageom.w = max(ageom.w, cgeom.w+margin.left+margin.right);
+ ageom.h = max(ageom.h, cgeom.h+margin.top+margin.bottom);
+}
+
+void Container::reposition_child(Widget &child, const Part &part) const
+{
+ child.set_geometry(determine_child_geometry(child, part));
+}
+
list<Widget *> Container::get_children() const
{
list<Widget *> result;
void remove(Widget &);
protected:
virtual Child *create_child(Widget *);
+ Geometry determine_child_geometry(const Widget &, const Part &) const;
+ void autosize_child(const Widget &, const Part &, Geometry &) const;
+ void reposition_child(Widget &, const Part &) const;
public:
std::list<Widget *> get_children() const;
Widget *get_child_at(int, int);
ageom.h = max(ageom.h, line_height+margin.top+margin.bottom);
}
else if(part.get_name()=="slider" && multiline)
- {
- Geometry sgeom = part.get_geometry();
- if(!sgeom.w || !sgeom.h)
- {
- Geometry wgeom;
- slider->autosize(wgeom);
- if(!sgeom.w)
- sgeom.w = wgeom.w;
- if(!sgeom.h)
- sgeom.h = wgeom.h;
- }
-
- 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);
- }
+ autosize_child(*slider, part, ageom);
}
void Entry::set_text(const string &t)
add(*slider);
slider->set_step(1);
slider->signal_value_changed.connect(sigc::mem_fun(this, &Entry::slider_value_changed));
- reposition_slider();
+ rebuild();
}
check_view_range();
}
bld.matrix() *= GL::Matrix::translation(rgeom.x, rgeom.y, 0);
graphic->build(part.get_geometry().w, part.get_geometry().h, bld);
}
+ else if(part.get_name()=="slider")
+ {
+ if(multiline)
+ {
+ reposition_child(*slider, part);
+ Widget::rebuild_special(part);
+ }
+ }
else
Widget::rebuild_special(part);
}
void Entry::on_geometry_change()
{
- reposition_slider();
-
if(multiline)
check_view_range();
}
text_part = style->get_part("text");
- reposition_slider();
-
if(multiline)
check_view_range();
}
rebuild();
}
-void Entry::reposition_slider()
-{
- if(!style || !slider)
- return;
-
- if(const Part *slider_part = style->get_part("slider"))
- {
- Geometry sgeom = slider_part->get_geometry();
- if(!sgeom.w || !sgeom.h)
- {
- Geometry wgeom;
- slider->autosize(wgeom);
- if(!sgeom.w)
- sgeom.w = wgeom.w;
- if(!sgeom.h)
- sgeom.h = wgeom.h;
- }
-
- slider_part->get_alignment().apply(sgeom, geom, slider_part->get_margin());
- slider->set_geometry(sgeom);
- }
-}
-
void Entry::check_view_range()
{
if(!multiline || !text_part)
virtual void on_style_change();
void set_edit_position(unsigned);
- void reposition_slider();
void check_view_range();
void slider_value_changed(double);
};
ageom.w = max(ageom.w, max_w+margin.left+margin.right);
ageom.h = max(ageom.h, total_h+margin.top+margin.bottom);
}
+ else if(part.get_name()=="slider")
+ autosize_child(slider, part, ageom);
}
void List::set_data(ListData &d)
}
}
+void List::rebuild_special(const Part &part)
+{
+ if(part.get_name()=="slider")
+ reposition_child(slider, part);
+ Widget::rebuild_special(part);
+}
+
void List::render_special(const Part &part, GL::Renderer &renderer) const
{
if(part.get_name()=="items")
void List::on_geometry_change()
{
- reposition_slider();
reposition_items();
check_view_range();
if(!style)
return;
- reposition_slider();
reposition_items();
check_view_range();
}
-void List::reposition_slider()
-{
- if(!style)
- return;
-
- if(const Part *slider_part = style->get_part("slider"))
- {
- Geometry sgeom = slider_part->get_geometry();
- slider_part->get_alignment().apply(sgeom, geom, slider_part->get_margin());
- slider.set_geometry(sgeom);
- }
-}
-
void List::item_autosize_changed()
{
signal_autosize_changed.emit();
int get_selected_index() const { return sel_index; }
private:
+ virtual void rebuild_special(const Part &);
virtual void render_special(const Part &, GL::Renderer &) const;
public:
virtual void on_geometry_change();
virtual void on_style_change();
- void reposition_slider();
void item_autosize_changed();
void reposition_items();
void check_view_range();