]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/layout.cpp
Store autosized geom in Layout::Slot
[libs/gltk.git] / source / layout.cpp
index 6cf7b348a4dc5c753f0d5bd7574cc39c477ed365..b95ab92ffd0f85685216a7501ad35131e0e45f3e 100644 (file)
@@ -217,12 +217,6 @@ void Layout::set_expand(Widget &wdg, bool h, bool v)
 
 void Layout::update()
 {
-       for(list<Slot *>::iterator i=slots.begin(); i!=slots.end(); ++i)
-       {
-               (*i)->widget.autosize();
-               (*i)->geom = (*i)->widget.get_geometry();
-       }
-
        solve_constraints(HORIZONTAL);
        solve_constraints(VERTICAL);
 
@@ -268,7 +262,7 @@ void Layout::solve_constraints(int dir)
                        LinearProgram::Row row = linprog.add_row();
                        row[(*i)->index*5+1] = 1;
                        row[(*i)->index*5+4] = -1;
-                       row.back() = (*i)->geom.*(ptrs.dim);
+                       row.back() = (*i)->autosize_geom.*(ptrs.dim);
                }
 
                /* Add rows for user-defined constraints.  Below/above and left/right of
@@ -321,11 +315,20 @@ Layout::Slot::Slot(Layout &l, Widget &w):
 {
        vert_pack.gravity = 1;
        widget.signal_autosize_changed.connect(sigc::mem_fun(this, &Slot::autosize_changed));
+       widget.autosize();
+       autosize_geom = widget.get_geometry();
 }
 
 void Layout::Slot::autosize_changed()
 {
-       layout.update();
+       widget.autosize();
+       autosize_geom = widget.get_geometry();
+
+       // If the widget fits in the area it had, just leave it there.
+       if(autosize_geom.w<=geom.w && autosize_geom.h<=geom.h)
+               widget.set_geometry(geom);
+       else
+               layout.update();
 }