WIP: trying again to built a model of a tree...

This commit is contained in:
Jean Sirmai 2024-01-18 19:11:22 +01:00
parent e47bd2b0dc
commit e991c80998
Signed by: jean
GPG Key ID: FB3115C340E057E3
1 changed files with 43 additions and 3 deletions

View File

@ -29,10 +29,22 @@
#include "../../include/base.h" #include "../../include/base.h"
#include "../../include/ui.h" #include "../../include/ui.h"
static void on_button_action (GtkWidget *widget, gpointer data) { g_print ("Hello, it's me ! (again)\n");} static void on_button_action (GtkWidget *widget, gpointer data) { g_print ("Hello, it's me ! (again)\n");}
static void on_destroy (GtkWidget *widget, gpointer data) { exit(0);} static void on_destroy (GtkWidget *widget, gpointer data) { exit(0);}
enum { NAME_COLUMN };
/* custom function to fill the model with data */
static void populate_tree_model (my_store){
GtkTreeIter my_iter_1, my_iter_2;
gtk_tree_store_append (my_store, &my_iter_1, NULL); /* Acquire an iterator */
gtk_tree_store_set (my_store, &my_iter_1, NAME_COLUMN, "value A", -1);
gtk_tree_store_append (my_store, &my_iter_2, &my_iter_1); /* Acquire a child iterator */
// gtk_tree_store_set (my_store, &my_iter_2, NAME_COLUMN, "value B", -1);
// my_column = gtk_tree_view_column_new_with_attributes ("names", my_renderer, "text", NAME_COLUMN, NULL);
// gtk_tree_view_append_column (GTK_TREE_VIEW (my_tree), my_column);
};
void hello_it_s_me() void hello_it_s_me()
{ {
GtkWidget *my_window; GtkWidget *my_window;
@ -40,6 +52,14 @@ void hello_it_s_me()
GtkWidget *my_button; GtkWidget *my_button;
char *my_window_title = "Hello, it's me !"; char *my_window_title = "Hello, it's me !";
char *my_button_title = "And I'm the button."; char *my_button_title = "And I'm the button.";
GtkListStore *my_store;
GtkTreeIter my_iter_1, my_iter_2;
GtkWidget *my_tree;
GtkCellRenderer *my_renderer;
GtkTreeViewColumn *my_column;
GHashTable *my_hash_table;
guint my_hash_table_size;
gtk_init(); // < nécessaire ici car, pour ne pas désorganiser l'écriture de main(), gtk_init(); // < nécessaire ici car, pour ne pas désorganiser l'écriture de main(),
// hello_it_s_me() est appelé avant l'initialisation de l'application // hello_it_s_me() est appelé avant l'initialisation de l'application
@ -60,18 +80,28 @@ void hello_it_s_me()
// gtk_widget_show (my_button); < inutile (appels récursifs) // gtk_widget_show (my_button); < inutile (appels récursifs)
gtk_window_set_child(GTK_WINDOW(my_window), GTK_WIDGET(my_box)); gtk_window_set_child(GTK_WINDOW(my_window), GTK_WIDGET(my_box));
my_store = gtk_list_store_new (1, G_TYPE_STRING); // G_TYPE_CHAR);
populate_tree_model (my_store);
my_tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (my_store));
my_renderer = gtk_cell_renderer_text_new ();
g_object_unref (G_OBJECT (my_store));
gtk_widget_show (my_window); gtk_widget_show (my_window);
printf("A little window is created in bac-a-sable with title : %s\n", my_window_title); printf("Window ('%s') with button ('%s') -[see the sand box]-\nhash_table_size = %d\n",
my_window_title, my_button_title, my_hash_table_size);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// guix shell -m manifest.scm make clean && clear && time make run // guix shell -m manifest.scm make clean && clear && time make run
// GOBJECT_DEBUG=instance_count Gio Gnome input output // GOBJECT_DEBUG=instance_count GIO Gnome Input Output
// https://docs.gtk.org/ // https://docs.gtk.org/
// https://docs.gtk.org/gtk4/ // https://docs.gtk.org/gtk4/
// https://docs.gtk.org/gobject/
// https://docs.gtk.org/glib/ // https://docs.gtk.org/glib/
// https://docs.gtk.org/gio/ // https://docs.gtk.org/gio/
// //
@ -84,4 +114,14 @@ void hello_it_s_me()
// https://developer-old.gnome.org/gtk4/stable/GtkListView.html <<< copy that ! // https://developer-old.gnome.org/gtk4/stable/GtkListView.html <<< copy that !
// https://docs.gtk.org/gtk4/ctor.TreeListModel.new.html *** // https://docs.gtk.org/gtk4/ctor.TreeListModel.new.html ***
// https://blog.gtk.org/2020/06/08/more-on-lists-in-gtk-4/ *** // https://blog.gtk.org/2020/06/08/more-on-lists-in-gtk-4/ ***
//
//
//
/* Ce qui suit est compilé 2024-01-18 */
/* my_hash_table = g_hash_table_new(NULL, NULL); */
/* my_hash_table = g_hash_table_ref (my_hash_table); */
/* // gpointer my_key = ; gboolean my_bool = g_hash_table_add (my_hash_table, mykey); */
/* my_hash_table_size = g_hash_table_size(my_hash_table); */