add tabview value/varname parameter newapi

Tue, 08 Oct 2024 22:19:24 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 08 Oct 2024 22:19:24 +0200
branch
newapi
changeset 330
d615aa36c98e
parent 329
08ce6680d1cf
child 331
cdad8b7e83db

add tabview value/varname parameter

ui/gtk/container.c file | annotate | diff | comparison | revisions
ui/gtk/container.h file | annotate | diff | comparison | revisions
ui/ui/container.h file | annotate | diff | comparison | revisions
--- a/ui/gtk/container.c	Mon Oct 07 23:26:52 2024 +0200
+++ b/ui/gtk/container.c	Tue Oct 08 22:19:24 2024 +0200
@@ -352,10 +352,25 @@
             index);
 }
 
+int64_t ui_notebook_get(UiInteger *i) {
+    GtkNotebook *nb = i->obj;
+    i->value = gtk_notebook_get_current_page(nb);
+    return i->value;
+}
+
+void ui_notebook_set(UiInteger *i, int64_t value) {
+    GtkNotebook *nb = i->obj;
+    gtk_notebook_set_current_page(nb, value);
+    i->value = gtk_notebook_get_current_page(nb);
+}
+
 UiGtkTabView* ui_widget_get_tabview_data(UIWIDGET tabview) {
     return g_object_get_data(G_OBJECT(tabview), "ui_tabview");
 }
 
+typedef int64_t(*ui_tabview_get_func)(UiInteger*);
+typedef void (*ui_tabview_set_func)(UiInteger*, int64_t);
+
 UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs args) {
     UiGtkTabView *data = malloc(sizeof(UiGtkTabView));
     data->margin = args.margin;
@@ -363,6 +378,9 @@
     data->columnspacing = args.columnspacing;
     data->rowspacing = args.rowspacing;
     
+    ui_tabview_get_func getfunc = NULL;
+    ui_tabview_set_func setfunc = NULL;
+    
     GtkWidget *widget = NULL;
     switch(args.tabview) {
         case UI_TABVIEW_DOC: {
@@ -373,31 +391,37 @@
             // TODO
             break;
         }
-        case UI_TABVIEW_DEFAULT: 
-        case UI_TABVIEW_NAVIGATION_TOP:
+        case UI_TABVIEW_DEFAULT: /* fall through */
+        case UI_TABVIEW_NAVIGATION_TOP: /* fall through */
         case UI_TABVIEW_NAVIGATION_TOP2: {
             widget = gtk_notebook_new();
             data->select_tab = ui_notebook_tab_select;
             data->remove_tab = ui_notebook_tab_remove;
             data->add_tab = ui_notebook_tab_add;
-            break;
+            getfunc = ui_notebook_get;
+            setfunc = ui_notebook_set;
+            /* fall through */
         }
         case UI_TABVIEW_INVISIBLE: {
-            widget = gtk_notebook_new();
             gtk_notebook_set_show_tabs(GTK_NOTEBOOK(widget), FALSE);
             gtk_notebook_set_show_border(GTK_NOTEBOOK(widget), FALSE);
-            data->select_tab = ui_notebook_tab_select;
-            data->remove_tab = ui_notebook_tab_remove;
-            data->add_tab = ui_notebook_tab_add;
             break;
         }
     }
     
+    UiObject* current = uic_current_obj(obj);
+    if(args.value || args.varname) {
+        UiVar *var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER);
+        UiInteger *i = var->value;
+        i->get = getfunc;
+        i->set = setfunc;
+        i->obj = widget;
+    }
+    
     g_object_set_data(G_OBJECT(widget), "ui_tabview", data);
     data->widget = widget;
     data->subcontainer = args.subcontainer;
     
-    UiObject* current = uic_current_obj(obj);
     UI_APPLY_LAYOUT1(current, args);
     current->container->add(current->container, widget, TRUE);
     
--- a/ui/gtk/container.h	Mon Oct 07 23:26:52 2024 +0200
+++ b/ui/gtk/container.h	Tue Oct 08 22:19:24 2024 +0200
@@ -94,6 +94,7 @@
 #endif
 } UiGridContainer;
 
+/*
 typedef struct UiPanedContainer {
     UiContainer container;
     GtkWidget *current_pane;
@@ -101,6 +102,7 @@
     int max;
     int cur;
 } UiPanedContainer;
+*/
 
 typedef struct UiTabViewContainer {
     UiContainer container;
--- a/ui/ui/container.h	Mon Oct 07 23:26:52 2024 +0200
+++ b/ui/ui/container.h	Tue Oct 08 22:19:24 2024 +0200
@@ -97,6 +97,9 @@
     UiTabViewType tabview;
 
     UiSubContainerType subcontainer;
+    
+    UiInteger *value;
+    const char* varname;
 
     int margin;
     int spacing;

mercurial