WIP: ^c^v pas à pas, suite (DON'T read this commit)
This commit is contained in:
parent
d9689373d8
commit
6d4c076f98
|
@ -29,9 +29,61 @@
|
||||||
#include "../../include/ui.h"
|
#include "../../include/ui.h"
|
||||||
|
|
||||||
static void and_now_let_s_climb_that_tree (GtkWidget *in_that_box);
|
static void and_now_let_s_climb_that_tree (GtkWidget *in_that_box);
|
||||||
static void on_bind_list_item_cb (GtkListItemFactory* factory, GtkListItem* list_item, gpointer user_data){}
|
|
||||||
static void on_setup_list_item_cb (GtkListItemFactory* factory, GtkListItem* list_item, gpointer user_data){}
|
// This function is a placeholder. You need to implement the logic based on your tree structure.
|
||||||
|
static GListModel* create_child_model (const gchar* parent) {
|
||||||
|
GtkStringList* list = gtk_string_list_new (NULL);
|
||||||
|
if (g_strcmp0 (parent, "Parent Item 1") == 0) {
|
||||||
|
gtk_string_list_append (list, "Child 1.1");
|
||||||
|
gtk_string_list_append (list, "Child 1.2");
|
||||||
|
} else if (g_strcmp0 (parent, "Parent Item 2") == 0) {
|
||||||
|
gtk_string_list_append (list, "Child 2.1");
|
||||||
|
}
|
||||||
|
return G_LIST_MODEL (list);
|
||||||
|
}
|
||||||
|
|
||||||
static void on_destroy (GtkWidget *widget, gpointer data) {if (data) g_print (data); exit (0);}
|
static void on_destroy (GtkWidget *widget, gpointer data) {if (data) g_print (data); exit (0);}
|
||||||
|
|
||||||
|
static void on_bind_list_item_cb (GtkListItemFactory* factory, GtkListItem* list_item, gpointer user_data)
|
||||||
|
{
|
||||||
|
GObject* item = gtk_list_item_get_item (list_item);
|
||||||
|
if (!item) return; // Necessary check
|
||||||
|
|
||||||
|
const gchar* text = gtk_string_object_get_string (GTK_STRING_OBJECT (item));
|
||||||
|
|
||||||
|
GtkWidget* label = gtk_label_new (text);
|
||||||
|
GtkWidget* expander = gtk_list_item_get_child (list_item);
|
||||||
|
gtk_tree_expander_set_child (GTK_TREE_EXPANDER (expander), label);
|
||||||
|
|
||||||
|
// Determine if this item should have an expander (i.e., if it has children)
|
||||||
|
GListModel* child_model = create_child_model (text);
|
||||||
|
if (child_model) gtk_tree_expander_set_expanded (GTK_TREE_EXPANDER (expander), TRUE);
|
||||||
|
g_object_unref (child_model); // Cleanup
|
||||||
|
}
|
||||||
|
|
||||||
|
static void on_setup_list_item_cb (GtkListItemFactory* factory, GtkListItem* list_item, gpointer user_data) {
|
||||||
|
GtkWidget* expander = gtk_tree_expander_new ();
|
||||||
|
gtk_list_item_set_child (list_item, expander);
|
||||||
|
}
|
||||||
|
|
||||||
|
static GtkTreeListModel* create_tree_list_model () {
|
||||||
|
// Initial parent items
|
||||||
|
GtkStringList* base_model = gtk_string_list_new (NULL);
|
||||||
|
gtk_string_list_append (base_model, "Parent Item 1");
|
||||||
|
gtk_string_list_append (base_model, "Parent Item 2");
|
||||||
|
|
||||||
|
// Create a GtkTreeListModel that uses our function to fetch children for each parent
|
||||||
|
GtkTreeListModel* tree_model = gtk_tree_list_model_new (
|
||||||
|
GTK_SELECTION_MODEL (gtk_no_selection_new (G_LIST_MODEL (base_model))),
|
||||||
|
TRUE, // True to check for child items
|
||||||
|
0,
|
||||||
|
(GtkTreeListModelCreateModelFunc) create_child_model,
|
||||||
|
NULL, // user data
|
||||||
|
g_object_unref);
|
||||||
|
// cleanup function for user data
|
||||||
|
return tree_model;
|
||||||
|
}
|
||||||
|
|
||||||
static void on_app_activate (GApplication* app, gpointer user_data) {
|
static void on_app_activate (GApplication* app, gpointer user_data) {
|
||||||
GtkWidget* window = gtk_application_window_new (GTK_APPLICATION (app));
|
GtkWidget* window = gtk_application_window_new (GTK_APPLICATION (app));
|
||||||
gtk_window_set_title (GTK_WINDOW (window), "GTK4 Tree Example");
|
gtk_window_set_title (GTK_WINDOW (window), "GTK4 Tree Example");
|
||||||
|
|
Loading…
Reference in New Issue