From: Mikko Rasa Date: Sun, 14 Jul 2013 12:01:28 +0000 (+0300) Subject: Ensure that list items are autosized properly in all cases X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3ed9c4e3e26dbdce188c32d2dc63c3f921f053e3;p=libs%2Fgltk.git Ensure that list items are autosized properly in all cases --- diff --git a/source/list.cpp b/source/list.cpp index eaab9e0..b712574 100644 --- a/source/list.cpp +++ b/source/list.cpp @@ -65,7 +65,6 @@ void List::autosize_special(const Part &part, Geometry &ageom) unsigned total_h = 0; for(unsigned i=0; iautosize(); const Geometry &igeom = items[i]->get_geometry(); max_w = max(max_w, igeom.w); if(view_size==0 || icreate_item(index); + item = item_factory->create_item(index); else - return new BasicItem(data->get_string(index)); + item = new BasicItem(data->get_string(index)); + add(*item); + item->autosize(); + item->signal_autosize_changed.connect(sigc::bind(sigc::mem_fun(this, &List::item_autosize_changed), item)); + return item; } void List::set_view_size(unsigned s) @@ -207,6 +210,13 @@ void List::reposition_slider() } } +void List::item_autosize_changed(Item *item) +{ + signal_autosize_changed.emit(); + item->autosize(); + reposition_items(); +} + void List::reposition_items() { if(!style) @@ -298,7 +308,6 @@ void List::DataObserver::item_added(unsigned i) ++list.sel_index; Item *item = list.create_item(i); - list.add(*item); list.items.insert(list.items.begin()+i, item); list.items_changed(); } diff --git a/source/list.h b/source/list.h index 351b0a4..dd3ddaa 100644 --- a/source/list.h +++ b/source/list.h @@ -182,6 +182,7 @@ private: virtual void on_style_change(); void reposition_slider(); + void item_autosize_changed(Item *); void reposition_items(); void check_view_range(); void slider_value_changed(double);