From 1c62c04786585a817eea85aa9c948f3bb86cc437 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 4 May 2015 16:25:43 -0400 Subject: [PATCH] Partially fixed box updating issues by actually monitoring parent containers in uiBox. --- box.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/box.c b/box.c index b299111d..0031a206 100644 --- a/box.c +++ b/box.c @@ -2,9 +2,6 @@ #include "ui.h" #include "uipriv.h" -// TODOs -// - setting padded doesn't take effect immediately on Windows and OS X - struct box { uiBox b; void (*baseDestroy)(uiControl *); @@ -12,7 +9,7 @@ struct box { uintmax_t len; uintmax_t cap; int vertical; - int hasParent; + void (*baseSetParent)(uiControl *, uiContainer *); uiContainer *parent; int padded; }; @@ -29,7 +26,8 @@ static void boxDestroy(uiControl *c) struct box *b = (struct box *) c; uintmax_t i; - // TODO find a way to move the parented check here + if (b->parent != NULL) + complain("attempt to destroy uiBox %p while it has a parent", b); // don't chain up to base here; we need to destroy children ourselves first for (i = 0; i < b->len; i++) { uiControlSetParent(b->controls[i].c, NULL); @@ -41,6 +39,16 @@ static void boxDestroy(uiControl *c) uiFree(b); } +static void boxSetParent(uiControl *c, uiContainer *parent) +{ + struct box *b = (struct box *) c; + + // this does all the actual work + (*(b->baseSetParent))(uiControl(b), parent); + // we just need to have a copy of the parent ourselves for boxSetPadded() + b->parent = parent; +} + static void boxPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height) { struct box *b = (struct box *) c; @@ -250,6 +258,8 @@ uiBox *uiNewHorizontalBox(void) b->baseDestroy = uiControl(b)->Destroy; uiControl(b)->Destroy = boxDestroy; + b->baseSetParent = uiControl(b)->SetParent; + uiControl(b)->SetParent = boxSetParent; uiControl(b)->PreferredSize = boxPreferredSize; uiControl(b)->SysFunc = boxSysFunc;