diff --git a/darwin/form.m b/darwin/form.m index 3a61336b..ffebc67e 100644 --- a/darwin/form.m +++ b/darwin/form.m @@ -260,11 +260,8 @@ struct uiForm { prev = [fc view]; prevlabel = fc; } - relation = NSLayoutRelationEqual; - if (self->nStretchy != 0) - relation = NSLayoutRelationLessThanOrEqual; self->last = mkConstraint(prev, NSLayoutAttributeBottom, - relation, + NSLayoutRelationEqual, self, NSLayoutAttributeBottom, 1, 0, @"uiForm last vertical constraint"); @@ -314,6 +311,25 @@ struct uiForm { [self->trailings addObject:c]; } + // and make all stretchy controls have the same height + prev = nil; + for (fc in self->children) { + if (!fc.stretchy) + continue; + if (prev == nil) { + prev = [fc view]; + continue; + } + c = mkConstraint([fc view], NSLayoutAttributeHeight, + NSLayoutRelationEqual, + prev, NSLayoutAttributeHeight, + 1, 0, + @"uiForm stretchy constraint"); + [self addConstraint:c]; + // TODO make a dedicated array for this + [self->leadings addObject:c]; + } + // we don't arrange the labels vertically; that's done when we add the control since those constraints don't need to change (they just need to be at their baseline) } @@ -333,7 +349,6 @@ struct uiForm { [self addSubview:fc]; uiControlSetParent(fc.c, uiControl(self->f)); - // TODO fix this it's wrong uiDarwinControlSetSuperview(uiDarwinControl(fc.c), self); uiDarwinControlSyncEnableState(uiDarwinControl(fc.c), uiControlEnabledToUser(uiControl(self->f))); diff --git a/examples/controlgallery/main.c b/examples/controlgallery/main.c index 1e426041..a3bc099c 100644 --- a/examples/controlgallery/main.c +++ b/examples/controlgallery/main.c @@ -3,25 +3,114 @@ #include #include "../../ui.h" -// TODOs -// - rename variables in main() -// - make both columns the same size? - -static uiWindow *mainwin; - static int onClosing(uiWindow *w, void *data) { - uiControlDestroy(uiControl(mainwin)); uiQuit(); - return 0; + return 1; } -static int shouldQuit(void *data) +static int onShouldQuit(void *data) { + uiWindow *mainwin = uiWindow(data); + uiControlDestroy(uiControl(mainwin)); return 1; } +static uiControl *makeBasicControlsPage(void) +{ + uiBox *vbox; + uiBox *hbox; + uiGroup *group; + uiForm *entryForm; + + vbox = uiNewVerticalBox(); + uiBoxSetPadded(vbox, 1); + + hbox = uiNewHorizontalBox(); + uiBoxSetPadded(hbox, 1); + uiBoxAppend(vbox, uiControl(hbox), 0); + + uiBoxAppend(hbox, + uiControl(uiNewButton("Button")), + 0); + uiBoxAppend(hbox, + uiControl(uiNewCheckbox("Checkbox")), + 0); + + uiBoxAppend(vbox, + uiControl(uiNewLabel("This is a label. Right now, labels can only span one line.")), + 0); + + uiBoxAppend(vbox, + uiControl(uiNewHorizontalSeparator()), + 0); + + group = uiNewGroup("Entries"); + uiGroupSetMargined(group, 1); + uiBoxAppend(vbox, uiControl(group), 1); + + entryForm = uiNewForm(); + uiFormSetPadded(entryForm, 1); + uiGroupSetChild(group, uiControl(entryForm)); + + uiFormAppend(entryForm, + "Entry", + uiControl(uiNewEntry()), + 0); + uiFormAppend(entryForm, + "Password Entry", + uiControl(uiNewPasswordEntry()), + 0); + uiFormAppend(entryForm, + "Search Entry", + uiControl(uiNewSearchEntry()), + 0); + uiFormAppend(entryForm, + "Multiline Entry", + uiControl(uiNewMultilineEntry()), + 1); + uiFormAppend(entryForm, + "Multiline Entry No Wrap", + uiControl(uiNewNonWrappingMultilineEntry()), + 1); + + return uiControl(vbox); +} + +int main(void) +{ + uiInitOptions options; + const char *err; + uiWindow *mainwin; + uiTab *tab; + + memset(&options, 0, sizeof (uiInitOptions)); + err = uiInit(&options); + if (err != NULL) { + fprintf(stderr, "error initializing libui: %s", err); + uiFreeInitError(err); + return 1; + } + + mainwin = uiNewWindow("libui Control Gallery", 640, 480, 1); + uiWindowOnClosing(mainwin, onClosing, NULL); + uiOnShouldQuit(onShouldQuit, mainwin); + + tab = uiNewTab(); + uiWindowSetChild(mainwin, uiControl(tab)); + uiWindowSetMargined(mainwin, 1); + + uiTabAppend(tab, "Basic Controls", makeBasicControlsPage()); + uiTabSetMargined(tab, 0, 1); + + uiControlShow(uiControl(mainwin)); + uiMain(); + return 0; +} + +#if 0 + static void openClicked(uiMenuItem *item, uiWindow *w, void *data) { char *filename; @@ -230,3 +319,5 @@ int main(void) uiUninit(); return 0; } + +#endif diff --git a/unix/form.c b/unix/form.c index bf0c9b52..4e1f7fa0 100644 --- a/unix/form.c +++ b/unix/form.c @@ -17,7 +17,6 @@ struct uiForm { GtkGrid *grid; GArray *children; int padded; - // TODO OS X is missing this GtkSizeGroup *stretchygroup; // ensures all stretchy controls have the same size };