WIP: playing in the sand box
This commit is contained in:
parent
ca2a4e332d
commit
fadd5f256f
|
@ -128,3 +128,5 @@ GtkWidget *create_my_deprec_tree_model(GtkBox *runlib_objects);
|
|||
GtkWidget *create_my_button_test(GtkBox *runlib_objects);
|
||||
GtkWidget *create_my_list_view_test(GtkBox *runlib_objects);
|
||||
GtkWidget *create_my_editable_cells (GtkBox *my_box);
|
||||
|
||||
void hello_it_s_me();
|
||||
|
|
|
@ -58,6 +58,8 @@
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
hello_it_s_me(); // in bac-à-sable
|
||||
|
||||
g_autoptr(GemGraphClientApplication) app = NULL;
|
||||
int res;
|
||||
|
||||
|
@ -67,3 +69,4 @@ int main(int argc, char **argv)
|
|||
res = g_application_run(G_APPLICATION(app), argc, argv);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,71 +28,38 @@
|
|||
#include "../../include/base.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* view;
|
||||
GtkTreeViewColumn* column;
|
||||
GtkWidget* window;
|
||||
GtkWidget *my_window;
|
||||
GtkWidget *my_box;
|
||||
GtkWidget *my_button;
|
||||
char *my_title = "Hello, it's me !";
|
||||
char *my_button_title = "And I'm the button.";
|
||||
|
||||
/* 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);
|
||||
gtk_init();
|
||||
my_window = gtk_window_new ();
|
||||
|
||||
/* VIEW */
|
||||
view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
|
||||
g_object_unref(model);
|
||||
g_signal_connect(G_OBJECT (my_window), "on_destroy::", G_CALLBACK(on_destroy), NULL);
|
||||
|
||||
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);
|
||||
gtk_window_set_title (GTK_WINDOW(my_window), my_title);
|
||||
gtk_window_set_default_size (GTK_WINDOW(my_window), 200, 34);
|
||||
|
||||
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);
|
||||
my_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
|
||||
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);
|
||||
my_button = gtk_button_new_with_label (my_button_title);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,6 +28,9 @@
|
|||
#include "../../include/base.h"
|
||||
#include "../../include/ui.h"
|
||||
|
||||
// TODO use GTK_DEBUG
|
||||
GTK_DEBUG;
|
||||
|
||||
enum
|
||||
{
|
||||
STRING_COLUMN,
|
||||
|
@ -42,13 +45,6 @@ struct _TreeItem
|
|||
TreeItem *children;
|
||||
};
|
||||
|
||||
void // https://docs.gtk.org/gtk4/method.StringList.take.html
|
||||
gtk_string_list_take (
|
||||
GtkStringList* self,
|
||||
char* string
|
||||
)
|
||||
{}
|
||||
|
||||
// tree data
|
||||
static TreeItem E[] = {NULL}, F[] = {NULL}, G[] = {NULL}, H[] = {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 O[] = {{"ROOT", R}, {NULL}}; // Artefact added for symmetry
|
||||
|
||||
void gtk_string_list_take (GtkStringList* self, char* string){}
|
||||
|
||||
static void
|
||||
bind_listitem_cb_complex (GtkListItemFactory *factory,
|
||||
GtkListItem *list_item)
|
||||
static void bind_listitem_cb_complex (GtkListItemFactory *factory,
|
||||
GtkListItem *list_item)
|
||||
{
|
||||
GtkWidget *label;
|
||||
TreeItem *obj;
|
||||
|
@ -76,9 +72,8 @@ bind_listitem_cb_complex (GtkListItemFactory *factory,
|
|||
static GtkWidget *my_tree_view;
|
||||
static GListModel *my_Glist_model = NULL;
|
||||
|
||||
|
||||
// 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;
|
||||
|
@ -114,10 +109,10 @@ static void setup_listitem_cb (GtkListItemFactory *my_factory,
|
|||
GtkLabel *my_label,
|
||||
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);
|
||||
|
||||
//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_list_item_set_child (my_list_item, my_image);
|
||||
}
|
||||
|
@ -144,13 +139,15 @@ static void activate_cb (GtkListView *list,
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Parameters : self : the GtkSignalListItemFactory,
|
||||
// listitem : the GtkListItem to bind,
|
||||
// user_data : the user data set when the signal handler was connected.
|
||||
// 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
|
||||
//
|
||||
|
@ -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,
|
||||
// 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,
|
||||
gpointer unused)
|
||||
{
|
||||
|
@ -240,8 +238,12 @@ user_function (GListModel *list,
|
|||
//------------------------------------------------------------------------------
|
||||
|
||||
// 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://gnome.pages.gitlab.gnome.org/libsoup/gio/GListModel.html
|
||||
// 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://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://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
|
||||
|
|
Loading…
Reference in New Issue