--- a/application/main.c Thu Nov 14 17:26:16 2024 +0100 +++ b/application/main.c Fri Nov 15 21:16:18 2024 +0100 @@ -216,6 +216,29 @@ } } +static UiObject *ref_window; + +void action_button_ref(UiEvent *event, void *userdata) { + UiObject *obj = event->obj; + printf("action_button_ref: %u\n", obj->ref); + ui_object_ref(obj); + ref_window = obj; +} + +void action_button_unref(UiEvent *event, void *userdata) { + UiObject *obj = userdata; + printf("action_button_unref: %u\n", obj->ref); + ui_object_unref(obj); +} + +void action_toolbar_unrefwindow(UiEvent *event, void *userdata) { + UiObject *obj = ui_simple_window("Unref", NULL); + ui_grid(obj, .margin = 20) { + ui_button(obj, .label = "Unref", .onclick = action_button_unref, .onclickdata = ref_window); + } + ui_show(obj); +} + void application_startup(UiEvent *event, void *data) { // global list UiContext *global = ui_global_context(); @@ -283,8 +306,8 @@ ui_tab(obj, "Tab 2") { ui_button(obj, .label = "Button 1 Start Thread", .onclick=action_start_thread); ui_button(obj, .label = "Button 2 Notify Thread", .onclick=action_notify_thread); - ui_button(obj, .label = "Button 3", .onclick=action_tab2_button); - ui_button(obj, .label = "Button 4", .onclick=action_tab2_button); + ui_button(obj, .label = "Obj Ref", .onclick=action_button_ref); + ui_button(obj, .label = "Obj Unref", .onclick=action_button_unref, .onclickdata = obj); ui_button(obj, .label = "Button 5", .onclick=action_tab2_button); ui_button(obj, .label = "Button 6", .onclick=action_tab2_button); } @@ -349,7 +372,7 @@ ui_toolbar_item("Test", .label = "Test", .onclick = action_toolbar_button); ui_toolbar_item("Test2", .label = "New Window", .onclick = action_toolbar_newwindow); ui_toolbar_item("Test3", .label = "Dialog", .onclick = action_toolbar_dialog); - ui_toolbar_item("Test4", .label = "Test 4", .onclick = action_toolbar_button); + ui_toolbar_item("Test4", .label = "Unref Window", .onclick = action_toolbar_unrefwindow); ui_toolbar_item("Test5", .label = "Test 5", .onclick = action_toolbar_button); ui_toolbar_item("Test6", .label = "Test 6", .onclick = action_toolbar_button); ui_toolbar_toggleitem("Toggle", .label = "Toggle", .onchange = action_toolbar_button);