WIP: Popover MENU <> A robust starting point.

This commit is contained in:
Jean Sirmai 2024-07-14 08:12:44 +02:00
parent 34f295d8cc
commit 3d42cd041a
Signed by: jean
GPG Key ID: FB3115C340E057E3
4 changed files with 15 additions and 18 deletions

View File

@ -1,4 +1,4 @@
https://developer.gnome.org/hig/principles.html
================================================================================ ================================================================================

View File

@ -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, 1)))),
gtk_button_get_label (GTK_BUTTON (gtk_list_box_row_get_child (gtk_list_box_get_row_at_index (list_box, 2))))); 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); // learning_how_to_create_a_menu (menu_button);
// https://docs.gtk.org/gtk4/class.ListBox.html // https://docs.gtk.org/gtk4/class.ListBox.html

View File

@ -172,29 +172,22 @@ static void window_header_bar (GtkWindow *window, char *title)
GtkWidget* list_box = gtk_list_box_new(); 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_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_button_new_with_label ("button_B")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_B); 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_button_new_with_label ("button_C")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_C); GtkWidget *menu_item_C = GTK_WIDGET (gtk_label_new ("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 *pop = gtk_popover_new (); GtkWidget *pop = gtk_popover_new ();
gtk_popover_set_child (GTK_POPOVER (pop), list_box); gtk_popover_set_child (GTK_POPOVER (pop), list_box);
if (0) gtk_popover_popup (GTK_POPOVER (pop)); gtk_popover_present (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"); GtkMenuButton *open_menu = GTK_MENU_BUTTON (gtk_menu_button_new ()); // gtk_button_new or gtk_menu_button_new ?
// g_signal_connect (open_menu, "clicked", G_CALLBACK (on_clicked_MENU_list_box), list_box); gtk_menu_button_set_icon_name (open_menu, "open-menu-symbolic");
g_signal_connect (open_menu, "clicked", G_CALLBACK (on_clicked_MENU_pop), pop); 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 (open_menu));
/* // g_signal_connect (open_menu, "clicked", G_CALLBACK (on_clicked_MENU_pop), pop);
gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (get_menu_anchor()));
GtkWidget *menu_btt = gtk_menu_button_new (); // 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
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));
*/
} }
void widget_head_MAIN_WINDOW_design (GtkWindow *main_window){ void widget_head_MAIN_WINDOW_design (GtkWindow *main_window){

View File

@ -83,6 +83,7 @@ GtkWidget *get_menu_anchor()
{ {
// https://docs.gtk.org/gio/class.MenuModel.html // https://docs.gtk.org/gio/class.MenuModel.html
// https://www.geany.org/manual/gtk/gobject/index.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 (); if (0) labo_create_a_simple_gtk_string_list ();
struct MenuNode_t *menu_root = create_user_menu_node("menu"); struct MenuNode_t *menu_root = create_user_menu_node("menu");
@ -128,3 +129,4 @@ GtkWidget *get_menu_anchor()
} }
*/ */