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);
}
}
throw hierarchy_error("widget already parented");
else if(p==parent)
return;
- parent = p;
- on_reparent();
- update_style();
+ try
+ {
+ parent = p;
+
+ on_reparent();
+ update_style();
+ }
+ catch(...)
+ {
+ // The container has not yet added the widget as its child
+ parent = 0;
+ throw;
+ }
}
void Widget::set_style(const string &s)