void List::items_changed()
{
- check_view_range();
signal_autosize_changed.emit();
- reposition_items();
+ rebuild();
}
List::Item *List::create_item(unsigned index)
item = item_factory->create_item(index);
else
item = new BasicItem(data->get_string(index));
+ item->signal_autosize_changed.connect(sigc::bind(sigc::mem_fun(this, &List::item_autosize_changed), item));
add(*item);
- item->signal_autosize_changed.connect(sigc::mem_fun(this, &List::item_autosize_changed));
return item;
}
{
if(part.get_name()=="slider")
reposition_child(slider, part);
+ else if(part.get_name()=="items")
+ {
+ const Sides &margin = part.get_margin();
+ unsigned w = geom.w-min(geom.w, margin.left+margin.right);
+ unsigned y = geom.h-min(geom.h, margin.top);
+ for(unsigned i=0; i<items.size(); ++i)
+ {
+ if(i<first || !y)
+ items[i]->set_visible(false);
+ else
+ {
+ Geometry igeom = items[i]->get_geometry();
+ if(igeom.h+margin.bottom<=y)
+ {
+ items[i]->set_visible(true);
+ y -= igeom.h;
+ igeom.x = margin.left;
+ igeom.y = y;
+ igeom.w = w;
+ items[i]->set_geometry(igeom);
+ }
+ else
+ {
+ items[i]->set_visible(false);
+ y = 0;
+ }
+ }
+ }
+
+ check_view_range();
+ }
+
Widget::rebuild_special(part);
}
}
}
-void List::on_geometry_change()
-{
- reposition_items();
-
- check_view_range();
-}
-
-void List::on_style_change()
-{
- if(!style)
- return;
-
- reposition_items();
-
- check_view_range();
-}
-
-void List::item_autosize_changed()
+void List::item_autosize_changed(Item *item)
{
+ item->autosize();
signal_autosize_changed.emit();
- reposition_items();
-}
-
-void List::reposition_items()
-{
- if(!style)
- return;
-
- if(const Part *items_part = style->get_part("items"))
- {
- const Sides &margin = items_part->get_margin();
- unsigned w = geom.w-min(geom.w, margin.left+margin.right);
- unsigned y = geom.h-min(geom.h, margin.top);
- for(unsigned i=0; i<items.size(); ++i)
- {
- if(i<first || !y)
- items[i]->set_visible(false);
- else
- {
- Geometry igeom;
- items[i]->autosize(igeom);
- if(igeom.h+margin.bottom<=y)
- {
- items[i]->set_visible(true);
- y -= igeom.h;
- igeom.x = margin.left;
- igeom.y = y;
- igeom.w = w;
- items[i]->set_geometry(igeom);
- }
- else
- {
- items[i]->set_visible(false);
- y = 0;
- }
- }
- }
- }
+ rebuild();
}
void List::check_view_range()
if(max_scroll>0)
{
first = max_scroll-static_cast<unsigned>(value);
- reposition_items();
+ rebuild();
}
}
public:
virtual void button_press(int, int, unsigned);
-private:
- virtual void on_geometry_change();
- virtual void on_style_change();
- void item_autosize_changed();
- void reposition_items();
+private:
+ void item_autosize_changed(Item *);
void check_view_range();
void slider_value_changed(double);
};