implement ui_menuseparator (GTK4) newapi

Thu, 03 Oct 2024 15:37:55 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 03 Oct 2024 15:37:55 +0200
branch
newapi
changeset 322
22f6dadd9f46
parent 321
8d63b7cd3d98
child 323
38cb8e3992e8

implement ui_menuseparator (GTK4)

application/main.c file | annotate | diff | comparison | revisions
ui/gtk/headerbar.c file | annotate | diff | comparison | revisions
ui/gtk/menu.c file | annotate | diff | comparison | revisions
--- a/application/main.c	Thu Oct 03 11:58:09 2024 +0200
+++ b/application/main.c	Thu Oct 03 15:37:55 2024 +0200
@@ -201,10 +201,22 @@
         ui_menu("Secondary Sub") {
             ui_menuitem("Secondary subitem", NULL, NULL);
         }
+        ui_menuseparator();
         ui_menu_itemlist(.varname = "menulist", .onselect=action_menu_list);
+        ui_menuseparator();
         ui_menuitem("last", .onclick = action_add_menu_item);
     }
     
+    ui_toolbar_appmenu() {
+        ui_menuitem("New");
+        ui_menuitem("Open");
+        ui_menuitem("Save");
+        
+        ui_menuseparator();
+        
+        ui_menuitem("Close");
+    }
+    
     ui_toolbar_add_default("Test", UI_TOOLBAR_LEFT);
     ui_toolbar_add_default("Test6", UI_TOOLBAR_LEFT);
     ui_toolbar_add_default("Toggle", UI_TOOLBAR_LEFT);
--- a/ui/gtk/headerbar.c	Thu Oct 03 11:58:09 2024 +0200
+++ b/ui/gtk/headerbar.c	Thu Oct 03 15:37:55 2024 +0200
@@ -58,6 +58,11 @@
     
     ui_headerbar_add_items(obj, headerbar, left_defaults, UI_TOOLBAR_LEFT);
     ui_headerbar_add_items(obj, headerbar, center_defaults, UI_TOOLBAR_CENTER);
+    
+    UiToolbarMenuItem *appmenu = uic_get_appmenu();
+    if(appmenu) {
+        ui_add_headerbar_menu(headerbar, NULL, appmenu, obj, UI_TOOLBAR_RIGHT);
+    }
     ui_headerbar_add_items(obj, headerbar, right_defaults, UI_TOOLBAR_RIGHT);
 }
 
@@ -163,6 +168,10 @@
         gtk_menu_button_set_icon_name(GTK_MENU_BUTTON(menubutton), item->args.icon); 
     }
     
+    if(!item->args.label && !item->args.icon) {
+        gtk_menu_button_set_icon_name(GTK_MENU_BUTTON(menubutton), "open-menu-symbolic"); 
+    }
+    
     GMenu *menu = g_menu_new();
     ui_gmenu_add_menu_items(menu, 0, &item->menu, obj);
     
--- a/ui/gtk/menu.c	Thu Oct 03 11:58:09 2024 +0200
+++ b/ui/gtk/menu.c	Thu Oct 03 15:37:55 2024 +0200
@@ -522,10 +522,22 @@
 void ui_gmenu_add_menu_items(GMenu *parent, int i, UiMenu *menu, UiObject *obj) {
     UiMenuItemI *it = menu->items_begin;
     int index = 0;
+    int index_section = 0;
+    GMenu *section = NULL;
     while(it) {
-        createMenuItem[it->type](parent, index, it, obj);
+        if(it->type == UI_MENU_SEPARATOR) {
+            section = g_menu_new();
+            g_menu_append_section(parent, NULL, G_MENU_MODEL(section));
+            index++;
+            index_section = 0;
+        } else {
+            if(section) {
+                createMenuItem[it->type](section, index_section++, it, obj);
+            } else {
+                createMenuItem[it->type](parent, index++, it, obj);
+            }
+        }
         it = it->next;
-        index++;
     }
 }
 
@@ -563,7 +575,7 @@
     }
     
     char action_name[32];
-    snprintf(action_name, 32, "win.%s", item->id);
+    snprintf(action_name, 32, "win.%s", item->id); 
     g_menu_append(parent, i->label, action_name);
 }
 

mercurial