diff --git a/hot.c b/hot.c index 371fb7e..1b4aa57 100644 --- a/hot.c +++ b/hot.c @@ -12,20 +12,39 @@ // https://docs.gtk.org/gtk4/class.Widget.html#height-for-width-geometry-management // GTK_ORIENTATION_VERTICAL GTK_ORIENTATION_HORIZONTAL - 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){ struct TreeNode_t *node = g_malloc0 (sizeof(struct TreeNode_t)); node->text = g_strdup (text); - node->child = NULL; // if (0) printf("create_user_tree_node %s\n", text); + node->child = NULL; + printf("create_user_tree_node %s ", text); if (text == "root") printf("\n"); return node; } -static void create_a_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);*/ +static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child){ + if (parent->child && parent->child != child) { + parent->child = child; + printf("add_child_node (%s, %s) \n", parent->text, child->text); + } 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 *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); @@ -113,17 +132,10 @@ GListModel* get_user_tree_model (GObject *item, gpointer root){ 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 (){ struct TreeNode_t *tree_root = create_user_tree_node("root"); - create_a_complex_useless_and_expensive_tree (tree_root); +// create_a_hazardous_complex_useless_and_expensive_tree (tree_root); + create_a_simple_tree (tree_root); GtkStringList *model = gtk_string_list_new(NULL); gtk_string_list_append (model, tree_root->text); @@ -134,7 +146,7 @@ GtkScrolledWindow *get_user_rules_tree (){ GtkTreeListModel *tree_model = gtk_tree_list_model_new( G_LIST_MODEL (model), FALSE, // Passthrough - False in actual usage with dynamic children retrieval - TRUE, // FALSE, // autoexpand + FALSE, // autoexpand TRUE, // (GtkTreeListModelCreateModelFunc) &get_user_tree_model, tree_root, NULL // (GDestroyNotify) free_user_tree_node diff --git a/image/autoexpand = FALSE.png b/image/autoexpand = FALSE.png new file mode 100644 index 0000000..fa42796 Binary files /dev/null and b/image/autoexpand = FALSE.png differ diff --git a/image/node a is added to the root before node b.png b/image/node a is added to the root before node b.png new file mode 100644 index 0000000..7646128 Binary files /dev/null and b/image/node a is added to the root before node b.png differ diff --git a/image/node b is added to the root before node a.png b/image/node b is added to the root before node a.png new file mode 100644 index 0000000..7e73229 Binary files /dev/null and b/image/node b is added to the root before node a.png differ