More control gallery rewriting. Removed some debugging code in the OS X grid.

This commit is contained in:
Pietro Gagliardi 2016-06-12 19:55:35 -04:00
parent 41ec54cb47
commit f08cd96688
2 changed files with 179 additions and 1 deletions

View File

@ -500,11 +500,13 @@ struct uiGrid {
CGFloat padding; CGFloat padding;
NSLayoutConstraint *c; NSLayoutConstraint *c;
#if 0 /* TODO */
dispatch_after( dispatch_after(
dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC),
dispatch_get_main_queue(), dispatch_get_main_queue(),
^{ [[self window] visualizeConstraints:[self constraints]]; } ^{ [[self window] visualizeConstraints:[self constraints]]; }
); );
#endif
self->padded = p; self->padded = p;
padding = [self paddingAmount]; padding = [self paddingAmount];
for (c in self->inBetweens) for (c in self->inBetweens)

View File

@ -78,11 +78,181 @@ static uiControl *makeBasicControlsPage(void)
return uiControl(vbox); return uiControl(vbox);
} }
// TODO make these not global
static uiSpinbox *spinbox;
static uiSlider *slider;
static uiProgressBar *pbar;
static void onSpinboxChanged(uiSpinbox *s, void *data)
{
uiSliderSetValue(slider, uiSpinboxValue(s));
uiProgressBarSetValue(pbar, uiSpinboxValue(s));
}
static void onSliderChanged(uiSlider *s, void *data)
{
uiSpinboxSetValue(spinbox, uiSliderValue(s));
uiProgressBarSetValue(pbar, uiSliderValue(s));
}
static uiControl *makeNumbersPage()
{
uiBox *hbox;
uiGroup *group;
uiBox *vbox;
uiCombobox *cbox;
uiEditableCombobox *ecbox;
uiRadioButtons *rb;
hbox = uiNewHorizontalBox();
uiBoxSetPadded(hbox, 1);
group = uiNewGroup("Numbers");
uiGroupSetMargined(group, 1);
uiBoxAppend(hbox, uiControl(group), 1);
vbox = uiNewVerticalBox();
uiBoxSetPadded(vbox, 1);
uiGroupSetChild(group, uiControl(vbox));
spinbox = uiNewSpinbox(0, 100);
slider = uiNewSlider(0, 100);
pbar = uiNewProgressBar();
uiSpinboxOnChanged(spinbox, onSpinboxChanged, NULL);
uiSliderOnChanged(slider, onSliderChanged, NULL);
uiBoxAppend(vbox, uiControl(spinbox), 0);
uiBoxAppend(vbox, uiControl(slider), 0);
uiBoxAppend(vbox, uiControl(pbar), 0);
group = uiNewGroup("Lists");
uiGroupSetMargined(group, 1);
uiBoxAppend(hbox, uiControl(group), 1);
vbox = uiNewVerticalBox();
uiBoxSetPadded(vbox, 1);
uiGroupSetChild(group, uiControl(vbox));
cbox = uiNewCombobox();
uiComboboxAppend(cbox, "Combobox Item 1");
uiComboboxAppend(cbox, "Combobox Item 2");
uiComboboxAppend(cbox, "Combobox Item 3");
uiBoxAppend(vbox, uiControl(cbox), 0);
ecbox = uiNewEditableCombobox();
uiEditableComboboxAppend(ecbox, "Editable Item 1");
uiEditableComboboxAppend(ecbox, "Editable Item 2");
uiEditableComboboxAppend(ecbox, "Editable Item 3");
uiBoxAppend(vbox, uiControl(ecbox), 0);
rb = uiNewRadioButtons();
uiRadioButtonsAppend(rb, "Radio Button 1");
uiRadioButtonsAppend(rb, "Radio Button 2");
uiRadioButtonsAppend(rb, "Radio Button 3");
uiBoxAppend(vbox, uiControl(rb), 0);
return uiControl(hbox);
}
// TODO make this not global
static uiWindow *mainwin;
static void onOpenFileClicked(uiButton *b, void *data)
{
uiEntry *entry = uiEntry(data);
char *filename;
filename = uiOpenFile(mainwin);
if (filename == NULL) {
uiEntrySetText(entry, "(cancelled)");
return;
}
uiEntrySetText(entry, filename);
uiFreeText(filename);
}
static void onSaveFileClicked(uiButton *b, void *data)
{
uiEntry *entry = uiEntry(data);
char *filename;
filename = uiSaveFile(mainwin);
if (filename == NULL) {
uiEntrySetText(entry, "(cancelled)");
return;
}
uiEntrySetText(entry, filename);
uiFreeText(filename);
}
static uiControl *makeDataChoosersPage(void)
{
uiBox *hbox;
uiBox *vbox;
uiGrid *grid;
uiButton *button;
uiEntry *entry;
hbox = uiNewHorizontalBox();
uiBoxSetPadded(hbox, 1);
vbox = uiNewVerticalBox();
uiBoxSetPadded(vbox, 1);
uiBoxAppend(hbox, uiControl(vbox), 0);
uiBoxAppend(vbox,
uiControl(uiNewDatePicker()),
0);
uiBoxAppend(vbox,
uiControl(uiNewTimePicker()),
0);
uiBoxAppend(vbox,
uiControl(uiNewDateTimePicker()),
0);
uiBoxAppend(vbox,
uiControl(uiNewFontButton()),
0);
uiBoxAppend(vbox,
uiControl(uiNewColorButton()),
0);
vbox = uiNewVerticalBox();
uiBoxSetPadded(vbox, 1);
uiBoxAppend(hbox, uiControl(vbox), 1);
grid = uiNewGrid();
uiGridSetPadded(grid, 1);
uiBoxAppend(vbox, uiControl(grid), 0);
button = uiNewButton("Open File");
entry = uiNewEntry();
uiEntrySetReadOnly(entry, 1);
uiButtonOnClicked(button, onOpenFileClicked, entry);
uiGridAppend(grid, uiControl(button),
0, 0, 1, 1,
0, uiAlignFill, 0, uiAlignFill);
uiGridAppend(grid, uiControl(entry),
1, 0, 1, 1,
1, uiAlignFill, 0, uiAlignFill);
button = uiNewButton("Save File");
entry = uiNewEntry();
uiEntrySetReadOnly(entry, 1);
uiButtonOnClicked(button, onSaveFileClicked, entry);
uiGridAppend(grid, uiControl(button),
0, 1, 1, 1,
0, uiAlignFill, 0, uiAlignFill);
uiGridAppend(grid, uiControl(entry),
1, 1, 1, 1,
1, uiAlignFill, 0, uiAlignFill);
return uiControl(hbox);
}
int main(void) int main(void)
{ {
uiInitOptions options; uiInitOptions options;
const char *err; const char *err;
uiWindow *mainwin;
uiTab *tab; uiTab *tab;
memset(&options, 0, sizeof (uiInitOptions)); memset(&options, 0, sizeof (uiInitOptions));
@ -104,6 +274,12 @@ int main(void)
uiTabAppend(tab, "Basic Controls", makeBasicControlsPage()); uiTabAppend(tab, "Basic Controls", makeBasicControlsPage());
uiTabSetMargined(tab, 0, 1); uiTabSetMargined(tab, 0, 1);
uiTabAppend(tab, "Numbers and Lists", makeNumbersPage());
uiTabSetMargined(tab, 1, 1);
uiTabAppend(tab, "Data Choosers", makeDataChoosersPage());
uiTabSetMargined(tab, 2, 1);
uiControlShow(uiControl(mainwin)); uiControlShow(uiControl(mainwin));
uiMain(); uiMain();
return 0; return 0;