From: Mikko Rasa Date: Tue, 27 Nov 2012 07:36:36 +0000 (+0200) Subject: Store autosized geom in Layout::Slot X-Git-Url: http://git.tdb.fi/?p=libs%2Fgltk.git;a=commitdiff_plain;h=99595e939b7f5753773f36a0a8298cd837924030 Store autosized geom in Layout::Slot 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. --- diff --git a/source/layout.cpp b/source/layout.cpp index 6cf7b34..b95ab92 100644 --- a/source/layout.cpp +++ b/source/layout.cpp @@ -217,12 +217,6 @@ void Layout::set_expand(Widget &wdg, bool h, bool v) void Layout::update() { - for(list::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(); } diff --git a/source/layout.h b/source/layout.h index 582bc1b..cf63538 100644 --- a/source/layout.h +++ b/source/layout.h @@ -101,6 +101,7 @@ protected: Layout &layout; unsigned index; Widget &widget; + Geometry autosize_geom; Geometry geom; std::list constraints; Packing horiz_pack;