]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/list.cpp
Improve widget part caching
[libs/gltk.git] / source / list.cpp
index 378bf707c1a7d702f2192d50b0da8cd2ea70d9bc..710d1fc6fa7cf7c05e2fe88e5c6349aa018cf298 100644 (file)
@@ -64,15 +64,16 @@ void List::autosize_rows(unsigned n)
 
                unsigned max_w = 0;
                unsigned total_h = 0;
-               for(unsigned i=0; (i<n && i<items.size()); ++i)
+               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);
-                       total_h += igeom.h;
+                       if(i<n)
+                               total_h += igeom.h;
                }
 
-               if(items.size()<n)
+               if(!items.empty() && items.size()<n)
                        total_h = total_h*n/items.size();
 
                geom.w = max(geom.w, max_w+margin.left+margin.right);
@@ -310,13 +311,6 @@ void List::DataObserver::refresh_strings()
 }
 
 
-List::Loader::Loader(List &l):
-       Widget::Loader(l)
-{
-       add("item", &Loader::item);
-}
-
-
 void List::Item::autosize()
 {
        Widget::autosize();
@@ -368,9 +362,15 @@ void List::BasicItem::on_style_change()
 }
 
 
+List::Loader::Loader(List &l):
+       DataFile::DerivedObjectLoader<List, Widget::Loader>(l)
+{
+       add("item", &Loader::item);
+}
+
 void List::Loader::item(const string &v)
 {
-       dynamic_cast<BasicListData<string> &>(*dynamic_cast<List &>(obj).data).append(v);
+       dynamic_cast<BasicListData<string> &>(*obj.data).append(v);
 }
 
 } // namespace GLtk