From b278bbb4ee98486340472066411ce253d07461b1 Mon Sep 17 00:00:00 2001 From: Freddie Witherden Date: Fri, 21 Nov 2008 17:52:21 +0000 Subject: [PATCH] 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-861f7616d084 --- lib/betawidget/widget.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/betawidget/widget.c b/lib/betawidget/widget.c index 43b929bb2..da9dc87c9 100644 --- a/lib/betawidget/widget.c +++ b/lib/betawidget/widget.c @@ -434,6 +434,10 @@ void widgetInit(widget *self, const char *id) // Default parent is none 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 self->rotate = 0.0f; @@ -692,15 +696,16 @@ bool widgetAddChildImpl(widget *self, widget *child) // Add the widget vectorAdd(self->children, child); - // Re-layout the window - if (widgetDoLayout(widgetGetRoot(self))) + // So long as our size is not (-1,-1) (NULL-size), re-layout the window + if ((self->size.x == -1.0f && self->size.y == -1.0f) + || widgetDoLayout(widgetGetRoot(self))) { // Set ourself as its parent child->parent = self; return true; } - // Not enough space to fit the widget + // Not enough space to fit the widget (widgetDoLayout returned false) else { // Remove child *without* calling its destructor @@ -728,11 +733,14 @@ void widgetRemoveChildImpl(widget *self, widget *child) // Remove it from the list of children vectorRemoveAt(self->children, i); - // Re-layout the window - widgetDoLayout(widgetGetRoot(self)); + // Re-layout the window (so long as we are part of one) + if (self->size.x != -1.0f && self->size.y != -1.0f) + { + widgetDoLayout(widgetGetRoot(self)); + } } // See if it is one of its children - else + else if (child->parent != self) { widgetRemoveChild(vectorAt(self->children, i), child); }