ui/gtk/window.c

branch
newapi
changeset 409
86fbc80f0be7
parent 400
a1946c97de09
child 410
a080c69125d1
--- a/ui/gtk/window.c	Thu Dec 05 08:40:37 2024 +0100
+++ b/ui/gtk/window.c	Thu Dec 05 16:44:05 2024 +0100
@@ -101,7 +101,7 @@
 }
 #endif
 
-static UiObject* create_window(const char *title, void *window_data, UiBool simple) {
+static UiObject* create_window(const char *title, void *window_data, UiBool sidebar, UiBool simple) {
     CxMempool *mp = cxBasicMempoolCreate(256);
     UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject));
     obj->ref = 0;
@@ -163,8 +163,24 @@
     GtkWidget *vbox = ui_gtk_vbox_new(0);
 #ifdef UI_LIBADWAITA
     GtkWidget *toolbar_view = adw_toolbar_view_new();
-    adw_application_window_set_content(ADW_APPLICATION_WINDOW(obj->widget), toolbar_view);
     adw_toolbar_view_set_content(ADW_TOOLBAR_VIEW(toolbar_view), vbox);
+    
+    if(sidebar) {
+        GtkWidget *splitview = adw_overlay_split_view_new();
+        adw_application_window_set_content(ADW_APPLICATION_WINDOW(obj->widget), splitview);
+        
+        GtkWidget *sidebar_toolbar_view = adw_toolbar_view_new();
+        adw_overlay_split_view_set_sidebar(ADW_OVERLAY_SPLIT_VIEW(splitview), sidebar_toolbar_view);
+        GtkWidget *sidebar_headerbar = adw_header_bar_new();
+        adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(sidebar_toolbar_view), sidebar_headerbar);
+        
+        adw_overlay_split_view_set_content(ADW_OVERLAY_SPLIT_VIEW(splitview), toolbar_view);
+        
+        g_object_set_data(G_OBJECT(obj->widget), "ui_sidebar", sidebar_toolbar_view);
+    } else {
+        adw_application_window_set_content(ADW_APPLICATION_WINDOW(obj->widget), toolbar_view);
+    }
+    
 
     GtkWidget *headerbar = adw_header_bar_new();
     adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(toolbar_view), headerbar);
@@ -223,11 +239,15 @@
 
 
 UiObject* ui_window(const char *title, void *window_data) {
-    return create_window(title, window_data, FALSE);
+    return create_window(title, window_data, FALSE, FALSE);
+}
+
+UiObject *ui_sidebar_window(const char *title, void *window_data) {
+    return create_window(title, window_data, TRUE, FALSE);
 }
 
 UiObject* ui_simple_window(const char *title, void *window_data) {
-    return create_window(title, window_data, TRUE);
+    return create_window(title, window_data, FALSE, TRUE);
 }
 
 void ui_window_size(UiObject *obj, int width, int height) {

mercurial