]> git.tdb.fi Git - libs/gltk.git/commitdiff
Store autosized geom in Layout::Slot
authorMikko Rasa <tdb@tdb.fi>
Tue, 27 Nov 2012 07:36:36 +0000 (09:36 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 27 Nov 2012 14:50:27 +0000 (16:50 +0200)
This avoids having to autosize all widgets in the layout every time one of
them changes, and allows checking whether an update is actually needed.

source/layout.cpp
source/layout.h

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();
 }
 
 
index 582bc1b0f685297b053ca73e38044aef592d777b..cf63538413e6465c967f93063ee394e8fc09f07d 100644 (file)
@@ -101,6 +101,7 @@ protected:
                Layout &layout;
                unsigned index;
                Widget &widget;
+               Geometry autosize_geom;
                Geometry geom;
                std::list<Constraint> constraints;
                Packing horiz_pack;