From 1f96af32fdd8deaafdd6184f5bdbca9153429949 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Sat, 25 Nov 2023 08:59:48 +0100 Subject: [PATCH] WIP: introducing a simple text renderer. (I) --- src/ui/tree.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/src/ui/tree.c b/src/ui/tree.c index ac48935..3c93c5f 100644 --- a/src/ui/tree.c +++ b/src/ui/tree.c @@ -28,12 +28,49 @@ #include "../../include/base.h" #include "../../include/ui.h" +#include + +enum +{ + COL_FIRST_NAME = 0, + COL_LAST_NAME, + NUM_COLS +} ; + GtkListStore *list_store; GtkTreeStore *tree_store; GtkTreeIter iter, child; static void tree_c_printing_test(void); +static GtkTreeModel * +create_and_fill_model (void) +{ + GtkTreeStore *treestore; + GtkTreeIter toplevel, child; + + treestore = gtk_tree_store_new(NUM_COLS, G_TYPE_STRING, G_TYPE_STRING); + + /* Append a top level row and leave it empty */ + gtk_tree_store_append(treestore, &toplevel, NULL); + + /* Append a second top level row, and fill it with some data */ + gtk_tree_store_append(treestore, &toplevel, NULL); + gtk_tree_store_set(treestore, &toplevel, + COL_FIRST_NAME, "Joe", + COL_LAST_NAME, "Dalton", + -1); + + /* Append a child to the second top level row, and fill in some data */ + gtk_tree_store_append(treestore, &child, &toplevel); + gtk_tree_store_set(treestore, &child, + COL_FIRST_NAME, "Averell", + COL_LAST_NAME, "Dalton", + -1); + + return GTK_TREE_MODEL(treestore); +} + /*********************************************************** * * * Going through every row in a list store * @@ -130,10 +167,10 @@ tree_c_test(void) static void tree_c_printing_test(void) { - printf("tree_c_printing_test() \ ---------------------------------------------------------\n\n\ -(https://en.wikibooks.org/wiki/GTK (modulo) 2B_By_Example/Tree_View/Tree_Models)\n\n\ +(https://en.wikibooks.org/wiki/GTK (modulo) 2B_By_Example/Tree_View/Tree_Models)\n\ +(https://en.wikibooks.org/wiki/GTK (modulo) 2B_By_Example/Tree_View/Columns_and_Renderer)\n\n\ cf. tuto : gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_UINT); - (cf. line 69)\n\ creates a new list store with two columns.\n\n\ gtk_tree_store_new(1, G_TYPE_STRING); - (cf. line 108)\n\