]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/widget.cpp
Avoid autosizing widgets with no style
[libs/gltk.git] / source / widget.cpp
index bbd2e8877af608b1255d21eb10d9b23d2506fba4..3d3b0068ad6f394b905d8e6854dafdfeebf9769e 100644 (file)
@@ -30,30 +30,29 @@ Widget::~Widget()
 
 void Widget::set_position(int x, int y)
 {
-       geom.x = x;
-       geom.y = y;
-       on_geometry_change();
-       rebuild();
+       set_geometry(Geometry(x, y, geom.w, geom.h));
 }
 
 void Widget::set_size(unsigned w, unsigned h)
 {
-       geom.w = w;
-       geom.h = h;
-       on_geometry_change();
-       rebuild();
+       set_geometry(Geometry(geom.x, geom.y, w, 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);
                }
 }