add sidebar implementation (GTK) newapi

Thu, 05 Dec 2024 20:02:30 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 05 Dec 2024 20:02:30 +0100
branch
newapi
changeset 410
a080c69125d1
parent 409
86fbc80f0be7
child 411
3e91b7aff6a1

add sidebar implementation (GTK)

ui/gtk/container.c file | annotate | diff | comparison | revisions
ui/gtk/window.c file | annotate | diff | comparison | revisions
--- a/ui/gtk/container.c	Thu Dec 05 16:44:05 2024 +0100
+++ b/ui/gtk/container.c	Thu Dec 05 20:02:30 2024 +0100
@@ -911,6 +911,20 @@
     
     return box;
 }
+#else
+UIWIDGET ui_sidebar_create(UiObject *obj, UiSidebarArgs args) {
+    GtkWidget *sidebar_vbox = g_object_get_data(G_OBJECT(obj->widget), "ui_sidebar");
+    
+    GtkWidget *box = ui_gtk_vbox_new(args.spacing);
+    ui_box_set_margin(box, args.margin);
+    BOX_ADD_EXPAND(sidebar_vbox, box);
+    
+    UiObject *newobj = uic_object_new(obj, box);
+    newobj->container = ui_box_container(obj, box, UI_CONTAINER_VBOX);
+    uic_obj_add(obj, newobj);
+    
+    return box;
+}
 #endif
 
 /* -------------------- Splitpane -------------------- */
--- a/ui/gtk/window.c	Thu Dec 05 16:44:05 2024 +0100
+++ b/ui/gtk/window.c	Thu Dec 05 20:02:30 2024 +0100
@@ -190,10 +190,19 @@
         ui_fill_headerbar(obj, headerbar);
     }
 #elif GTK_MAJOR_VERSION >= 4
+    GtkWidget *content_box = ui_gtk_vbox_new(0);
     WINDOW_SET_CONTENT(obj->widget, vbox);
+    if(sidebar) {
+        GtkWidget *paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
+        GtkWidget *sidebar_vbox = ui_gtk_vbox_new(0);
+        gtk_paned_set_start_child(GTK_PANED(paned), sidebar_vbox);
+        gtk_paned_set_end_child(GTK_PANED(paned), content_box);
+        BOX_ADD_EXPAND(GTK_BOX(vbox), paned);
+        g_object_set_data(G_OBJECT(obj->widget), "ui_sidebar", sidebar_vbox);
+    } else {
+        BOX_ADD_EXPAND(GTK_BOX(vbox), content_box);
+    }
 #else
-    gtk_container_add(GTK_CONTAINER(obj->widget), vbox);
-    
     if(!simple) {
         // menu
         if(uic_get_menu_list()) {
@@ -214,6 +223,20 @@
         //GtkWidget *hb = ui_create_headerbar(obj);
         //gtk_window_set_titlebar(GTK_WINDOW(obj->widget), hb);
     }
+    
+    GtkWidget *content_box = ui_gtk_vbox_new(0);
+    WINDOW_SET_CONTENT(obj->widget, vbox);
+    if(sidebar) {
+        GtkWidget *paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
+        GtkWidget *sidebar_vbox = ui_gtk_vbox_new(0);
+        gtk_paned_add1(GTK_PANED(paned), sidebar_vbox);
+        gtk_paned_add2(GTK_PANED(paned), content_box);
+        BOX_ADD_EXPAND(GTK_BOX(vbox), paned);
+        g_object_set_data(G_OBJECT(obj->widget), "ui_sidebar", sidebar_vbox);
+    } else {
+        BOX_ADD_EXPAND(GTK_BOX(vbox), content_box);
+    }
+    
 #endif
     
     // window content
@@ -229,8 +252,6 @@
     gtk_container_add(GTK_CONTAINER(frame), content_box);
     obj->container = ui_box_container(obj, content_box);
     */
-    GtkWidget *content_box = ui_gtk_vbox_new(0);
-    BOX_ADD_EXPAND(GTK_BOX(vbox), content_box);
     obj->container = ui_box_container(obj, content_box, UI_CONTAINER_VBOX);
     
     nwindows++;

mercurial