2 weeks ago
implement tabview UiInteger binding (Motif)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/motif/container.c | file | annotate | diff | comparison | revisions | |
ui/motif/container.h | file | annotate | diff | comparison | revisions |
--- a/application/main.c Sun Feb 23 17:10:45 2025 +0100 +++ b/application/main.c Mon Feb 24 22:08:27 2025 +0100 @@ -609,6 +609,7 @@ UiString *path; UiList *list; UiInteger *spinner; + UiInteger *tab; } WData; @@ -642,6 +643,12 @@ ui_tabview_remove(wdata->tabview, 2); } +static void action_next_tab(UiEvent *event, void *data) { + WData *wdata = event->window; + int index = ui_get(wdata->tab); + ui_set(wdata->tab, index+1); +} + void application_startup(UiEvent *event, void *data) { menulist = ui_list_new(ui_global_context(), "menulist"); @@ -656,6 +663,7 @@ wdata->path = ui_string_new(obj->ctx, NULL); wdata->list = ui_list_new(obj->ctx, NULL); wdata->spinner = ui_int_new(obj->ctx, NULL); + wdata->tab = ui_int_new(obj->ctx, NULL); obj->window = wdata; ui_list_append(wdata->list, "List Item 1"); @@ -675,8 +683,8 @@ .onselection = action_listevent, .onselectiondata = "selection"); */ - - ui_tabview_w(obj, wdata->tabview, .tabview = UI_TABVIEW_NAVIGATION_TOP, .fill = UI_ON) { + ui_button(obj, .label = "Next Tab", .onclick = action_next_tab); + ui_tabview_w(obj, wdata->tabview, .tabview = UI_TABVIEW_INVISIBLE, .value = wdata->tab, .fill = UI_ON) { ui_tab(obj, "Tab 1") { ui_textarea(obj, .varname = "text", .fill = UI_ON); }
--- a/ui/motif/container.c Sun Feb 23 17:10:45 2025 +0100 +++ b/ui/motif/container.c Mon Feb 24 22:08:27 2025 +0100 @@ -226,6 +226,10 @@ static void ui_tabbar_resize(Widget widget, XtPointer udata, XtPointer cdata) { UiMotifTabView *tabview = udata; + if(tabview->tabview == UI_TABVIEW_INVISIBLE) { + return; + } + int width = 0; int height = 0; XtVaGetValues(widget, XmNwidth, &width, XmNheight, &height, NULL); @@ -326,7 +330,8 @@ tabview->select = ui_motif_tabview_select; tabview->add = ui_motif_tabview_add_tab; tabview->remove = ui_motif_tabview_remove; - tabview->tabs = cxArrayListCreate(obj->ctx->allocator, NULL, sizeof(UiTab), 8); + tabview->tabs = cxArrayListCreate(obj->ctx->allocator, cx_cmp_ptr, sizeof(UiTab), 8); + tabview->current_index = -1; UiTabViewContainer *ct = ui_malloc(obj->ctx, sizeof(UiTabViewContainer)); ct->container.widget = form; @@ -335,11 +340,33 @@ ct->container.add = ui_tabview_container_add; ct->tabview = tabview; + UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_INTEGER); + if(var) { + UiInteger *i = var->value; + i->obj = tabview; + i->get = ui_tabview_get; + i->set = ui_tabview_set; + } + uic_object_push_container(obj, (UiContainerX*)ct); return form; } +int64_t ui_tabview_get(UiInteger *i) { + UiMotifTabView *tabview = i->obj; + i->value = tabview->current_index; + return i->value; +} + +void ui_tabview_set(UiInteger *i, int64_t value) { + UiMotifTabView *tabview = i->obj; + if(value < cxListSize(tabview->tabs)) { + ui_motif_tabview_select(tabview, value); + i->value = value; + } +} + void ui_tab_create(UiObject *obj, const char* title) { UiContainerPrivate *ctn = ui_obj_container(obj); if(ctn->type != UI_CONTAINER_TABVIEW) { @@ -416,6 +443,7 @@ void ui_motif_tabview_select(UiMotifTabView *tabview, int tab) { UiTab *t = cxListAt(tabview->tabs, tab); if(t) { + tabview->current_index = tab; ui_motif_tabview_change_tab(tabview, t); } } @@ -439,7 +467,9 @@ XtSetArg(args[n], XmNuserData, tabview); n++; Widget button = XmCreatePushButton(tabview->tabbar, "tab_button", args, n); - XtManageChild(button); + if(tabview->tabview != UI_TABVIEW_INVISIBLE) { + XtManageChild(button); + } if(tabview->height == 0) { Dimension h; @@ -489,6 +519,7 @@ ui_motif_tabview_select(tabview, index+1); } else { tabview->current_tab = NULL; + tabview->current_index = -1; } } } @@ -505,6 +536,7 @@ } XtVaSetValues(tab->tab_button, XmNshadowThickness, 1, XmNbackground, tabview->bg2, NULL); tabview->current_tab = tab; + tabview->current_index = (int)cxListFind(tabview->tabs, tab);; XtManageChild(tab->child); }
--- a/ui/motif/container.h Sun Feb 23 17:10:45 2025 +0100 +++ b/ui/motif/container.h Mon Feb 24 22:08:27 2025 +0100 @@ -117,6 +117,7 @@ Widget content; Widget current; UiTab *current_tab; + int current_index; int height; Pixel bg1; Pixel bg2; @@ -140,6 +141,8 @@ void ui_motif_tabview_add_tab(UiMotifTabView *tabview, int index, const char *name, Widget child); void ui_motif_tabview_remove(UiMotifTabView *tabview, int index); void ui_motif_tabview_change_tab(UiMotifTabView *tabview, UiTab *tab); +int64_t ui_tabview_get(UiInteger *i); +void ui_tabview_set(UiInteger *i, int64_t value); Widget ui_tabview_container_prepare(UiContainerPrivate *ctn, Arg *args, int *n); void ui_tabview_container_add(UiContainerPrivate *ctn, Widget widget);