before completing my first experimental GTK4 tree
This commit is contained in:
parent
2af51060e7
commit
2bd8febffc
58
hot.c
58
hot.c
|
@ -15,6 +15,26 @@
|
|||
|
||||
static struct TreeNode_t {gchar *text; struct TreeNode_t *child, *next;};
|
||||
|
||||
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; // printf("create_tree_node %s\n", text);
|
||||
return node;
|
||||
}
|
||||
|
||||
/*static void on_experimental_expander_toggled(GtkExpander *expander, gpointer user_data){
|
||||
gtk_expander_set_expanded (expander, gtk_expander_get_expanded (expander));
|
||||
printf("> %s\n", gtk_expander_get_label (user_data));
|
||||
}*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static GListModel* ui_experimental_tree_get_children_model (struct TreeNode_t *parent){
|
||||
GtkStringList *list = NULL;
|
||||
if (parent) {
|
||||
|
@ -55,45 +75,21 @@ static void on_experimental_tree_bind_factory (GtkSignalListItemFactory *factory
|
|||
// 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);
|
||||
printf("[on_experimental_tree_bind_factory] row content is [%s] 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){
|
||||
gtk_expander_set_expanded (expander, gtk_expander_get_expanded (expander));
|
||||
printf("> %s\n", gtk_expander_get_label (user_data));
|
||||
}
|
||||
|
||||
void on_experimental_tree_setup_factory (GtkSignalListItemFactory *factory,
|
||||
GObject* object,
|
||||
gpointer user_data)
|
||||
{
|
||||
GObject* object, gpointer user_data){
|
||||
GtkWidget* expander = gtk_expander_new (NULL);
|
||||
gtk_list_item_set_child (GTK_LIST_ITEM(object), expander);
|
||||
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){
|
||||
struct TreeNode_t *tree_root = create_tree_node("hello");
|
||||
struct TreeNode_t *child = create_tree_node("it's me");
|
||||
add_child_node(tree_root, child);
|
||||
struct TreeNode_t *it_s_me = create_tree_node("it's me"); add_child_node(tree_root, it_s_me);
|
||||
struct TreeNode_t *remember = create_tree_node("remember"); add_child_node(it_s_me, remember);
|
||||
|
||||
GtkStringList *model = gtk_string_list_new(NULL);
|
||||
gtk_string_list_append (model, tree_root->text);
|
||||
|
@ -109,6 +105,7 @@ void create_experimental_tree (GtkBox *experimental_box){
|
|||
tree_root,
|
||||
NULL // (GDestroyNotify) free_tree_node
|
||||
);
|
||||
|
||||
GtkSingleSelection *selection_model = gtk_single_selection_new (G_LIST_MODEL (tree_model));
|
||||
gtk_single_selection_set_autoselect (selection_model, FALSE);
|
||||
gtk_single_selection_set_can_unselect (selection_model, TRUE);
|
||||
|
@ -116,8 +113,9 @@ void create_experimental_tree (GtkBox *experimental_box){
|
|||
GtkWidget *list_view = gtk_list_view_new (GTK_SELECTION_MODEL (selection_model),
|
||||
GTK_LIST_ITEM_FACTORY (factory));
|
||||
|
||||
gtk_widget_set_visible(GTK_WIDGET(experimental_box), TRUE);
|
||||
gtk_widget_set_visible(GTK_WIDGET(list_view), TRUE);
|
||||
gtk_box_append(experimental_box, list_view);
|
||||
|
||||
// gtk_widget_set_visible(GTK_WIDGET(experimental_box), TRUE);
|
||||
// gtk_widget_set_visible(GTK_WIDGET(list_view), TRUE);
|
||||
}
|
||||
|
||||
|
|
28
tree.c
28
tree.c
|
@ -199,25 +199,15 @@ void ui_create_tree (GtkWidget *target_widget)
|
|||
|
||||
assert(target_widget);
|
||||
|
||||
// AD HOC XXX & no free()
|
||||
struct TreeNode_t *tree_root = create_tree_node("Root");
|
||||
struct TreeNode_t *ATP = create_tree_node("ATP");
|
||||
struct TreeNode_t *ADP = create_tree_node("ADP");
|
||||
struct TreeNode_t *AMP = create_tree_node("AMP");
|
||||
struct TreeNode_t *adenine = create_tree_node("adénine");
|
||||
struct TreeNode_t *ribose = create_tree_node("ribose");
|
||||
struct TreeNode_t *PO4H3_1 = create_tree_node("phosphate 1");
|
||||
struct TreeNode_t *PO4H3_2 = create_tree_node("phosphate 2");
|
||||
struct TreeNode_t *PO4H3_3 = create_tree_node("phosphate 3");
|
||||
|
||||
add_child_node(tree_root, ATP);
|
||||
add_child_node(tree_root, ADP);
|
||||
add_child_node(tree_root, AMP);
|
||||
add_child_node(ATP, adenine);
|
||||
add_child_node(adenine, ribose);
|
||||
add_child_node(ribose, PO4H3_1);
|
||||
add_child_node(PO4H3_1, PO4H3_2);
|
||||
add_child_node(PO4H3_3, PO4H3_3);
|
||||
struct TreeNode_t *tree_root = create_tree_node("Root"); // AD HOC XXX & no free()
|
||||
struct TreeNode_t *ATP = create_tree_node("ATP"); add_child_node(tree_root, ATP);
|
||||
struct TreeNode_t *ADP = create_tree_node("ADP"); add_child_node(tree_root, ADP);
|
||||
struct TreeNode_t *AMP = create_tree_node("AMP"); add_child_node(tree_root, AMP);
|
||||
struct TreeNode_t *adenine = create_tree_node("adénine"); add_child_node(ATP, adenine);
|
||||
struct TreeNode_t *ribose = create_tree_node("ribose"); add_child_node(adenine, ribose);
|
||||
struct TreeNode_t *PO4H3_1 = create_tree_node("phosphate 1"); add_child_node(ribose, PO4H3_1);
|
||||
struct TreeNode_t *PO4H3_2 = create_tree_node("phosphate 2"); add_child_node(PO4H3_1, PO4H3_2);
|
||||
struct TreeNode_t *PO4H3_3 = create_tree_node("phosphate 3"); add_child_node(PO4H3_2, PO4H3_3);
|
||||
|
||||
model = gtk_string_list_new(NULL);
|
||||
gtk_string_list_append(model, tree_root->text);
|
||||
|
|
Loading…
Reference in New Issue