Revert "Pourquoi ajouter les enfants d'un noeud à la fin de la liste (des enfants) ?"

This reverts commit b8874c8e7c.
This commit is contained in:
Jean Sirmai 2024-05-23 11:55:50 +02:00
parent b8874c8e7c
commit abf5c4ca3e
Signed by: jean
GPG Key ID: FB3115C340E057E3
4 changed files with 17 additions and 29 deletions

46
hot.c
View File

@ -12,39 +12,20 @@
// https://docs.gtk.org/gtk4/class.Widget.html#height-for-width-geometry-management // https://docs.gtk.org/gtk4/class.Widget.html#height-for-width-geometry-management
// GTK_ORIENTATION_VERTICAL GTK_ORIENTATION_HORIZONTAL // GTK_ORIENTATION_VERTICAL GTK_ORIENTATION_HORIZONTAL
static struct TreeNode_t {gchar *text; struct TreeNode_t *child, *next;};
static struct TreeNode_t {gchar *text; struct TreeNode_t *child, *next;};
static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child);
static struct TreeNode_t *create_user_tree_node (const gchar* text){ static struct TreeNode_t *create_user_tree_node (const gchar* text){
struct TreeNode_t *node = g_malloc0 (sizeof(struct TreeNode_t)); struct TreeNode_t *node = g_malloc0 (sizeof(struct TreeNode_t));
node->text = g_strdup (text); node->text = g_strdup (text);
node->child = NULL; node->child = NULL; // if (0) printf("create_user_tree_node %s\n", text);
printf("create_user_tree_node %s ", text); if (text == "root") printf("\n");
return node; return node;
} }
static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child){ static void create_a_complex_useless_and_expensive_tree (struct TreeNode_t *tree_root){
if (parent->child && parent->child != child) { /* struct TreeNode_t *move_random = create_user_tree_node("move random"); add_child_node(tree_root, move_random);
parent->child = child; struct TreeNode_t *move_determ = create_user_tree_node("move determ"); add_child_node(tree_root, move_determ);
printf("add_child_node (%s, %s) \n", parent->text, child->text); struct TreeNode_t *transport = create_user_tree_node("transport"); add_child_node(tree_root, transport);*/
} else printf("add_child_node (%s, %s) else \n", parent->text, child->text);
}
static void create_a_simple_tree (struct TreeNode_t *tree_root){
struct TreeNode_t *a = create_user_tree_node("a"); add_child_node(tree_root, a);
struct TreeNode_t *b = create_user_tree_node("b"); add_child_node(tree_root, b);
struct TreeNode_t *aa = create_user_tree_node("aa"); add_child_node(a, aa);
struct TreeNode_t *aaa = create_user_tree_node("aaa"); add_child_node(aa, aaa);
struct TreeNode_t *bb = create_user_tree_node("bb"); add_child_node(b, bb);
struct TreeNode_t *bbb = create_user_tree_node("bbb"); add_child_node(bb, bbb);
}
static void create_a_hazardous_complex_useless_and_expensive_tree (struct TreeNode_t *tree_root){
// struct TreeNode_t *move_random = create_user_tree_node("move random"); add_child_node(tree_root, move_random);
// struct TreeNode_t *move_determ = create_user_tree_node("move determ"); add_child_node(tree_root, move_determ);
// struct TreeNode_t *transport = create_user_tree_node("transport"); add_child_node(tree_root, transport);
struct TreeNode_t *transform = create_user_tree_node("transform"); add_child_node(tree_root, transform); struct TreeNode_t *transform = create_user_tree_node("transform"); add_child_node(tree_root, transform);
struct TreeNode_t *regulate = create_user_tree_node("regulate"); add_child_node(tree_root, regulate); struct TreeNode_t *regulate = create_user_tree_node("regulate"); add_child_node(tree_root, regulate);
/* struct TreeNode_t *isole = create_user_tree_node("isolated object"); add_child_node(move_random, isole); /* struct TreeNode_t *isole = create_user_tree_node("isolated object"); add_child_node(move_random, isole);
@ -132,10 +113,17 @@ GListModel* get_user_tree_model (GObject *item, gpointer root){
return get_user_tree_model_child (cur); return get_user_tree_model_child (cur);
} }
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;
}
GtkScrolledWindow *get_user_rules_tree (){ GtkScrolledWindow *get_user_rules_tree (){
struct TreeNode_t *tree_root = create_user_tree_node("root"); struct TreeNode_t *tree_root = create_user_tree_node("root");
// create_a_hazardous_complex_useless_and_expensive_tree (tree_root); create_a_complex_useless_and_expensive_tree (tree_root);
create_a_simple_tree (tree_root);
GtkStringList *model = gtk_string_list_new(NULL); GtkStringList *model = gtk_string_list_new(NULL);
gtk_string_list_append (model, tree_root->text); gtk_string_list_append (model, tree_root->text);
@ -146,7 +134,7 @@ GtkScrolledWindow *get_user_rules_tree (){
GtkTreeListModel *tree_model = gtk_tree_list_model_new( GtkTreeListModel *tree_model = gtk_tree_list_model_new(
G_LIST_MODEL (model), G_LIST_MODEL (model),
FALSE, // Passthrough - False in actual usage with dynamic children retrieval FALSE, // Passthrough - False in actual usage with dynamic children retrieval
FALSE, // autoexpand TRUE, // TRUE, // FALSE, // autoexpand
(GtkTreeListModelCreateModelFunc) &get_user_tree_model, (GtkTreeListModelCreateModelFunc) &get_user_tree_model,
tree_root, tree_root,
NULL // (GDestroyNotify) free_user_tree_node NULL // (GDestroyNotify) free_user_tree_node

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB