WIP: playing in the sand box

This commit is contained in:
Jean Sirmai 2024-01-17 18:14:53 +01:00
parent ca2a4e332d
commit fadd5f256f
Signed by: jean
GPG Key ID: FB3115C340E057E3
4 changed files with 54 additions and 75 deletions

View File

@ -128,3 +128,5 @@ GtkWidget *create_my_deprec_tree_model(GtkBox *runlib_objects);
GtkWidget *create_my_button_test(GtkBox *runlib_objects); GtkWidget *create_my_button_test(GtkBox *runlib_objects);
GtkWidget *create_my_list_view_test(GtkBox *runlib_objects); GtkWidget *create_my_list_view_test(GtkBox *runlib_objects);
GtkWidget *create_my_editable_cells (GtkBox *my_box); GtkWidget *create_my_editable_cells (GtkBox *my_box);
void hello_it_s_me();

View File

@ -58,6 +58,8 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
hello_it_s_me(); // in bac-à-sable
g_autoptr(GemGraphClientApplication) app = NULL; g_autoptr(GemGraphClientApplication) app = NULL;
int res; int res;
@ -67,3 +69,4 @@ int main(int argc, char **argv)
res = g_application_run(G_APPLICATION(app), argc, argv); res = g_application_run(G_APPLICATION(app), argc, argv);
return res; return res;
} }

View File

@ -28,71 +28,38 @@
#include "../../include/base.h" #include "../../include/base.h"
#include "../../include/ui.h" #include "../../include/ui.h"
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
};
GtkWidget *create_my_list_view_test(GtkBox *runlib_objects) 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);}
void hello_it_s_me()
{ {
GtkListStore* model; GtkWidget *my_window;
GtkWidget* view; GtkWidget *my_box;
GtkTreeViewColumn* column; GtkWidget *my_button;
GtkWidget* window; char *my_title = "Hello, it's me !";
char *my_button_title = "And I'm the button.";
/* MODEL */ gtk_init();
model = gtk_list_store_new(N_COLUMNS, my_window = gtk_window_new ();
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 */ g_signal_connect(G_OBJECT (my_window), "on_destroy::", G_CALLBACK(on_destroy), NULL);
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_window_set_title (GTK_WINDOW(my_window), my_title);
gtk_cell_renderer_text_new(), gtk_window_set_default_size (GTK_WINDOW(my_window), 200, 34);
"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", my_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
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", my_button = gtk_button_new_with_label (my_button_title);
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); g_signal_connect(G_OBJECT (my_button), "on_button_action::", G_CALLBACK(on_button_action), NULL);
gtk_box_append(GTK_BOX(my_box), GTK_WIDGET(my_button));
// gtk_widget_show (my_button);
return 0; gtk_window_set_child(GTK_WINDOW(my_window), GTK_WIDGET(my_box));
gtk_widget_show (my_window);
printf("A little window is created in bac-a-sable with title : %s\n", my_title);
} }

View File

@ -28,6 +28,9 @@
#include "../../include/base.h" #include "../../include/base.h"
#include "../../include/ui.h" #include "../../include/ui.h"
// TODO use GTK_DEBUG
GTK_DEBUG;
enum enum
{ {
STRING_COLUMN, STRING_COLUMN,
@ -42,13 +45,6 @@ struct _TreeItem
TreeItem *children; TreeItem *children;
}; };
void // https://docs.gtk.org/gtk4/method.StringList.take.html
gtk_string_list_take (
GtkStringList* self,
char* string
)
{}
// tree data // tree data
static TreeItem E[] = {NULL}, F[] = {NULL}, G[] = {NULL}, H[] = {NULL}; static TreeItem E[] = {NULL}, F[] = {NULL}, G[] = {NULL}, H[] = {NULL};
static TreeItem I[] = {NULL}, K[] = {NULL}, N[] = {NULL}, M[] = {NULL}; static TreeItem I[] = {NULL}, K[] = {NULL}, N[] = {NULL}, M[] = {NULL};
@ -59,10 +55,10 @@ static TreeItem A[] = {{"D", D}, {NULL}}, B[] = {{"E", E}, {NULL}};
static TreeItem R[] = {{"A", A}, {"B", B}, {"C", C}, {NULL}}; static TreeItem R[] = {{"A", A}, {"B", B}, {"C", C}, {NULL}};
static TreeItem O[] = {{"ROOT", R}, {NULL}}; // Artefact added for symmetry static TreeItem O[] = {{"ROOT", R}, {NULL}}; // Artefact added for symmetry
void gtk_string_list_take (GtkStringList* self, char* string){}
static void static void bind_listitem_cb_complex (GtkListItemFactory *factory,
bind_listitem_cb_complex (GtkListItemFactory *factory, GtkListItem *list_item)
GtkListItem *list_item)
{ {
GtkWidget *label; GtkWidget *label;
TreeItem *obj; TreeItem *obj;
@ -76,9 +72,8 @@ bind_listitem_cb_complex (GtkListItemFactory *factory,
static GtkWidget *my_tree_view; static GtkWidget *my_tree_view;
static GListModel *my_Glist_model = NULL; static GListModel *my_Glist_model = NULL;
// erreur: un élément de l'initialisation n'est pas une constante // erreur: un élément de l'initialisation n'est pas une constante
//model = create_application_list (); // model = create_application_list (); g_list_model_get_item_type()
typedef struct _GtkListView GtkListView; typedef struct _GtkListView GtkListView;
@ -114,10 +109,10 @@ static void setup_listitem_cb (GtkListItemFactory *my_factory,
GtkLabel *my_label, GtkLabel *my_label,
GtkImage *my_image) GtkImage *my_image)
{ {
//GtkWidget *my_label = gtk_label_new (""); // If not provided : GtkWidget *my_label = gtk_label_new ("");
gtk_list_item_set_child (my_list_item, my_label); gtk_list_item_set_child (my_list_item, my_label);
//GtkWidget *my_image = gtk_image_new (); // If not provided : GtkWidget *my_image = gtk_image_new ();
gtk_image_set_icon_size (GTK_IMAGE (my_image), GTK_ICON_SIZE_LARGE); gtk_image_set_icon_size (GTK_IMAGE (my_image), GTK_ICON_SIZE_LARGE);
gtk_list_item_set_child (my_list_item, my_image); gtk_list_item_set_child (my_list_item, my_image);
} }
@ -144,13 +139,15 @@ static void activate_cb (GtkListView *list,
} }
// Parameters : self : the GtkSignalListItemFactory, // Parameters : self : the GtkSignalListItemFactory,
// listitem : the GtkListItem to bind, // listitem : the GtkListItem to bind,
// user_data : the user data set when the signal handler was connected. // user_data : the user data set when the signal handler was connected.
// Flags: Run First // Flags: Run First
static void any_user_function (GtkSignalListItemFactory *self, GtkListItem *listitem, gpointer user_data) {} static void any_user_function (GtkSignalListItemFactory *self, GtkListItem *listitem, gpointer user_data) {
// my_factory = gtk_signal_list_item_factory_new ();
g_signal_connect (my_factory, "setup", setup_listitem_cb, NULL);
g_signal_connect (my_factory, "bind", bind_listitem_cb, NULL);
}
// user_function can be : setup, bind, unbind or teardown // user_function can be : setup, bind, unbind or teardown
// //
@ -167,6 +164,7 @@ static void any_user_function (GtkSignalListItemFactory *self, GtkListItem *list
// If your “bind” handler connects to signals on the item or does other things that require cleanup, // If your “bind” handler connects to signals on the item or does other things that require cleanup,
// you can use the “unbind” signal to do that cleanup. The “setup” signal has a similar counterpart called “teardown”. // you can use the “unbind” signal to do that cleanup. The “setup” signal has a similar counterpart called “teardown”.
static GListModel *create_settings_model (gpointer item, static GListModel *create_settings_model (gpointer item,
gpointer unused) gpointer unused)
{ {
@ -240,8 +238,12 @@ user_function (GListModel *list,
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// 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
// Gio Gnome input output // https://docs.gtk.org/gtk4/
// https://docs.gtk.org/gtk4/question_index.html
// https://docs.gtk.org/gtk4/running.html
//
// https://docs.gtk.org/gtk4/section-list-widget.html // https://docs.gtk.org/gtk4/section-list-widget.html
// https://gnome.pages.gitlab.gnome.org/libsoup/gio/GListModel.html // https://gnome.pages.gitlab.gnome.org/libsoup/gio/GListModel.html
// https://blog.gtk.org/2020/09/05/a-primer-on-gtklistview/ <<< Factory mechanism // https://blog.gtk.org/2020/09/05/a-primer-on-gtklistview/ <<< Factory mechanism
@ -254,4 +256,9 @@ user_function (GListModel *list,
// https://gitlab.gnome.org/GNOME/gtk/-/blob/main/demos/gtk-demo/listview_settings.c GtkBuilder *builder; (line 216) // https://gitlab.gnome.org/GNOME/gtk/-/blob/main/demos/gtk-demo/listview_settings.c GtkBuilder *builder; (line 216)
// https://discourse.gnome.org/t/how-can-i-get-the-expanded-collapsed-items-in-the-new-gtktreelistmodel-implementation/16824 // https://discourse.gnome.org/t/how-can-i-get-the-expanded-collapsed-items-in-the-new-gtktreelistmodel-implementation/16824
// https://developer-old.gnome.org/gtk4/stable/GtkSignalListItemFactory.html // https://developer-old.gnome.org/gtk4/stable/GtkSignalListItemFactory.html
// https://docs.gtk.org/gtk4/method.StringList.take.html
// https://developer-old.gnome.org/gtk4/stable/gtk-running.html
// https://fr.wikibooks.org/wiki/Programmation_GTK // mars 2022
// https://fr.wikibooks.org/wiki/Programmation_GTK/Bonjour_tout_le_monde