Migrated uiBox to use the child system. It all works! :D

This commit is contained in:
Pietro Gagliardi 2015-08-28 18:12:24 -04:00
parent ef0f36a8ec
commit 3fa52f811e
1 changed files with 19 additions and 30 deletions

View File

@ -14,11 +14,6 @@ struct uiBox {
GtkSizeGroup *stretchygroup; // ensures all stretchy controls have the same size GtkSizeGroup *stretchygroup; // ensures all stretchy controls have the same size
}; };
struct boxControl {
uiControl *c;
int stretchy;
};
static void onDestroy(uiBox *b); static void onDestroy(uiBox *b);
uiUnixDefineControlWithOnDestroy( uiUnixDefineControlWithOnDestroy(
@ -29,15 +24,12 @@ uiUnixDefineControlWithOnDestroy(
static void onDestroy(uiBox *b) static void onDestroy(uiBox *b)
{ {
struct boxControl *bc; struct child *bc;
// don't chain up to base here; we need to destroy children ourselves first
while (b->controls->len != 0) { while (b->controls->len != 0) {
bc = ptrArrayIndex(b->controls, struct boxControl *, 0); bc = ptrArrayIndex(b->controls, struct child *, 0);
uiControlSetParent(bc->c, NULL); childDestroy(bc);
uiControlDestroy(bc->c);
ptrArrayDelete(b->controls, 0); ptrArrayDelete(b->controls, 0);
uiFree(bc);
} }
ptrArrayDestroy(b->controls); ptrArrayDestroy(b->controls);
// kill the size group // kill the size group
@ -47,27 +39,26 @@ static void onDestroy(uiBox *b)
static void boxContainerUpdateState(uiControl *c) static void boxContainerUpdateState(uiControl *c)
{ {
uiBox *b = uiBox(c); uiBox *b = uiBox(c);
struct boxControl *bc; struct child *bc;
uintmax_t i; uintmax_t i;
for (i = 0; i < b->controls->len; i++) { for (i = 0; i < b->controls->len; i++) {
bc = ptrArrayIndex(b->controls, struct boxControl *, i); bc = ptrArrayIndex(b->controls, struct child *, i);
controlUpdateState(bc->c); childUpdateState(bc);
} }
} }
#define isStretchy(bc) childFlag(bc)
void uiBoxAppend(uiBox *b, uiControl *c, int stretchy) void uiBoxAppend(uiBox *b, uiControl *c, int stretchy)
{ {
struct boxControl *bc; struct child *bc;
GtkWidget *widget; GtkWidget *widget;
bc = uiNew(struct boxControl); bc = newChild(c, uiControl(b), b->container);
bc->c = c; childSetFlag(bc, stretchy);
bc->stretchy = stretchy; widget = childWidget(bc);
uiControlSetParent(bc->c, uiControl(b)); if (isStretchy(bc)) {
gtk_container_add(b->container, GTK_WIDGET(uiControlHandle(bc->c)));
widget = GTK_WIDGET(uiControlHandle(bc->c));
if (bc->stretchy) {
if (b->vertical) { if (b->vertical) {
gtk_widget_set_vexpand(widget, TRUE); gtk_widget_set_vexpand(widget, TRUE);
gtk_widget_set_valign(widget, GTK_ALIGN_FILL); gtk_widget_set_valign(widget, GTK_ALIGN_FILL);
@ -76,7 +67,7 @@ void uiBoxAppend(uiBox *b, uiControl *c, int stretchy)
gtk_widget_set_halign(widget, GTK_ALIGN_FILL); gtk_widget_set_halign(widget, GTK_ALIGN_FILL);
} }
gtk_size_group_add_widget(b->stretchygroup, widget); gtk_size_group_add_widget(b->stretchygroup, widget);
} else // TODO undo this all in delete } else
if (b->vertical) if (b->vertical)
gtk_widget_set_vexpand(widget, FALSE); gtk_widget_set_vexpand(widget, FALSE);
else else
@ -88,15 +79,13 @@ void uiBoxAppend(uiBox *b, uiControl *c, int stretchy)
void uiBoxDelete(uiBox *b, uintmax_t index) void uiBoxDelete(uiBox *b, uintmax_t index)
{ {
struct boxControl *bc; struct child *bc;
bc = ptrArrayIndex(b->controls, struct boxControl *, index); bc = ptrArrayIndex(b->controls, struct child *, index);
ptrArrayDelete(b->controls, index); ptrArrayDelete(b->controls, index);
if (bc->stretchy) if (isStretchy(bc))
gtk_size_group_remove_widget(b->stretchygroup, GTK_WIDGET(uiControlHandle(bc->c))); gtk_size_group_remove_widget(b->stretchygroup, childWidget(bc));
gtk_container_remove(b->container, GTK_WIDGET(uiControlHandle(bc->c))); childRemove(bc);
uiControlSetParent(bc->c, NULL);
uiFree(bc);
uiControlQueueResize(uiControl(b)); uiControlQueueResize(uiControl(b));
} }