Merci Adrien pour l'explication des pointeurs sur fonctions. Ça marche

This commit is contained in:
Jean Sirmai 2024-05-22 07:44:50 +02:00
parent 7d1bc83d56
commit 62008e0248
Signed by: jean
GPG Key ID: FB3115C340E057E3
6 changed files with 71 additions and 9 deletions

39
hot.c
View File

@ -35,6 +35,14 @@ static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child)
} else parent->child = child; } else parent->child = child;
} }
void on_experimental_tree_expander_toggled(GtkExpander *expander, gpointer user_data)
{
// This is a conceptual callback for when an expander is toggled
GtkTreeListRow *row = GTK_TREE_LIST_ROW(user_data);
gboolean is_expanded = gtk_tree_list_row_get_expanded(row);
gtk_tree_list_row_set_expanded(row, !is_expanded);
}
static void on_experimental_tree_bind_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data){ static void on_experimental_tree_bind_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data){
GtkListItem *list_item = GTK_LIST_ITEM (object); GtkListItem *list_item = GTK_LIST_ITEM (object);
GtkTreeListRow *row = gtk_list_item_get_item (list_item); GtkTreeListRow *row = gtk_list_item_get_item (list_item);
@ -42,8 +50,8 @@ static void on_experimental_tree_bind_factory (GtkSignalListItemFactory *factory
const gchar *text = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_tree_list_row_get_item (row))); const gchar *text = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_tree_list_row_get_item (row)));
GtkWidget *expander = gtk_list_item_get_child (list_item); GtkWidget *expander = gtk_list_item_get_child (list_item);
gtk_expander_set_label (GTK_EXPANDER (expander), text); gtk_expander_set_label (GTK_EXPANDER (expander), text);
// g_signal_handlers_disconnect_by_func(expander, G_CALLBACK(on_tree_expander_toggled), row); g_signal_handlers_disconnect_by_func(expander, G_CALLBACK(on_experimental_tree_expander_toggled), row);
// g_signal_connect(expander, "activate", G_CALLBACK(on_tree_expander_toggled), row); g_signal_connect(expander, "activate", G_CALLBACK(on_experimental_tree_expander_toggled), row);
gtk_widget_set_margin_start(expander, gtk_tree_list_row_get_depth(row)*20); gtk_widget_set_margin_start(expander, gtk_tree_list_row_get_depth(row)*20);
gboolean is_expanded = gtk_tree_list_row_get_expanded(row); gboolean is_expanded = gtk_tree_list_row_get_expanded(row);
printf("[on_experimental_tree_bind_factory] row content is [%s] and expander is [%d]\n", text, is_expanded); printf("[on_experimental_tree_bind_factory] row content is [%s] and expander is [%d]\n", text, is_expanded);
@ -57,10 +65,10 @@ void on_experimental_tree_setup_factory (GtkSignalListItemFactory *factory,
printf("[on_experimental_tree_setup_factory] here is an expander\n"); printf("[on_experimental_tree_setup_factory] here is an expander\n");
} }
static GListModel* get_experimental_tree_children_model (struct TreeNode_t *parent){ static GListModel* get_experimental_tree_model_child (struct TreeNode_t *parent){
GtkStringList *list = NULL; GtkStringList *list = NULL;
if (parent) { if (parent) {
printf("[get_experimental_tree_children_model] here is %s content : ", parent->text); printf("[get_experimental_tree_model_child] here is %s content : ", parent->text);
struct TreeNode_t *child = parent->child; struct TreeNode_t *child = parent->child;
if (child) {list = gtk_string_list_new(NULL);} if (child) {list = gtk_string_list_new(NULL);}
while(child) { while(child) {
@ -73,7 +81,7 @@ static GListModel* get_experimental_tree_children_model (struct TreeNode_t *pare
return G_LIST_MODEL(list); return G_LIST_MODEL(list);
} }
static GListModel* experimental_tree_create_model (GObject *item, gpointer root){ GListModel* create_experimental_tree_model (GObject *item, gpointer root){
struct TreeNode_t *cur = (struct TreeNode_t *)root; struct TreeNode_t *cur = (struct TreeNode_t *)root;
struct TreeNode_t *parent = root; struct TreeNode_t *parent = root;
const gchar *string = gtk_string_object_get_string (GTK_STRING_OBJECT(item)); const gchar *string = gtk_string_object_get_string (GTK_STRING_OBJECT(item));
@ -83,11 +91,12 @@ static GListModel* experimental_tree_create_model (GObject *item, gpointer root)
cur = cur->next; cur = cur->next;
if (cur == NULL) {cur = parent->child; parent = cur;} if (cur == NULL) {cur = parent->child; parent = cur;}
} }
printf("[experimental_tree_create_model] looked for %s in %s item\n", cur->text, string); printf("[create_experimental_tree_model] looked for %s in %s item\n", cur->text, string);
return get_experimental_tree_children_model (cur); return get_experimental_tree_model_child (cur);
} }
void create_experimental_tree (GtkBox *experimental_box){ void create_experimental_tree (GtkBox *experimental_box){
GtkScrolledWindow *scrolled_window;
struct TreeNode_t *tree_root = create_tree_node("hello"); struct TreeNode_t *tree_root = create_tree_node("hello");
struct TreeNode_t *it_s_me = create_tree_node("it's me"); add_child_node(tree_root, it_s_me); struct TreeNode_t *it_s_me = create_tree_node("it's me"); add_child_node(tree_root, it_s_me);
struct TreeNode_t *remember = create_tree_node("remember"); add_child_node(it_s_me, remember); struct TreeNode_t *remember = create_tree_node("remember"); add_child_node(it_s_me, remember);
@ -97,13 +106,15 @@ void create_experimental_tree (GtkBox *experimental_box){
GtkSignalListItemFactory *factory = GTK_SIGNAL_LIST_ITEM_FACTORY (gtk_signal_list_item_factory_new()); GtkSignalListItemFactory *factory = GTK_SIGNAL_LIST_ITEM_FACTORY (gtk_signal_list_item_factory_new());
g_signal_connect (factory, "setup", G_CALLBACK(on_experimental_tree_setup_factory), NULL); g_signal_connect (factory, "setup", G_CALLBACK(on_experimental_tree_setup_factory), NULL);
g_signal_connect (factory, "bind", G_CALLBACK(on_experimental_tree_bind_factory), NULL); g_signal_connect (factory, "bind", G_CALLBACK(on_experimental_tree_bind_factory), NULL);
// GListModel *a_test = create_experimental_tree_model(G_OBJECT (model), tree_root);
printf("> %s > %s > %s\n", tree_root->text, it_s_me->text, remember->text); printf("> %s > %s > %s\n", tree_root->text, it_s_me->text, remember->text);
GtkTreeListModel *tree_model = gtk_tree_list_model_new( GtkTreeListModel *tree_model = gtk_tree_list_model_new(
G_LIST_MODEL (model), G_LIST_MODEL (model),
FALSE, // Passthrough - False in actual usage with dynamic children retrieval FALSE, // Passthrough - False in actual usage with dynamic children retrieval
FALSE, // autoexpand FALSE, // autoexpand
(GtkTreeListModelCreateModelFunc) experimental_tree_create_model, (GtkTreeListModelCreateModelFunc) &create_experimental_tree_model,
tree_root, tree_root,
NULL // (GDestroyNotify) free_tree_node NULL // (GDestroyNotify) free_tree_node
); );
@ -115,7 +126,17 @@ void create_experimental_tree (GtkBox *experimental_box){
GtkWidget *list_view = gtk_list_view_new (GTK_SELECTION_MODEL (selection_model), GtkWidget *list_view = gtk_list_view_new (GTK_SELECTION_MODEL (selection_model),
GTK_LIST_ITEM_FACTORY (factory)); GTK_LIST_ITEM_FACTORY (factory));
gtk_box_append(experimental_box, list_view); scrolled_window = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new());
gtk_scrolled_window_set_child(scrolled_window, list_view);
gtk_scrolled_window_set_policy (scrolled_window,
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_widget_set_vexpand(GTK_WIDGET(scrolled_window), TRUE);
gtk_box_append(GTK_BOX(experimental_box), GTK_WIDGET(scrolled_window));
gtk_widget_set_visible(GTK_WIDGET(scrolled_window), TRUE);
gtk_widget_set_visible(GTK_WIDGET(list_view), TRUE);
// gtk_widget_set_visible(GTK_WIDGET(experimental_box), TRUE); // gtk_widget_set_visible(GTK_WIDGET(experimental_box), TRUE);
// gtk_widget_set_visible(GTK_WIDGET(list_view), TRUE); // gtk_widget_set_visible(GTK_WIDGET(list_view), TRUE);

BIN
hot.o

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 405 KiB

BIN
myprogram

Binary file not shown.

41
warm.c
View File

@ -7,6 +7,47 @@
#include "texts.h" #include "texts.h"
// https://docs.gtk.org/gtk4/visual_index.html < widgets gallery // https://docs.gtk.org/gtk4/visual_index.html < widgets gallery
//typedef anytype = {(int)(*fnct) {printf("typedef {(int)(*fnct) {printf("");}");} GtkModelFnct;
GtkFrame *get_frame_with_label(){ // EN ATTENDANT DE SAVOIR UTILISER : GtkTextTagTable et GtkTextBuffer GtkFrame *get_frame_with_label(){ // EN ATTENDANT DE SAVOIR UTILISER : GtkTextTagTable et GtkTextBuffer
GtkFrame *space_specif = GTK_FRAME(gtk_frame_new ("Space (run / edit) specifications")); GtkFrame *space_specif = GTK_FRAME(gtk_frame_new ("Space (run / edit) specifications"));

BIN
warm.o

Binary file not shown.