Tue, 08 Oct 2024 22:53:27 +0200
implement side navigation tabview (GTK)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/gtk/container.c | file | annotate | diff | comparison | revisions | |
ui/gtk/toolkit.h | file | annotate | diff | comparison | revisions |
--- a/application/main.c Tue Oct 08 22:19:24 2024 +0200 +++ b/application/main.c Tue Oct 08 22:53:27 2024 +0200 @@ -134,7 +134,7 @@ MyDocument *doc = create_doc(); ui_attach_document(obj->ctx, doc); - ui_tabview(obj, .spacing=10, .margin=10) { + ui_tabview(obj, .spacing=10, .margin=10, .tabview = UI_TABVIEW_NAVIGATION_SIDE) { ui_tab(obj, "Tab 1") { ui_vbox(obj, .fill = UI_OFF, .margin = 15, .spacing = 15) { ui_button(obj, .label = "Test Button", .icon = "application-x-generic", .onclick = action_button); @@ -179,6 +179,9 @@ } } } + ui_tab(obj, "Tab 2") { + ui_button(obj, .label = "Button"); + } } /*
--- a/ui/gtk/container.c Tue Oct 08 22:19:24 2024 +0200 +++ b/ui/gtk/container.c Tue Oct 08 22:53:27 2024 +0200 @@ -332,10 +332,6 @@ } -void ui_select_tab(UIWIDGET tabview, int tab) { - gtk_notebook_set_current_page(GTK_NOTEBOOK(tabview), tab); -} - void ui_notebook_tab_select(UIWIDGET tabview, int tab) { gtk_notebook_set_current_page(GTK_NOTEBOOK(tabview), tab); } @@ -364,6 +360,28 @@ i->value = gtk_notebook_get_current_page(nb); } + +void ui_stack_tab_select(UIWIDGET tabview, int tab) { + +} + +void ui_stack_tab_remove(UIWIDGET tabview, int tab) { + +} + +void ui_stack_tab_add(UIWIDGET widget, int index, const char *name, UIWIDGET child) { + GtkStackPage *page = gtk_stack_add_titled(GTK_STACK(widget), child, name, name); +} + +int64_t ui_stack_get(UiInteger *i) { + +} + +void ui_stack_set(UiInteger *i, int64_t value) { + +} + + UiGtkTabView* ui_widget_get_tabview_data(UIWIDGET tabview) { return g_object_get_data(G_OBJECT(tabview), "ui_tabview"); } @@ -382,19 +400,37 @@ ui_tabview_set_func setfunc = NULL; GtkWidget *widget = NULL; + GtkWidget *data_widget = NULL; switch(args.tabview) { case UI_TABVIEW_DOC: { // TODO break; } case UI_TABVIEW_NAVIGATION_SIDE: { +#if GTK_CHECK_VERSION(3, 10, 0) + widget = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + GtkWidget *sidebar = gtk_stack_sidebar_new(); + BOX_ADD(widget, sidebar); + GtkWidget *stack = gtk_stack_new(); + gtk_stack_set_transition_type (GTK_STACK(stack), GTK_STACK_TRANSITION_TYPE_SLIDE_UP_DOWN); + gtk_stack_sidebar_set_stack(GTK_STACK_SIDEBAR(sidebar), GTK_STACK(stack)); + BOX_ADD_EXPAND(widget, stack); + data->select_tab = ui_stack_tab_select; + data->remove_tab = ui_stack_tab_remove; + data->add_tab = ui_stack_tab_add; + getfunc = ui_stack_get; + setfunc = ui_stack_set; + data_widget = stack; +#else // TODO +#endif break; } case UI_TABVIEW_DEFAULT: /* fall through */ case UI_TABVIEW_NAVIGATION_TOP: /* fall through */ case UI_TABVIEW_NAVIGATION_TOP2: { widget = gtk_notebook_new(); + data_widget = widget; data->select_tab = ui_notebook_tab_select; data->remove_tab = ui_notebook_tab_remove; data->add_tab = ui_notebook_tab_add; @@ -419,7 +455,7 @@ } g_object_set_data(G_OBJECT(widget), "ui_tabview", data); - data->widget = widget; + data->widget = data_widget; data->subcontainer = args.subcontainer; UI_APPLY_LAYOUT1(current, args); @@ -441,7 +477,7 @@ return; } - UiObject *newobj = ui_tabview_add(data->widget, title, -1); + UiObject *newobj = ui_tabview_add(current->widget, title, -1); current->next = newobj; }
--- a/ui/gtk/toolkit.h Tue Oct 08 22:19:24 2024 +0200 +++ b/ui/gtk/toolkit.h Tue Oct 08 22:53:27 2024 +0200 @@ -59,6 +59,8 @@ #define WINDOW_DESTROY(window) gtk_window_destroy(GTK_WINDOW(window)) #define WINDOW_SET_CONTENT(window, child) gtk_window_set_child(GTK_WINDOW(window), child) #define BOX_ADD(box, child) gtk_box_append(GTK_BOX(box), child) +#define BOX_ADD_EXPAND(box, child) gtk_widget_set_hexpand(child, TRUE); gtk_box_append(GTK_BOX(box), child) +#define BOX_ADD_NO_EXPAND(box, child) gtk_box_append(GTK_BOX(box), child) #define ENTRY_SET_TEXT(entry, text) gtk_editable_set_text(GTK_EDITABLE(entry), text) #define ENTRY_GET_TEXT(entry) gtk_editable_get_text(GTK_EDITABLE(entry)) #define SCROLLEDWINDOW_NEW() gtk_scrolled_window_new() @@ -71,6 +73,8 @@ #define WINDOW_DESTROY(window) gtk_widget_destroy(window) #define WINDOW_SET_CONTENT(window, child) gtk_container_add(GTK_CONTAINER(window), child) #define BOX_ADD(box, child) gtk_box_pack_end(GTK_BOX(box), child, TRUE, TRUE, 0) +#define BOX_ADD_EXPAND(box, child) gtk_box_pack_end(GTK_BOX(box), child, TRUE, TRUE, 0) +#define BOX_ADD_NO_EXPAND(box, child) gtk_box_pack_end(GTK_BOX(box), child, TRUE, FALSE, 0) #define ENTRY_SET_TEXT(entry, text) gtk_entry_set_text(GTK_ENTRY(entry), text) #define ENTRY_GET_TEXT(entry) gtk_entry_get_text(GTK_ENTRY(entry)) #define SCROLLEDWINDOW_NEW() gtk_scrolled_window_new(NULL, NULL)