]> git.tdb.fi Git - libs/gltk.git/commitdiff
Fix list autosizing logic
authorMikko Rasa <tdb@tdb.fi>
Wed, 6 Nov 2013 11:42:35 +0000 (13:42 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 6 Nov 2013 11:42:35 +0000 (13:42 +0200)
source/list.cpp
source/list.h

index 461d5e425c3076426f8ad51029ee971825cf396f..c5dddf5aaac8533c0f40bec86ed53f7e171c6e37 100644 (file)
@@ -65,7 +65,8 @@ void List::autosize_special(const Part &part, Geometry &ageom) const
                unsigned total_h = 0;
                for(unsigned i=0; i<items.size(); ++i)
                {
-                       const Geometry &igeom = items[i]->get_geometry();
+                       Geometry igeom;
+                       items[i]->autosize(igeom);
                        max_w = max(max_w, igeom.w);
                        if(view_size==0 || i<view_size)
                                total_h += igeom.h;
@@ -121,7 +122,7 @@ List::Item *List::create_item(unsigned 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));
+       item->signal_autosize_changed.connect(sigc::mem_fun(this, &List::item_autosize_changed));
        return item;
 }
 
@@ -213,10 +214,9 @@ void List::reposition_slider()
        }
 }
 
-void List::item_autosize_changed(Item *item)
+void List::item_autosize_changed()
 {
        signal_autosize_changed.emit();
-       item->autosize();
        reposition_items();
 }
 
@@ -228,15 +228,16 @@ void List::reposition_items()
        if(const Part *items_part = style->get_part("items"))
        {
                const Sides &margin = items_part->get_margin();
-               unsigned w = geom.w-margin.left-margin.right;
-               unsigned y = geom.h-margin.top;
+               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();
+                               Geometry igeom;
+                               items[i]->autosize(igeom);
                                if(igeom.h+margin.bottom<=y)
                                {
                                        items[i]->set_visible(true);
index 6f6aec1f9dcf50d2dd5b5ead0fb66db4790b5d72..0761caf63ed93858d20fd1cf7aabfea7888dfbb3 100644 (file)
@@ -182,7 +182,7 @@ private:
        virtual void on_style_change();
 
        void reposition_slider();
-       void item_autosize_changed(Item *);
+       void item_autosize_changed();
        void reposition_items();
        void check_view_range();
        void slider_value_changed(double);