]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/list.cpp
Refactor widget autosizing
[libs/gltk.git] / source / list.cpp
index c74af90d4541cb2185f2afc1f0d7a1bff8f6c172..b969ec038994bbe9d9609bf558b4d0b732e57ca4 100644 (file)
@@ -47,16 +47,11 @@ List::~List()
                delete data;
 }
 
-void List::autosize()
+void List::autosize_special(const Part &part, Geometry &ageom)
 {
-       if(!style)
-               return;
-
-       Widget::autosize();
-
-       if(const Part *items_part = style->get_part("items"))
+       if(part.get_name()=="items")
        {
-               const Sides &margin = items_part->get_margin();
+               const Sides &margin = part.get_margin();
 
                unsigned max_w = 0;
                unsigned total_h = 0;
@@ -72,12 +67,9 @@ void List::autosize()
                if(!items.empty() && items.size()<view_size)
                        total_h = total_h*view_size/items.size();
 
-               geom.w = max(geom.w, max_w+margin.left+margin.right);
-               geom.h = max(geom.h, total_h+margin.top+margin.bottom);
+               ageom.w = max(ageom.w, max_w+margin.left+margin.right);
+               ageom.h = max(ageom.h, total_h+margin.top+margin.bottom);
        }
-
-       check_view_range();
-       rebuild();
 }
 
 void List::set_data(ListData &d)
@@ -313,18 +305,16 @@ void List::DataObserver::refresh_strings()
 }
 
 
-void List::Item::autosize()
+void List::Item::autosize_special(const Part &part, Geometry &ageom)
 {
-       Widget::autosize();
-
-       if(const Part *part = style->get_part("children"))
+       if(part.get_name()=="children")
        {
-               const Sides &margin = part->get_margin();
+               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();
-                       geom.w = max(geom.w, cgeom.x+cgeom.w+margin.right);
-                       geom.h = max(geom.h, cgeom.y+cgeom.h+margin.top);
+                       ageom.w = max(ageom.w, cgeom.x+cgeom.w+margin.right);
+                       ageom.h = max(ageom.h, cgeom.y+cgeom.h+margin.top);
                }
        }
 }