Add the concept of a NUL size to betawidget which is needed to allow widgets to be added to a parent-less container.
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@6356 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
266d51bbb5
commit
b278bbb4ee
|
@ -434,6 +434,10 @@ void widgetInit(widget *self, const char *id)
|
||||||
// Default parent is none
|
// Default parent is none
|
||||||
self->parent = NULL;
|
self->parent = NULL;
|
||||||
|
|
||||||
|
// Default size is (-1,-1) 'NULL' size
|
||||||
|
self->size.x = -1.0f;
|
||||||
|
self->size.y = -1.0f;
|
||||||
|
|
||||||
// We are not rotated by default
|
// We are not rotated by default
|
||||||
self->rotate = 0.0f;
|
self->rotate = 0.0f;
|
||||||
|
|
||||||
|
@ -692,15 +696,16 @@ bool widgetAddChildImpl(widget *self, widget *child)
|
||||||
// Add the widget
|
// Add the widget
|
||||||
vectorAdd(self->children, child);
|
vectorAdd(self->children, child);
|
||||||
|
|
||||||
// Re-layout the window
|
// So long as our size is not (-1,-1) (NULL-size), re-layout the window
|
||||||
if (widgetDoLayout(widgetGetRoot(self)))
|
if ((self->size.x == -1.0f && self->size.y == -1.0f)
|
||||||
|
|| widgetDoLayout(widgetGetRoot(self)))
|
||||||
{
|
{
|
||||||
// Set ourself as its parent
|
// Set ourself as its parent
|
||||||
child->parent = self;
|
child->parent = self;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Not enough space to fit the widget
|
// Not enough space to fit the widget (widgetDoLayout returned false)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Remove child *without* calling its destructor
|
// Remove child *without* calling its destructor
|
||||||
|
@ -728,11 +733,14 @@ void widgetRemoveChildImpl(widget *self, widget *child)
|
||||||
// Remove it from the list of children
|
// Remove it from the list of children
|
||||||
vectorRemoveAt(self->children, i);
|
vectorRemoveAt(self->children, i);
|
||||||
|
|
||||||
// Re-layout the window
|
// Re-layout the window (so long as we are part of one)
|
||||||
widgetDoLayout(widgetGetRoot(self));
|
if (self->size.x != -1.0f && self->size.y != -1.0f)
|
||||||
|
{
|
||||||
|
widgetDoLayout(widgetGetRoot(self));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// See if it is one of its children
|
// See if it is one of its children
|
||||||
else
|
else if (child->parent != self)
|
||||||
{
|
{
|
||||||
widgetRemoveChild(vectorAt(self->children, i), child);
|
widgetRemoveChild(vectorAt(self->children, i), child);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue