Compare commits

...

2 Commits

3 changed files with 82 additions and 93 deletions

View File

@ -42,7 +42,7 @@
/* */ /* */
/* https://docs.gtk.org/gtk4/class.TreeListModel.html (easy to find) */ /* https://docs.gtk.org/gtk4/class.TreeListModel.html (easy to find) */
/* https://developer-old.gnome.org/gtk4/stable/GtkTreeView.html (vieux...) */ /* 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/ */ /* https://blog.gtk.org/2020/09/08/on-list-models/ */
/* */ /* */
/******************************************************************************/ /******************************************************************************/

View File

@ -21,85 +21,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/**************** 2024-01-06 À la chasse aux widgets ! ****************/
/* in > 01/GTK4/tree (learning)/The_Gnome_way/demos/gtk-demo */
/* */
/* tree_store() listview_words() editable_cells() search_entry2() */
/* dnd()(= drag and drop) entry_undo() expander() textundo() */
/* scale() (= scale entries from bars) font_features() hypertext() */
/* iconview_edit() (= drag and drop icons) image_scaling() infobar() */
/* links() listbox_controls() list_store() listview_colors() */
/* listview_selections() mask(NULL) and more... */
/* */
/******************************************************************************/
/*************** The basic ideas behind list views: *******************/
/* */
/* The data for items is provided in the form of a model containing objects */
/* Widgets are created just for the viewable range of items */
/* Widgets can be recycled by binding them to different items */
/* Avoid iterating over all items in the model as much as possible, and */
/* just deal with the items in the visible range which are bound to widgets */
/* from https://blog.gtk.org/2020/06/07/scalable-lists-in-gtk-4/ */
/* */
/******************************************************************************/
// GtkListItemFactory is the object that is tasked with creating widgets
// for the items in the model.
// One implementations of this factory, GtkBuilderListItemFactory,
// is using ui files as templates for the list item widgets.
/*************** A B O U T T R E E S **************************/
/* */
/* https://docs.gtk.org/gtk4/ */
/* https://docs.gtk.org/gtk4/getting_started.html */
/* https://toshiocp.github.io/Gtk4-tutorial/sec29.html <<< TODO (tuto) */
/* Keep the "comparison chart of equivalent functionalities" (link below) */
/* https://docs.gtk.org/gtk4/section-list-widget.html */
/* https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View */
/* https://gnome.pages.gitlab.gnome.org/libsoup/gio/GListModel.html */
/* https://docs.gtk.org/gio/iface.ListModel.html < +++ */
/* */
/* 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. */
/* https://blog.gtk.org/2020/09/08/on-list-models/ */
/* */
/******************************************************************************/
/*..............................................................................
*
* >>> GtkStringList <<<
*
* GtkStringList is a list model that wraps an array of strings.
* The objects in the model are of type GtkStringObject
* and have a string property that can be used inside expressions.
* Use it where/when you would typically use a char*[], but need a list model.
*
* Every item in a model has a position (= unsigned integer)
* "factories" takes care of mapping the items of the model
* to widgets that can be shown in the view
* by creating a listitem for each item that is currently in use.
* List items are always GtkListItem instances. Widgets can be recycled.
*
* GtkStringList can only handle strings.
* It is backed by a dynamically allocated array.
* GListStore is backed by a balanced tree.
*
* GTK provides functionality to make lists look and behave like trees
* by using the GtkTreeListModel and the GtkTreeExpander widget.
*
* Widgets are styleable using GTK CSS. Use the .rich-list style class.
*
* GListModel is an interface that represents a mutable list of GObjects.
*
*............................................................................*/
#include <unistd.h> #include <unistd.h>
#include <gtk-4.0/gtk/gtk.h> #include <gtk-4.0/gtk/gtk.h>
#include <glib-2.0/glib.h> #include <glib-2.0/glib.h>
@ -107,12 +28,6 @@
#include "../../include/base.h" #include "../../include/base.h"
#include "../../include/ui.h" #include "../../include/ui.h"
#include <gtk/gtk.h>
#include <stdio.h>
#include <gio/gio.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
enum enum
{ {
STRING_COLUMN, STRING_COLUMN,
@ -170,11 +85,11 @@ static GListStore *create_node_recursive (GListStore *model,
GtkWidget *create_my_list_model(GtkBox *runlib_objects) GtkWidget *create_my_list_model(GtkBox *runlib_objects)
{ {
GListStore *my_list_model = NULL;
GtkWidget *my_tree_box = NULL; GtkWidget *my_tree_box = NULL;
GtkWidget *my_scrolled_window = NULL; GtkWidget *my_scrolled_window = NULL;
GListStore *my_list_model = NULL;
GtkWidget *my_tree_view = 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_list_model = create_node_recursive (my_list_model, O, NULL, 0);
my_tree_view = gtk_tree_view_new_with_model (my_list_model); my_tree_view = gtk_tree_view_new_with_model (my_list_model);
@ -186,9 +101,9 @@ GtkWidget *create_my_list_model(GtkBox *runlib_objects)
gtk_tree_view_set_reorderable (GTK_TREE_VIEW (my_tree_view), TRUE); gtk_tree_view_set_reorderable (GTK_TREE_VIEW (my_tree_view), TRUE);
g_object_unref (my_list_model); 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, 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 (); my_scrolled_window = gtk_scrolled_window_new ();
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (my_scrolled_window), TRUE); gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (my_scrolled_window), TRUE);
@ -208,6 +123,7 @@ GtkWidget *create_my_list_model(GtkBox *runlib_objects)
} }
static gint xxx(GtkBox *runlib_objects);
static void static void
print_hello (GtkWidget *widget, print_hello (GtkWidget *widget,
@ -229,9 +145,76 @@ GtkWidget *create_a_button(GtkBox *runlib_objects)
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL); g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
printf("--------------------------------------------- tree.c line 232\n\ xxx(runlib_objects);
my widgets' tank : 01/GTK4/tree (learning)/The_Gnome_way/demos/gtk-demo\n");
return button; 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 // Setup GLArea
//XXX TEMP ui_setup_glarea(window->run_glarea, window->run_controls); //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)) */ /* if (!gtk_widget_get_visible (my_window)) */
/* gtk_widget_set_visible (my_window, TRUE); */ /* gtk_widget_set_visible (my_window, TRUE); */