From 52bd3b2c3597018d22f355395a10ef0053c5f79a Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 14 Jun 2016 22:41:37 +0200 Subject: [PATCH] Adds uiFormDelete() --- darwin/form.m | 5 +++++ ui.h | 1 + unix/form.c | 25 +++++++++++++++++++++++++ windows/form.cpp | 12 ++++++++++++ 4 files changed, 43 insertions(+) diff --git a/darwin/form.m b/darwin/form.m index acc33a3e..3d27520b 100644 --- a/darwin/form.m +++ b/darwin/form.m @@ -485,6 +485,11 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy) [f->view append:toNSString(label) c:c stretchy:stretchy]; } +void uiFormDelete(uiForm *f, int n) +{ + [f->view delete:n]; +} + int uiFormPadded(uiForm *f) { return [f->view isPadded]; diff --git a/ui.h b/ui.h index 7527ed11..85c2d302 100644 --- a/ui.h +++ b/ui.h @@ -625,6 +625,7 @@ _UI_EXTERN uiColorButton *uiNewColorButton(void); typedef struct uiForm uiForm; #define uiForm(this) ((uiForm *) (this)) _UI_EXTERN void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy); +_UI_EXTERN void uiFormDelete(uiForm *f, int index); _UI_EXTERN int uiFormPadded(uiForm *f); _UI_EXTERN void uiFormSetPadded(uiForm *f, int padded); _UI_EXTERN uiForm *uiNewForm(void); diff --git a/unix/form.c b/unix/form.c index 4e1f7fa0..7aa1a675 100644 --- a/unix/form.c +++ b/unix/form.c @@ -3,6 +3,7 @@ struct formChild { uiControl *c; + int stretchy; GtkWidget *label; gboolean oldhexpand; GtkAlign oldhalign; @@ -54,6 +55,7 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy) fc.c = c; widget = GTK_WIDGET(uiControlHandle(fc.c)); + fc.stretchy = stretchy; fc.oldhexpand = gtk_widget_get_hexpand(widget); fc.oldhalign = gtk_widget_get_halign(widget); fc.oldvexpand = gtk_widget_get_vexpand(widget); @@ -95,6 +97,29 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy) NULL); } +void uiFormDelete(uiForm *f, int index) +{ + struct formChild *fc; + GtkWidget *widget; + + fc = ctrl(f, index); + widget = GTK_WIDGET(uiControlHandle(fc->c)); + + gtk_widget_destroy(fc->label); + + uiControlSetParent(fc->c, NULL); + uiUnixControlSetContainer(uiUnixControl(fc->c), f->container, TRUE); + + if (fc->stretchy) + gtk_size_group_remove_widget(f->stretchygroup, widget); + gtk_widget_set_hexpand(widget, fc->oldhexpand); + gtk_widget_set_halign(widget, fc->oldhalign); + gtk_widget_set_vexpand(widget, fc->oldvexpand); + gtk_widget_set_valign(widget, fc->oldvalign); + + g_array_remove_index(f->children, index); +} + int uiFormPadded(uiForm *f) { return f->padded; diff --git a/windows/form.cpp b/windows/form.cpp index e15e9571..e22da976 100644 --- a/windows/form.cpp +++ b/windows/form.cpp @@ -258,6 +258,18 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy) uiWindowsControlMinimumSizeChanged(uiWindowsControl(f)); } +void uiFormDelete(uiForm *f, int index) +{ + uiControl *c; + + c = (*(f->controls))[index].c; + uiControlSetParent(c, NULL); + uiWindowsControlSetParentHWND(uiWindowsControl(c), NULL); + f->controls->erase(f->controls->begin() + index); + formArrangeChildren(f); + uiWindowsControlMinimumSizeChanged(uiWindowsControl(f)); +} + int uiFormPadded(uiForm *f) { return f->padded;