From 52bd3b2c3597018d22f355395a10ef0053c5f79a Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 14 Jun 2016 22:41:37 +0200 Subject: [PATCH 1/9] 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; From b817a16c051f59bba08a9217a8d3c8eee1a63c1f Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 14 Jun 2016 22:55:55 +0200 Subject: [PATCH 2/9] Adds missing delete() method for darwin --- darwin/form.m | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/darwin/form.m b/darwin/form.m index 3d27520b..08a3b6da 100644 --- a/darwin/form.m +++ b/darwin/form.m @@ -40,7 +40,7 @@ - (CGFloat)paddingAmount; - (void)establishOurConstraints; - (void)append:(NSString *)label c:(uiControl *)c stretchy:(int)stretchy; -//TODO- (void)delete:(int)n; +- (void)delete:(int)n; - (int)isPadded; - (void)setPadded:(int)p; - (BOOL)hugsTrailing; @@ -388,7 +388,31 @@ struct uiForm { [fc release]; // we don't need the initial reference now } -//TODO- (void)delete:(int)n +- (void)delete:(int)n +{ + formChild *fc; + int stretchy; + + fc = (formChild *) [self->children objectAtIndex:n]; + stretchy = fc.stretchy; + + uiControlSetParent(fc.c, NULL); + uiDarwinControlSetSuperview(uiDarwinControl(fc.c), nil); + + uiDarwinControlSetHuggingPriority(uiDarwinControl(fc.c), fc.oldHorzHuggingPri, NSLayoutConstraintOrientationHorizontal); + uiDarwinControlSetHuggingPriority(uiDarwinControl(fc.c), fc.oldVertHuggingPri, NSLayoutConstraintOrientationVertical); + + [fc.label removeFromSuperview]; + + [self->children removeObjectAtIndex:n]; + + [self establishOurConstraints]; + if (stretchy) { + self->nStretchy--; + if (self->nStretchy == 0) + uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->f)); + } +} - (int)isPadded { From c60cbb72f96ef20c057431fda429b2d045838d9a Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 15 Jun 2016 00:04:39 -0400 Subject: [PATCH 3/9] More TODOs. --- TODO.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TODO.md b/TODO.md index 5ba8193d..d0aa26cf 100644 --- a/TODO.md +++ b/TODO.md @@ -90,3 +90,5 @@ don't forget LONGTERMs as well notes - http://blogs.msdn.com/b/oldnewthing/archive/2004/03/29/101121.aspx on accelerators + +- group and tab should act as if they have no child if the child is hidden From 16b4409f380ba17bef6d9d156a3f437b5d99e687 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 15 Jun 2016 00:04:55 -0400 Subject: [PATCH 4/9] Amended TODO. --- TODO.md | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO.md b/TODO.md index d0aa26cf..981deef1 100644 --- a/TODO.md +++ b/TODO.md @@ -92,3 +92,4 @@ notes - http://blogs.msdn.com/b/oldnewthing/archive/2004/03/29/101121.aspx on accelerators - group and tab should act as if they have no child if the child is hidden +on windows From 831fe1e73bd07be2523630c5056208a6efa17da8 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 15 Jun 2016 16:39:23 +0200 Subject: [PATCH 5/9] Updates darwin to work with upstream changes --- darwin/form.m | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/darwin/form.m b/darwin/form.m index 08a3b6da..614c6114 100644 --- a/darwin/form.m +++ b/darwin/form.m @@ -23,7 +23,6 @@ uiForm *f; NSMutableArray *children; int padded; - int nStretchy; NSLayoutConstraint *first; NSMutableArray *inBetweens; @@ -45,6 +44,7 @@ - (void)setPadded:(int)p; - (BOOL)hugsTrailing; - (BOOL)hugsBottom; +- (int)nStretchy; @end struct uiForm { @@ -123,7 +123,6 @@ struct uiForm { self->f = ff; self->padded = 0; self->children = [NSMutableArray new]; - self->nStretchy = 0; self->inBetweens = [NSMutableArray new]; self->widths = [NSMutableArray new]; @@ -221,6 +220,9 @@ struct uiForm { // first arrange the children vertically and make them the same width prev = nil; for (fc in self->children) { + [fc setHidden:!uiControlVisible(fc.c)]; + if (!uiControlVisible(fc.c)) + continue; if (prev == nil) { // first view self->first = mkConstraint(self, NSLayoutAttributeTop, NSLayoutRelationEqual, @@ -259,6 +261,8 @@ struct uiForm { prev = [fc view]; prevlabel = fc; } + if (prev == nil) // all hidden; act as if nothing there + return; self->last = mkConstraint(prev, NSLayoutAttributeBottom, NSLayoutRelationEqual, self, NSLayoutAttributeBottom, @@ -269,6 +273,8 @@ struct uiForm { // now arrange the controls horizontally for (fc in self->children) { + if (!uiControlVisible(fc.c)) + continue; c = mkConstraint(self, NSLayoutAttributeLeading, NSLayoutRelationEqual, fc, NSLayoutAttributeLeading, @@ -313,6 +319,8 @@ struct uiForm { // and make all stretchy controls have the same height prev = nil; for (fc in self->children) { + if (!uiControlVisible(fc.c)) + continue; if (!fc.stretchy) continue; if (prev == nil) { @@ -375,15 +383,13 @@ struct uiForm { @"uiForm baseline constraint"); [self addConstraint:fc.baseline]; + oldnStretchy = [self nStretchy]; [self->children addObject:fc]; [self establishOurConstraints]; - if (fc.stretchy) { - oldnStretchy = self->nStretchy; - self->nStretchy++; + if (fc.stretchy) if (oldnStretchy == 0) uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->f)); - } [fc release]; // we don't need the initial reference now } @@ -408,8 +414,7 @@ struct uiForm { [self establishOurConstraints]; if (stretchy) { - self->nStretchy--; - if (self->nStretchy == 0) + if ([self nStretchy] == 0) uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->f)); } } @@ -440,7 +445,22 @@ struct uiForm { - (BOOL)hugsBottom { // only hug if we have stretchy - return self->nStretchy != 0; + return [self nStretchy] != 0; +} + +- (int)nStretchy +{ + formChild *fc; + int n; + + n = 0; + for (fc in self->children) { + if (!uiControlVisible(fc.c)) + continue; + if (fc.stretchy) + n++; + } + return n; } @end @@ -500,6 +520,13 @@ static void uiFormChildEdgeHuggingChanged(uiDarwinControl *c) uiDarwinControlDefaultHuggingPriority(uiForm, view) uiDarwinControlDefaultSetHuggingPriority(uiForm, view) +static void uiFormChildVisibilityChanged(uiDarwinControl *c) +{ + uiForm *f = uiForm(c); + + [f->view establishOurConstraints]; +} + void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy) { // LONGTERM on other platforms From 3173fc6cdca14258ce00130633c01d52a2ac6320 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 15 Jun 2016 17:07:52 +0200 Subject: [PATCH 6/9] Fixes windows static library copy --- windows/CMakeLists.txt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt index a2506705..0f1d61de 100644 --- a/windows/CMakeLists.txt +++ b/windows/CMakeLists.txt @@ -68,16 +68,11 @@ if(NOT BUILD_SHARED_LIBS) set(_LIBUI_STATIC_RES ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libui.res PARENT_SCOPE) endif() macro(_handle_static) - if(MSVC) - set(_res_suffix res) - else() - set(_res_suffix obj) - endif() # TODO this full path feels hacky add_custom_command( TARGET libui POST_BUILD COMMAND - ${CMAKE_COMMAND} -E copy $/CMakeFiles/libui.dir/windows/resources.rc.${_res_suffix} ${_LIBUI_STATIC_RES} + ${CMAKE_COMMAND} -E copy $/CMakeFiles/libui.dir/windows/resources.rc.* ${_LIBUI_STATIC_RES} COMMENT "Copying libui.res") set(_res_suffix) endmacro() From cea52e2df60ecd5e8ef904c576448a360f5421cd Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 15 Jun 2016 11:58:26 -0400 Subject: [PATCH 7/9] Preemptive README change for next merge. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index e693e7a6..1aea4549 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ This README is being written.
*Note that today's entry may be updated later today Eastern Time.* +* **15 June 2016** + * Added `uiFormDelete()`; thanks to @emersion. + * **14 June 2016** * uiDarwinControl now has a `ChildVisibilityChanged()` method and a corresponding `NotifyVisibilityChanged()` function that is called by the default show/hide handlers. This is used to make visibility changes work on OS X; uiBox, uiForm, and uiGrid all respect these now. * The same has been done on the Windows side as well. From dda58c93237467dade3526f630e1803ee6dc5fbf Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 15 Jun 2016 12:04:11 -0400 Subject: [PATCH 8/9] Fixed leaking issues with the previous commit. --- darwin/form.m | 6 ++---- windows/form.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/darwin/form.m b/darwin/form.m index 614c6114..7cdb965a 100644 --- a/darwin/form.m +++ b/darwin/form.m @@ -408,15 +408,13 @@ struct uiForm { uiDarwinControlSetHuggingPriority(uiDarwinControl(fc.c), fc.oldHorzHuggingPri, NSLayoutConstraintOrientationHorizontal); uiDarwinControlSetHuggingPriority(uiDarwinControl(fc.c), fc.oldVertHuggingPri, NSLayoutConstraintOrientationVertical); - [fc.label removeFromSuperview]; - + [fc onDestroy]; [self->children removeObjectAtIndex:n]; [self establishOurConstraints]; - if (stretchy) { + if (stretchy) if ([self nStretchy] == 0) uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->f)); - } } - (int)isPadded diff --git a/windows/form.cpp b/windows/form.cpp index d0607235..febcc693 100644 --- a/windows/form.cpp +++ b/windows/form.cpp @@ -278,11 +278,12 @@ void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy) void uiFormDelete(uiForm *f, int index) { - uiControl *c; + struct formChild fc; - c = (*(f->controls))[index].c; - uiControlSetParent(c, NULL); - uiWindowsControlSetParentHWND(uiWindowsControl(c), NULL); + fc = (*(f->controls))[index]; + uiControlSetParent(fc.c, NULL); + uiWindowsControlSetParentHWND(uiWindowsControl(fc.c), NULL); + uiWindowsEnsureDestroyWindow(fc.label); f->controls->erase(f->controls->begin() + index); formArrangeChildren(f); uiWindowsControlMinimumSizeChanged(uiWindowsControl(f)); From efe207ca372a493142c54658a9327502e8dc7338 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 15 Jun 2016 12:06:19 -0400 Subject: [PATCH 9/9] Added a test of uiFormDelete(). --- test/page13.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/page13.c b/test/page13.c index 519fb347..0f3f358c 100644 --- a/test/page13.c +++ b/test/page13.c @@ -75,6 +75,13 @@ static void showHide(uiButton *b, void *data) uiControlShow(c); } +static void deleteFirst(uiButton *b, void *data) +{ + uiForm *f = uiForm(data); + + uiFormDelete(f, 0); +} + uiBox *makePage13(void) { uiBox *page13; @@ -119,6 +126,9 @@ uiBox *makePage13(void) b = uiNewButton("Show/Hide"); uiButtonOnClicked(b, showHide, e); uiBoxAppend(page13, uiControl(b), 0); + b = uiNewButton("Delete First"); + uiButtonOnClicked(b, deleteFirst, f); + uiBoxAppend(page13, uiControl(b), 0); uiBoxAppend(page13, uiControl(f), 1); return page13;