WIP: Test gtk_box_append (copier/coller) un exemple de liste simple

This commit is contained in:
Jean Sirmai 2024-01-10 08:59:36 +01:00
parent 74cbded108
commit 8aad4e1d54
Signed by: jean
GPG Key ID: FB3115C340E057E3
3 changed files with 82 additions and 8 deletions

View File

@ -42,7 +42,7 @@
/* */
/* https://docs.gtk.org/gtk4/class.TreeListModel.html (easy to find) */
/* https://developer-old.gnome.org/gtk4/stable/GtkTreeView.html (vieux...) */
/* get-path-at-pos(x,y) finds the path at these window coordinates. */
/* get-path-at-pos(x,y) <> finds the path at these window coordinates. */
/* https://blog.gtk.org/2020/09/08/on-list-models/ */
/* */
/******************************************************************************/

View File

@ -85,11 +85,11 @@ static GListStore *create_node_recursive (GListStore *model,
GtkWidget *create_my_list_model(GtkBox *runlib_objects)
{
GListStore *my_list_model = NULL;
GtkWidget *my_tree_box = NULL;
GtkWidget *my_scrolled_window = NULL;
GListStore *my_list_model = NULL;
GtkWidget *my_tree_view = NULL;
GtkCellRenderer *renderer = NULL;
GtkCellRenderer *my_renderer = NULL;
my_list_model = create_node_recursive (my_list_model, O, NULL, 0);
my_tree_view = gtk_tree_view_new_with_model (my_list_model);
@ -101,9 +101,9 @@ GtkWidget *create_my_list_model(GtkBox *runlib_objects)
gtk_tree_view_set_reorderable (GTK_TREE_VIEW (my_tree_view), TRUE);
g_object_unref (my_list_model);
renderer = gtk_cell_renderer_text_new (); g_object_set (renderer, "xalign", 0.0, NULL);
my_renderer = gtk_cell_renderer_text_new (); g_object_set (my_renderer, "xalign", 0.0, NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (my_tree_view), -1,
"Col 0", renderer, "text", STRING_COLUMN, NULL);
"Col 0", my_renderer, "text", STRING_COLUMN, NULL);
my_scrolled_window = gtk_scrolled_window_new ();
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (my_scrolled_window), TRUE);
@ -123,6 +123,7 @@ GtkWidget *create_my_list_model(GtkBox *runlib_objects)
}
static gint xxx(GtkBox *runlib_objects);
static void
print_hello (GtkWidget *widget,
@ -144,9 +145,76 @@ GtkWidget *create_a_button(GtkBox *runlib_objects)
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
printf("--------------------------------------------- tree.c line 232\n\
my widgets' tank : 01/GTK4/tree (learning)/The_Gnome_way/demos/gtk-demo\n");
xxx(runlib_objects);
return button;
}
enum {
FILE_NAME,
FILE_OFFSET,
FILE_SIZE,
FILE_DESCRIPTION, /* Not used by the view, maybe used elsewhere */
COLOR, /* Just to show how the model can affect the view */
N_COLUMNS
};
static gint xxx(GtkBox *runlib_objects)
{
GtkListStore* model;
GtkWidget* view;
GtkTreeViewColumn* column;
GtkWidget* window;
/* MODEL */
model = gtk_list_store_new(N_COLUMNS,
G_TYPE_STRING, /* FILE_NAME */
G_TYPE_UINT, /* FILE_OFFSET */
G_TYPE_UINT, /* FILE_SIZE */
G_TYPE_STRING, /* FILE_DESCRIPTION */
G_TYPE_STRING /* COLOR */
);
gtk_list_store_insert_with_values(model, NULL, -1,
FILE_NAME, "test name",
FILE_OFFSET, 0,
FILE_SIZE, 10,
-1);
gtk_list_store_insert_with_values(model, NULL, -1,
FILE_NAME, "Dummy",
FILE_OFFSET, 123,
COLOR, "black",
-1);
gtk_list_store_insert_with_values(model, NULL, -1,
FILE_NAME, "another name",
COLOR, "blue",
-1);
/* VIEW */
view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
g_object_unref(model);
column = gtk_tree_view_column_new_with_attributes("Name",
gtk_cell_renderer_text_new(),
"text", FILE_NAME,
"background", COLOR,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
column = gtk_tree_view_column_new_with_attributes("Offset",
gtk_cell_renderer_spin_new(),
"text", FILE_OFFSET,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
column = gtk_tree_view_column_new_with_attributes("Size",
gtk_cell_renderer_text_new(),
"text", FILE_SIZE,
NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(view), column);
gtk_box_append(runlib_objects, view);
return 0;
}
// guix shell -m manifest.scm make clean && clear && time make run

View File

@ -119,9 +119,15 @@ static void gem_graph_client_window_init(GemGraphClientWindow *self)
// Setup GLArea
//XXX TEMP ui_setup_glarea(window->run_glarea, window->run_controls);
//
printf("--------------------------------------------------------------------------------------\n\
from : gem_graph_client_window_init(GemGraphClientWindow *self) in window.c (line 123)\n\
> widgets examples in user/jean/01/GTK4/tree (learning)/The_Gnome_way/demos/gtk-demo <\n\
--------------------------------------------------------------------------------------\n");
}
/* Is this used to 'FREE' something and must be preserved ? */
/* Is this used to 'FREE' something and must be retained ? */
/* */
/* if (!gtk_widget_get_visible (my_window)) */
/* gtk_widget_set_visible (my_window, TRUE); */