From 76857c033e960f9f8a1fc256dbd394a74a3c887b Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Fri, 5 Jul 2024 11:59:18 +0200 Subject: [PATCH] WIP: menu <> model & list missing (see labo.learning...()) --- data/text/about_commands.txt | 2 +- include/callbacks.h | 2 +- include/widgets.h | 1 + src/callbacks.c | 5 ++- src/widget.c/heads.c | 2 +- src/widget.c/labo.c | 74 +++++++++++++++++++++++++++++++++++- 6 files changed, 80 insertions(+), 6 deletions(-) diff --git a/data/text/about_commands.txt b/data/text/about_commands.txt index 34a50c2..02c52e1 100644 --- a/data/text/about_commands.txt +++ b/data/text/about_commands.txt @@ -1,5 +1,5 @@ - Dans : [space_page - mode RUN] doivent ĂȘtre : ------------------------------------------------------ + Dans : [space_page - mode RUN] doivent ĂȘtre : ------------------------------------------------------------- (1) les commandes de mouvement: - run/stop, slow down/speed up, step by step, do/undo/redo diff --git a/include/callbacks.h b/include/callbacks.h index 0b933ce..e5c2c1f 100644 --- a/include/callbacks.h +++ b/include/callbacks.h @@ -63,7 +63,7 @@ void on_axis_value_change (GtkAdjustment *adjustment, gpointer data); void on_reset_image (GtkWidget *btt_reset, gpointer data); void on_clicked_HOME (GtkWidget *btt_reset, gpointer data); -void on_clicked_X (GtkWidget *btt_reset, gpointer data); +void on_clicked_MENU (GtkWidget *btt_reset, gpointer data); diff --git a/include/widgets.h b/include/widgets.h index 4933386..117fcea 100644 --- a/include/widgets.h +++ b/include/widgets.h @@ -61,6 +61,7 @@ GtkScrolledWindow *get_user_rules_tree (); void icons_for_fun (GtkHeaderBar *header_bar); GtkWidget *get_window_child_DATA_lab(); +void learning_menus_and_all_that_stuff(GtkMenuButton* menu_button); /******************************************************************************/ /* I M A G E S */ diff --git a/src/callbacks.c b/src/callbacks.c index 52f1c10..3fdb50f 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -320,8 +320,9 @@ void on_clicked_HOME (GtkWidget *btt_reset, gpointer data) { gtk_window_present (GTK_WINDOW (get_dialog_window())); // works once only ! } -void on_clicked_X (GtkWidget *btt_reset, gpointer data) { - printf ("callback.n_clicked_X button() presents the text_window ( :- ) but... it works only once.\n"); +void on_clicked_MENU (GtkWidget *btt_reset, gpointer menu_button) { + printf ("callback.on_clicked_MENU button() presents the text_window ( :- ) but... it works only once.\n"); + learning_menus_and_all_that_stuff (menu_button); gtk_window_present (GTK_WINDOW (get_text_window())); // works once only ! } diff --git a/src/widget.c/heads.c b/src/widget.c/heads.c index bf3749a..d85db2a 100644 --- a/src/widget.c/heads.c +++ b/src/widget.c/heads.c @@ -165,7 +165,7 @@ static void window_header_bar (GtkWindow *window, char *title){ GtkButton *open_menu = GTK_BUTTON (gtk_button_new ()); gtk_button_set_icon_name (open_menu, "open-menu-symbolic"); - g_signal_connect (open_menu, "clicked", G_CALLBACK (on_clicked_X), no_local_data); + g_signal_connect (open_menu, "clicked", G_CALLBACK (on_clicked_MENU), open_menu); gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (open_menu)); } diff --git a/src/widget.c/labo.c b/src/widget.c/labo.c index dd80258..cd183ba 100644 --- a/src/widget.c/labo.c +++ b/src/widget.c/labo.c @@ -47,10 +47,81 @@ +/******************************************************************************/ +/* E X P E R I M E N T A L A R E A */ +/******************************************************************************/ + + + +static void +setup_listitem_cb (GtkListItemFactory *factory, + GtkListItem *list_item) +{ + GtkWidget *image; + + image = gtk_image_new (); + gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE); + gtk_list_item_set_child (list_item, image); +} + +static void +bind_listitem_cb (GtkListItemFactory *factory, + GtkListItem *list_item) +{ + GtkWidget *image; + GAppInfo *app_info; + + image = gtk_list_item_get_child (list_item); + app_info = gtk_list_item_get_item (list_item); + gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (app_info)); +} + +static void +activate_cb (GtkListView *list, + guint position, + gpointer unused) +{ + GAppInfo *app_info; + + app_info = g_list_model_get_item (G_LIST_MODEL (gtk_list_view_get_model (list)), position); + g_app_info_launch (app_info, NULL, NULL, NULL); + g_object_unref (app_info); +} + +void learning_menus_and_all_that_stuff (GtkMenuButton* menu_button) { + printf ("labo.learning_menus_and_all_that_stuff...()\ + > presents the text_window ( ;- ))\n \ + which, at the present time,... works only once ( :- ((\n"); + + gtk_window_present (GTK_WINDOW (get_text_window())); + + + GtkListItemFactory *factory = gtk_signal_list_item_factory_new (); + g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL); + g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL); + + // model = + GSList *list = NULL; + // list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory); + g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL); // + gtk_menu_button_set_child (GTK_MENU_BUTTON (menu_button), NULL); // << list (a GtkWidget) + +// https://docs.gtk.org/gtk4/class.ListView.html +} + + + + + + +/******************************************************************************/ +/* C O N T A I N E R S */ +/******************************************************************************/ // https://blog.gtk.org/2020/09/08/on-list-models/ < TODO // https://docs.gtk.org/gtk4/visual_index.html < widgets gallery -// https://iconduck.com/sets/adwaita-icon-theme https://iconduck.com/sets/carbon-icons +// https://iconduck.com/sets/adwaita-icon-theme +// https://iconduck.com/sets/carbon-icons // https://docs.gtk.org/gtk4/section-text-widget.html // https://docs.gtk.org/gtk4/class.Widget.html#height-for-width-geometry-management // https://docs.gtk.org/gtk4/class.TextView.html @@ -59,6 +130,7 @@ // GTK_ORIENTATION_VERTICAL GTK_ORIENTATION_HORIZONTAL + void let_us_create_a_complex_useless_and_expensive_tree (struct TreeNode_t *tree_root) { struct TreeNode_t *a = create_user_tree_node("We, the people");add_child_node(tree_root, a); struct TreeNode_t *b = create_user_tree_node("in Order to"); add_child_node(tree_root, b);