]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/list.cpp
Autosize all items in a List
[libs/gltk.git] / source / list.cpp
index 4ce35e266f4418accb2b9b2716480dc1451f20ad..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);