]> git.tdb.fi Git - libs/gltk.git/commitdiff
Ensure that list items are autosized properly in all cases
authorMikko Rasa <tdb@tdb.fi>
Sun, 14 Jul 2013 12:01:28 +0000 (15:01 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 14 Jul 2013 12:01:28 +0000 (15:01 +0300)
source/list.cpp
source/list.h

index eaab9e0e5ed8857a0bdaea7e779374577efbf7da..b712574d3992f9a0a5c3406837206e6ed1204542 100644 (file)
@@ -65,7 +65,6 @@ void List::autosize_special(const Part &part, Geometry &ageom)
                unsigned total_h = 0;
                for(unsigned i=0; i<items.size(); ++i)
                {
-                       items[i]->autosize();
                        const Geometry &igeom = items[i]->get_geometry();
                        max_w = max(max_w, igeom.w);
                        if(view_size==0 || i<view_size)
@@ -100,7 +99,6 @@ void List::set_data(ListData &d)
        for(unsigned i=0; i<n_items; ++i)
        {
                Item *item = create_item(i);
-               add(*item);
                items.push_back(item);
        }
 
@@ -116,10 +114,15 @@ void List::items_changed()
 
 List::Item *List::create_item(unsigned index)
 {
+       Item *item = 0; 
        if(item_factory)
-               return item_factory->create_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();
 }
index 351b0a461e27aed15c0d271835317301926b70aa..dd3ddaa6d5e12100deff93187e068af07eaf1ceb 100644 (file)
@@ -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);