Pourquoi ajouter les enfants d'un noeud à la fin de la liste (des enfants) ?
This commit is contained in:
parent
bcff5304d9
commit
b8874c8e7c
46
hot.c
46
hot.c
|
@ -12,20 +12,39 @@
|
||||||
// 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; // 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;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void create_a_complex_useless_and_expensive_tree (struct TreeNode_t *tree_root){
|
static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child){
|
||||||
/* struct TreeNode_t *move_random = create_user_tree_node("move random"); add_child_node(tree_root, move_random);
|
if (parent->child && parent->child != child) {
|
||||||
struct TreeNode_t *move_determ = create_user_tree_node("move determ"); add_child_node(tree_root, move_determ);
|
parent->child = child;
|
||||||
struct TreeNode_t *transport = create_user_tree_node("transport"); add_child_node(tree_root, transport);*/
|
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 *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);
|
||||||
|
@ -113,17 +132,10 @@ 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_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);
|
GtkStringList *model = gtk_string_list_new(NULL);
|
||||||
gtk_string_list_append (model, tree_root->text);
|
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(
|
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
|
||||||
TRUE, // FALSE, // autoexpand
|
FALSE, // autoexpand TRUE, //
|
||||||
(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.
After Width: | Height: | Size: 43 KiB |
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
Binary file not shown.
After Width: | Height: | Size: 43 KiB |
Loading…
Reference in New Issue