--- a/application/main.c Thu Sep 26 22:43:13 2024 +0200 +++ b/application/main.c Sun Sep 29 11:29:37 2024 +0200 @@ -39,6 +39,7 @@ UiString *path; UiDouble *progress; UiList *list; + UiList *menulist; UiInteger *radio; } MyDocument; @@ -101,8 +102,31 @@ return col == 0 ? str : "x"; } +static UiList *menu_list; +int new_item_count = 0; + +void action_add_menu_item(UiEvent *event, void *userdata) { + char str[64]; + snprintf(str, 64, "new item %d", new_item_count++); + + ui_list_append(menu_list, strdup(str)); + ui_list_notify(menu_list); +} + +void action_menu_list(UiEvent *event, void *userdata) { + printf("menu list item: %d\n", event->intval); +} + void application_startup(UiEvent *event, void *data) { - + // global list + UiContext *global = ui_global_context(); + menu_list = ui_list_new(global, "menulist"); + ui_list_append(menu_list, "menu list item 1"); + ui_list_append(menu_list, "menu list item 2"); + ui_list_append(menu_list, "menu list item 3"); + + + UiObject *obj = ui_window("Test", NULL); MyDocument *doc = create_doc(); @@ -171,10 +195,12 @@ ui_toolbar_item("Test6", .label = "Test 6", .onclick = action_toolbar_button); ui_toolbar_toggleitem("Toggle", .label = "Toggle", .onchange = action_toolbar_button); ui_toolbar_menu("Menu", .label = "Menu") { - ui_menuitem("Secondary Test", NULL, NULL); + ui_menuitem("Secondary Test", .onclick = action_toolbar_button, NULL); ui_menu("Secondary Sub") { ui_menuitem("Secondary subitem", NULL, NULL); } + ui_menu_itemlist(.varname = "menulist", .onselect=action_menu_list); + ui_menuitem("last", .onclick = action_add_menu_item); } ui_toolbar_add_default("Test", UI_TOOLBAR_LEFT);