--- 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); }