]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/list.cpp
Fix some more inefficient autosizes
[libs/gltk.git] / source / list.cpp
index 653a40c92bc1195e7b75276a50f08fc37891ff29..a4550c4ee9ad220dfd22336657894b9cca13de9a 100644 (file)
@@ -55,7 +55,7 @@ List::~List()
                delete data;
 }
 
-void List::autosize_special(const Part &part, Geometry &ageom)
+void List::autosize_special(const Part &part, Geometry &ageom) const
 {
        if(part.get_name()=="items")
        {
@@ -65,7 +65,8 @@ void List::autosize_special(const Part &part, Geometry &ageom)
                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;
@@ -120,8 +121,7 @@ List::Item *List::create_item(unsigned index)
        else
                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 +213,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 +227,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);
@@ -344,14 +344,15 @@ void List::DataObserver::refresh_item(unsigned i)
 }
 
 
-void List::Item::autosize_special(const Part &part, Geometry &ageom)
+void List::Item::autosize_special(const Part &part, Geometry &ageom) const
 {
        if(part.get_name()=="children")
        {
                const Sides &margin = part.get_margin();
                for(list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
                {
-                       const Geometry &cgeom = (*i)->widget->get_geometry();
+                       Geometry cgeom;
+                       (*i)->widget->autosize(cgeom);
                        ageom.w = max(ageom.w, cgeom.x+cgeom.w+margin.right);
                        ageom.h = max(ageom.h, cgeom.y+cgeom.h+margin.top);
                }