uiMenuItem *uiMenuAppendSubmenu(uiMenu *m, uiMenu* child) { uiMenuItem *item; if (menusFinalized) userbug("You cannot create a new menu item after menus have been finalized."); item = uiNew(uiMenuItem); g_array_append_val(m->items, item); item->type = typeSubmenu; item->name = child->name; uiMenuItemOnClicked(item, defaultOnClicked, NULL); // checkme item->gtype = GTK_TYPE_MENU_ITEM; item->windows = g_hash_table_new(g_direct_hash, g_direct_equal); item->popupchild = child; child->ischild = TRUE; return item; }
static Janet janet_ui_menu_item_on_clicked(int32_t argc, Janet *argv) { janet_fixarity(argc, 2); uiMenuItem *mi = janet_getuitype(argv, 0, &menu_item_td); assert_callable(argv, 1); void *handle = janet_ui_to_handler_data(argv[1]); uiMenuItemOnClicked(mi, menu_item_on_clicked, handle); return argv[0]; }
static uiMenuItem *newItem(uiMenu *m, int type, const char *name) { uiMenuItem *item; if (menusFinalized) userbug("You cannot create a new menu item after menus have been finalized."); item = uiNew(uiMenuItem); g_array_append_val(m->items, item); item->type = type; switch (item->type) { case typeQuit: item->name = g_strdup("Quit"); break; case typePreferences: item->name = g_strdup("Preferences..."); break; case typeAbout: item->name = g_strdup("About"); break; case typeSeparator: break; default: item->name = g_strdup(name); break; } if (item->type == typeQuit) { // can't call uiMenuItemOnClicked() here item->onClicked = onQuitClicked; item->onClickedData = NULL; } else uiMenuItemOnClicked(item, defaultOnClicked, NULL); switch (item->type) { case typeCheckbox: item->gtype = GTK_TYPE_CHECK_MENU_ITEM; break; case typeSeparator: item->gtype = GTK_TYPE_SEPARATOR_MENU_ITEM; break; default: item->gtype = GTK_TYPE_MENU_ITEM; break; } item->windows = g_hash_table_new(g_direct_hash, g_direct_equal); item->popupchild = NULL; return item; }
static uiMenuItem *newItem(uiMenu *m, int type, const char *name) { uiMenuItem *item; if (menusFinalized) userbug("You can not create a new menu item after menus have been finalized."); if (m->len >= m->cap) { m->cap += grow; m->items = (uiMenuItem **) uiRealloc(m->items, m->cap * sizeof (uiMenuItem *), "uiMenuitem *[]"); } item = uiNew(uiMenuItem); m->items[m->len] = item; m->len++; item->type = type; switch (item->type) { case typeQuit: item->name = toUTF16("Quit"); break; case typePreferences: item->name = toUTF16("Preferences..."); break; case typeAbout: item->name = toUTF16("About"); break; case typeSeparator: break; default: item->name = toUTF16(name); break; } if (item->type != typeSeparator) { item->id = curID; curID++; } if (item->type == typeQuit) { // can't call uiMenuItemOnClicked() here item->onClicked = onQuitClicked; item->onClickedData = NULL; } else uiMenuItemOnClicked(item, defaultOnClicked, NULL); return item; }
int main(void) { uiInitOptions o; const char *err; uiMenu *menu; uiMenuItem *item; uiBox *box; uiBox *hbox; uiGroup *group; uiBox *inner; uiBox *inner2; uiEntry *entry; uiCombobox *cbox; uiRadioButtons *rb; uiTab *tab; memset(&o, 0, sizeof (uiInitOptions)); err = uiInit(&o); if (err != NULL) { fprintf(stderr, "error initializing ui: %s\n", err); uiFreeInitError(err); return 1; } menu = uiNewMenu("File"); item = uiMenuAppendItem(menu, "Open"); uiMenuItemOnClicked(item, openClicked, NULL); item = uiMenuAppendItem(menu, "Save"); uiMenuItemOnClicked(item, saveClicked, NULL); item = uiMenuAppendQuitItem(menu); uiOnShouldQuit(shouldQuit, NULL); menu = uiNewMenu("Edit"); item = uiMenuAppendCheckItem(menu, "Checkable Item"); uiMenuAppendSeparator(menu); item = uiMenuAppendItem(menu, "Disabled Item"); uiMenuItemDisable(item); item = uiMenuAppendPreferencesItem(menu); menu = uiNewMenu("Help"); item = uiMenuAppendItem(menu, "Help"); item = uiMenuAppendAboutItem(menu); mainwin = uiNewWindow("libui Control Gallery", 640, 480, 1); uiWindowSetMargined(mainwin, 1); uiWindowOnClosing(mainwin, onClosing, NULL); box = uiNewVerticalBox(); uiBoxSetPadded(box, 1); uiWindowSetChild(mainwin, uiControl(box)); hbox = uiNewHorizontalBox(); uiBoxSetPadded(hbox, 1); uiBoxAppend(box, uiControl(hbox), 1); group = uiNewGroup("Basic Controls"); uiGroupSetMargined(group, 1); uiBoxAppend(hbox, uiControl(group), 0); inner = uiNewVerticalBox(); uiBoxSetPadded(inner, 1); uiGroupSetChild(group, uiControl(inner)); uiBoxAppend(inner, uiControl(uiNewButton("Button")), 0); uiBoxAppend(inner, uiControl(uiNewCheckbox("Checkbox")), 0); entry = uiNewEntry(); uiEntrySetText(entry, "Entry"); uiBoxAppend(inner, uiControl(entry), 0); uiBoxAppend(inner, uiControl(uiNewLabel("Label")), 0); uiBoxAppend(inner, uiControl(uiNewHorizontalSeparator()), 0); uiBoxAppend(inner, uiControl(uiNewDatePicker()), 0); uiBoxAppend(inner, uiControl(uiNewTimePicker()), 0); uiBoxAppend(inner, uiControl(uiNewDateTimePicker()), 0); uiBoxAppend(inner, uiControl(uiNewFontButton()), 0); uiBoxAppend(inner, uiControl(uiNewColorButton()), 0); inner2 = uiNewVerticalBox(); uiBoxSetPadded(inner2, 1); uiBoxAppend(hbox, uiControl(inner2), 1); group = uiNewGroup("Numbers"); uiGroupSetMargined(group, 1); uiBoxAppend(inner2, uiControl(group), 0); inner = uiNewVerticalBox(); uiBoxSetPadded(inner, 1); uiGroupSetChild(group, uiControl(inner)); spinbox = uiNewSpinbox(0, 100); uiSpinboxOnChanged(spinbox, onSpinboxChanged, NULL); uiBoxAppend(inner, uiControl(spinbox), 0); slider = uiNewSlider(0, 100); uiSliderOnChanged(slider, onSliderChanged, NULL); uiBoxAppend(inner, uiControl(slider), 0); progressbar = uiNewProgressBar(); uiBoxAppend(inner, uiControl(progressbar), 0); group = uiNewGroup("Lists"); uiGroupSetMargined(group, 1); uiBoxAppend(inner2, uiControl(group), 0); inner = uiNewVerticalBox(); uiBoxSetPadded(inner, 1); uiGroupSetChild(group, uiControl(inner)); cbox = uiNewCombobox(); uiComboboxAppend(cbox, "Combobox Item 1"); uiComboboxAppend(cbox, "Combobox Item 2"); uiComboboxAppend(cbox, "Combobox Item 3"); uiBoxAppend(inner, uiControl(cbox), 0); cbox = uiNewEditableCombobox(); uiComboboxAppend(cbox, "Editable Item 1"); uiComboboxAppend(cbox, "Editable Item 2"); uiComboboxAppend(cbox, "Editable Item 3"); uiBoxAppend(inner, uiControl(cbox), 0); rb = uiNewRadioButtons(); uiRadioButtonsAppend(rb, "Radio Button 1"); uiRadioButtonsAppend(rb, "Radio Button 2"); uiRadioButtonsAppend(rb, "Radio Button 3"); uiBoxAppend(inner, uiControl(rb), 1); tab = uiNewTab(); uiTabAppend(tab, "Page 1", uiControl(uiNewHorizontalBox())); uiTabAppend(tab, "Page 2", uiControl(uiNewHorizontalBox())); uiTabAppend(tab, "Page 3", uiControl(uiNewHorizontalBox())); uiBoxAppend(inner2, uiControl(tab), 1); uiControlShow(uiControl(mainwin)); uiMain(); uiUninit(); return 0; }