From 3d42cd041a5147b767a28e42b4494b2fe1a17cdb Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Sun, 14 Jul 2024 08:12:44 +0200 Subject: [PATCH] WIP: Popover MENU <> A robust starting point. --- (notes) | 2 +- src/calls.c | 2 ++ src/widget.c/heads.c | 27 ++++++++++----------------- src/widget.c/menu.c | 2 ++ 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/(notes) b/(notes) index d23ac99..08516ba 100644 --- a/(notes) +++ b/(notes) @@ -1,4 +1,4 @@ - +https://developer.gnome.org/hig/principles.html ================================================================================ diff --git a/src/calls.c b/src/calls.c index 1f99405..23e7323 100644 --- a/src/calls.c +++ b/src/calls.c @@ -358,6 +358,8 @@ void on_clicked_MENU_pop (GtkWidget *btt_reset, gpointer pop) { gtk_button_get_label (GTK_BUTTON (gtk_list_box_row_get_child (gtk_list_box_get_row_at_index (list_box, 1)))), gtk_button_get_label (GTK_BUTTON (gtk_list_box_row_get_child (gtk_list_box_get_row_at_index (list_box, 2))))); + if (0) gtk_popover_popup (GTK_POPOVER (pop)); + // learning_how_to_create_a_menu (menu_button); // https://docs.gtk.org/gtk4/class.ListBox.html diff --git a/src/widget.c/heads.c b/src/widget.c/heads.c index 77be46d..06d0b8d 100644 --- a/src/widget.c/heads.c +++ b/src/widget.c/heads.c @@ -172,29 +172,22 @@ static void window_header_bar (GtkWindow *window, char *title) GtkWidget* list_box = gtk_list_box_new(); - GtkWidget *menu_item_A = GTK_WIDGET (gtk_button_new_with_label ("button_A")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_A); - GtkWidget *menu_item_B = GTK_WIDGET (gtk_button_new_with_label ("button_B")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_B); - GtkWidget *menu_item_C = GTK_WIDGET (gtk_button_new_with_label ("button_C")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_C); -// GtkWidget *menu_item_D = GTK_WIDGET (gtk_button_new_with_label ("button_D")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_D); -// gtk_list_box_append (GTK_LIST_BOX (list_box), gtk_label_new ("any text")); + GtkWidget *menu_item_A = GTK_WIDGET (gtk_label_new ("A")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_A); + GtkWidget *menu_item_B = GTK_WIDGET (gtk_label_new ("B")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_B); + GtkWidget *menu_item_C = GTK_WIDGET (gtk_label_new ("C")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_C); GtkWidget *pop = gtk_popover_new (); gtk_popover_set_child (GTK_POPOVER (pop), list_box); - if (0) gtk_popover_popup (GTK_POPOVER (pop)); - GtkButton *open_menu = GTK_BUTTON (gtk_button_new ()); // gtk_button_new or gtk_menu_button_new ? - gtk_button_set_icon_name (GTK_BUTTON (open_menu), "open-menu-symbolic"); -// g_signal_connect (open_menu, "clicked", G_CALLBACK (on_clicked_MENU_list_box), list_box); - g_signal_connect (open_menu, "clicked", G_CALLBACK (on_clicked_MENU_pop), pop); + gtk_popover_present (GTK_POPOVER (pop)); + + GtkMenuButton *open_menu = GTK_MENU_BUTTON (gtk_menu_button_new ()); // gtk_button_new or gtk_menu_button_new ? + gtk_menu_button_set_icon_name (open_menu, "open-menu-symbolic"); + gtk_menu_button_set_popover (open_menu, GTK_WIDGET (pop)); gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (open_menu)); -/* - gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (get_menu_anchor())); +// g_signal_connect (open_menu, "clicked", G_CALLBACK (on_clicked_MENU_pop), pop); - GtkWidget *menu_btt = gtk_menu_button_new (); - gtk_menu_button_set_child (GTK_MENU_BUTTON (menu_btt), NULL); - gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (menu_btt), NULL); // GMenuModel* menu_model - gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (menu_btt)); -*/ +// https://discourse.gnome.org/t/when-do-we-really-have-to-use-gtk-popover-present-to-show-a-popover-at-a-given-widget/17566/5 } void widget_head_MAIN_WINDOW_design (GtkWindow *main_window){ diff --git a/src/widget.c/menu.c b/src/widget.c/menu.c index a8bdfa9..9a7f2ed 100644 --- a/src/widget.c/menu.c +++ b/src/widget.c/menu.c @@ -83,6 +83,7 @@ GtkWidget *get_menu_anchor() { // https://docs.gtk.org/gio/class.MenuModel.html // https://www.geany.org/manual/gtk/gobject/index.html + // https://developer.gnome.org/hig/patterns/controls/menus.html if (0) labo_create_a_simple_gtk_string_list (); struct MenuNode_t *menu_root = create_user_menu_node("menu"); @@ -128,3 +129,4 @@ GtkWidget *get_menu_anchor() } */ +