un p'tit commit avant de connecter tout ça (^z < on en reparlera)
This commit is contained in:
parent
eec2ddeddb
commit
6e2594085a
1
(notes)
1
(notes)
|
@ -7,6 +7,7 @@ https://docs.gtk.org/gtk4/class.Widget.html#height-for-width-geometry-management
|
||||||
https://docs.gtk.org/gtk4/section-text-widget.html texts
|
https://docs.gtk.org/gtk4/section-text-widget.html texts
|
||||||
https://docs.gtk.org/gtk4/drag-and-drop.html drag-and-drop
|
https://docs.gtk.org/gtk4/drag-and-drop.html drag-and-drop
|
||||||
https://docs.gtk.org/gtk4/class.GestureZoom.html GtkGestureZoom
|
https://docs.gtk.org/gtk4/class.GestureZoom.html GtkGestureZoom
|
||||||
|
https://docs.gtk.org/gtk4/class.ListView.html
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
111
hot.c
111
hot.c
|
@ -13,9 +13,51 @@
|
||||||
// GTK_ORIENTATION_VERTICAL GTK_ORIENTATION_HORIZONTAL
|
// GTK_ORIENTATION_VERTICAL GTK_ORIENTATION_HORIZONTAL
|
||||||
|
|
||||||
|
|
||||||
static void on_experimental_tree_bind_factory (GtkSignalListItemFactory *factory,
|
static struct TreeNode_t {gchar *text; struct TreeNode_t *child, *next;};
|
||||||
GObject* object,
|
|
||||||
gpointer user_data);
|
static GListModel* ui_experimental_tree_get_children_model (struct TreeNode_t *parent){
|
||||||
|
GtkStringList *list = NULL;
|
||||||
|
if (parent) {
|
||||||
|
printf("[ui_experimental_tree_get_children_model] here is %s content : ", parent->text);
|
||||||
|
struct TreeNode_t *child = parent->child;
|
||||||
|
if (child) {list = gtk_string_list_new(NULL);}
|
||||||
|
while(child) {
|
||||||
|
gtk_string_list_append(list, child->text);
|
||||||
|
printf("%s ", child->text);
|
||||||
|
child = child->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
return G_LIST_MODEL(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
static GListModel* ui_experimental_tree_create_model_func (GObject *item, gpointer root){
|
||||||
|
struct TreeNode_t *cur = (struct TreeNode_t *)root;
|
||||||
|
struct TreeNode_t *parent = root;
|
||||||
|
const gchar *string = gtk_string_object_get_string (GTK_STRING_OBJECT(item));
|
||||||
|
while (cur) {
|
||||||
|
if (strcmp(string, cur->text) == 0) break;
|
||||||
|
cur = cur->next;
|
||||||
|
if (cur == NULL) {cur = parent->child; parent = cur;}
|
||||||
|
}
|
||||||
|
printf("[ui_experimental_tree_create_model_func] looked for %s in %s item\n", cur->text, string);
|
||||||
|
return ui_experimental_tree_get_children_model(cur);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void on_experimental_tree_bind_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data){
|
||||||
|
GtkListItem *list_item = GTK_LIST_ITEM (object);
|
||||||
|
GtkTreeListRow *row = gtk_list_item_get_item (list_item);
|
||||||
|
if (row != NULL) {
|
||||||
|
const gchar *text = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_tree_list_row_get_item (row)));
|
||||||
|
GtkWidget *expander = gtk_list_item_get_child (list_item);
|
||||||
|
gtk_expander_set_label (GTK_EXPANDER (expander), text);
|
||||||
|
// g_signal_handlers_disconnect_by_func(expander, G_CALLBACK(on_tree_expander_toggled), row);
|
||||||
|
// g_signal_connect(expander, "activate", G_CALLBACK(on_tree_expander_toggled), row);
|
||||||
|
gtk_widget_set_margin_start(expander, gtk_tree_list_row_get_depth(row)*20);
|
||||||
|
gboolean is_expanded = gtk_tree_list_row_get_expanded(row);
|
||||||
|
printf("[on_experimental_tree_bind_factory] row != NULL here is %s content and expander is %d\n", text, is_expanded);
|
||||||
|
} else printf("[on_experimental_tree_bind_factory] row == NULL\n");
|
||||||
|
}
|
||||||
|
|
||||||
static void on_experimental_expander_toggled(GtkExpander *expander, gpointer user_data){
|
static void on_experimental_expander_toggled(GtkExpander *expander, gpointer user_data){
|
||||||
gtk_expander_set_expanded (expander, gtk_expander_get_expanded (expander));
|
gtk_expander_set_expanded (expander, gtk_expander_get_expanded (expander));
|
||||||
|
@ -31,6 +73,23 @@ void on_experimental_tree_setup_factory (GtkSignalListItemFactory *factory,
|
||||||
printf("[on_experimental_tree_setup_factory] here is an expander\n");
|
printf("[on_experimental_tree_setup_factory] here is an expander\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct TreeNode_t *create_tree_node (const gchar* text){
|
||||||
|
struct TreeNode_t *node = g_malloc0 (sizeof(struct TreeNode_t));
|
||||||
|
node->text = g_strdup(text);
|
||||||
|
node->child = NULL;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child){
|
||||||
|
if (parent->child) {
|
||||||
|
struct TreeNode_t *cur = parent->child;
|
||||||
|
while (cur && cur->next) {
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
|
cur->next = child;
|
||||||
|
} else parent->child = child;
|
||||||
|
}
|
||||||
|
|
||||||
void create_experimental_tree (GtkBox *experimental_box){
|
void create_experimental_tree (GtkBox *experimental_box){
|
||||||
GtkSignalListItemFactory *factory = GTK_SIGNAL_LIST_ITEM_FACTORY (gtk_signal_list_item_factory_new ());
|
GtkSignalListItemFactory *factory = GTK_SIGNAL_LIST_ITEM_FACTORY (gtk_signal_list_item_factory_new ());
|
||||||
g_signal_connect (factory, "setup", G_CALLBACK(on_experimental_tree_setup_factory), NULL);
|
g_signal_connect (factory, "setup", G_CALLBACK(on_experimental_tree_setup_factory), NULL);
|
||||||
|
@ -49,49 +108,3 @@ void create_experimental_tree (GtkBox *experimental_box){
|
||||||
gtk_box_append (experimental_box, GTK_WIDGET (it_s_me));
|
gtk_box_append (experimental_box, GTK_WIDGET (it_s_me));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void on_experimental_tree_bind_factory (GtkSignalListItemFactory *factory,
|
|
||||||
GObject* object,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
// GObject *item;
|
|
||||||
const gchar *text;
|
|
||||||
GtkTreeListRow *row;
|
|
||||||
GtkListItem *list_item;
|
|
||||||
GtkWidget *expander;
|
|
||||||
|
|
||||||
list_item= GTK_LIST_ITEM(object);
|
|
||||||
row = gtk_list_item_get_item(list_item);
|
|
||||||
if (row != NULL) {
|
|
||||||
text = gtk_string_object_get_string(GTK_STRING_OBJECT(gtk_tree_list_row_get_item(row)));
|
|
||||||
expander = gtk_list_item_get_child(list_item);
|
|
||||||
gtk_expander_set_label(GTK_EXPANDER(expander), text);
|
|
||||||
|
|
||||||
// Disconnect previous signal handlers to avoid stacking them
|
|
||||||
// TODO g_signal_handlers_disconnect_by_func(expander, G_CALLBACK(on_tree_expander_toggled), row);
|
|
||||||
|
|
||||||
// Connect the signal handler
|
|
||||||
// TODO g_signal_connect(expander, "activate", G_CALLBACK(on_tree_expander_toggled), row);
|
|
||||||
|
|
||||||
gtk_widget_set_margin_start(expander, gtk_tree_list_row_get_depth(row)*20);
|
|
||||||
gboolean is_expanded = gtk_tree_list_row_get_expanded(row);
|
|
||||||
printf("[on_experimental_tree_bind_factory] here is %s content and expander is %d\n",
|
|
||||||
text,
|
|
||||||
is_expanded);
|
|
||||||
} else {
|
|
||||||
printf("[on_tree_bind_factory] here is NON content\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue