]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/widget.cpp
Avoid autosizing widgets with no style
[libs/gltk.git] / source / widget.cpp
index e73e5cf56ef89630c0b36944792ed7a225018e58..3d3b0068ad6f394b905d8e6854dafdfeebf9769e 100644 (file)
@@ -40,14 +40,19 @@ void Widget::set_size(unsigned w, unsigned h)
 
 void Widget::autosize()
 {
+       if(!style)
+               return;
+
        geom.w = 0;
        geom.h = 0;
        const Style::PartSeq &parts = style->get_parts();
        for(Style::PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i)
                if(i->get_name().empty())
                {
-                       geom.w = max(geom.w, i->get_geometry().w);
-                       geom.h = max(geom.h, i->get_geometry().h);
+                       const Geometry &pgeom = i->get_geometry();
+                       const Sides &pmargin = i->get_margin();
+                       geom.w = max(geom.w, pgeom.w+pmargin.left+pmargin.right);
+                       geom.h = max(geom.h, pgeom.h+pmargin.top+pmargin.bottom);
                }
 }