2024-04-27 16:16:21 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <gtk-4.0/gtk/gtk.h>
|
2024-05-08 07:50:04 +02:00
|
|
|
|
2024-04-29 23:43:04 +02:00
|
|
|
#include "warm.h"
|
|
|
|
#include "cold.h"
|
2024-05-10 06:19:20 +02:00
|
|
|
#include "display.h"
|
|
|
|
#include "contain.h"
|
2024-05-08 23:43:23 +02:00
|
|
|
#include "texts.h"
|
2024-04-29 23:43:04 +02:00
|
|
|
|
2024-04-30 18:59:44 +02:00
|
|
|
// https://docs.gtk.org/gtk4/visual_index.html < widgets gallery
|
2024-05-10 23:14:45 +02:00
|
|
|
// https://docs.gtk.org/gtk4/section-text-widget.html
|
2024-05-08 23:43:23 +02:00
|
|
|
// https://docs.gtk.org/gtk4/class.Widget.html#height-for-width-geometry-management
|
2024-05-06 23:29:54 +02:00
|
|
|
// GTK_ORIENTATION_VERTICAL GTK_ORIENTATION_HORIZONTAL
|
|
|
|
|
2024-05-08 23:43:23 +02:00
|
|
|
|
2024-05-16 17:20:44 +02:00
|
|
|
static struct TreeNode_t {gchar *text; struct TreeNode_t *child, *next;};
|
|
|
|
|
2024-05-22 08:59:32 +02:00
|
|
|
static struct TreeNode_t *create_user_tree_node (const gchar* text){
|
2024-05-17 09:05:46 +02:00
|
|
|
struct TreeNode_t *node = g_malloc0 (sizeof(struct TreeNode_t));
|
2024-05-22 21:33:35 +02:00
|
|
|
node->text = g_strdup (text);
|
2024-05-22 08:59:32 +02:00
|
|
|
node->child = NULL; // if (0) printf("create_user_tree_node %s\n", text);
|
2024-05-17 09:05:46 +02:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2024-05-22 09:32:17 +02:00
|
|
|
void on_user_tree_expander_toggled(GtkExpander *expander, gpointer user_data)
|
2024-05-22 07:44:50 +02:00
|
|
|
{
|
|
|
|
// This is a conceptual callback for when an expander is toggled
|
2024-05-22 21:33:35 +02:00
|
|
|
GtkTreeListRow *row = GTK_TREE_LIST_ROW (user_data);
|
2024-05-22 07:44:50 +02:00
|
|
|
gboolean is_expanded = gtk_tree_list_row_get_expanded(row);
|
2024-05-22 21:33:35 +02:00
|
|
|
gtk_tree_list_row_set_expanded (row, !is_expanded);
|
2024-05-22 07:44:50 +02:00
|
|
|
}
|
|
|
|
|
2024-05-22 08:59:32 +02:00
|
|
|
static void on_bind_user_tree_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data){
|
|
|
|
GtkListItem *list_item = GTK_LIST_ITEM (object); assert (list_item);
|
|
|
|
GtkTreeListRow *row = gtk_list_item_get_item (list_item); assert (row);
|
|
|
|
// if (row != NULL) {
|
2024-05-17 10:06:06 +02:00
|
|
|
const gchar *text = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_tree_list_row_get_item (row)));
|
|
|
|
GtkWidget *expander = gtk_list_item_get_child (list_item);
|
|
|
|
gtk_expander_set_label (GTK_EXPANDER (expander), text);
|
2024-05-22 21:33:35 +02:00
|
|
|
g_signal_handlers_disconnect_by_func(expander, G_CALLBACK (on_user_tree_expander_toggled), row);
|
|
|
|
g_signal_connect(expander, "activate", G_CALLBACK (on_user_tree_expander_toggled), row);
|
2024-05-17 10:06:06 +02:00
|
|
|
gtk_widget_set_margin_start(expander, gtk_tree_list_row_get_depth(row)*20);
|
|
|
|
gboolean is_expanded = gtk_tree_list_row_get_expanded(row);
|
2024-05-22 08:59:32 +02:00
|
|
|
if (0) printf("[on_bind_user_tree_factory] row content is [%s] and expander is [%d]\n", text, is_expanded);
|
|
|
|
// } else if (0) printf("[on_bind_user_tree_factory] row == NULL\n");
|
2024-05-17 10:06:06 +02:00
|
|
|
}
|
|
|
|
|
2024-05-22 08:59:32 +02:00
|
|
|
void on_setup_user_tree_factory (GtkSignalListItemFactory *factory,
|
|
|
|
GObject* object, gpointer user_data){
|
2024-05-17 10:06:06 +02:00
|
|
|
GtkWidget* expander = gtk_expander_new (NULL);
|
2024-05-22 08:59:32 +02:00
|
|
|
gtk_list_item_set_child (GTK_LIST_ITEM (object), expander);
|
|
|
|
if (0) printf("[on_setup_user_tree_factory] here is an expander\n");
|
2024-05-17 10:06:06 +02:00
|
|
|
}
|
|
|
|
|
2024-05-22 09:32:17 +02:00
|
|
|
static GListModel* get_user_tree_model_child (struct TreeNode_t *parent){
|
2024-05-16 17:20:44 +02:00
|
|
|
GtkStringList *list = NULL;
|
2024-05-22 21:33:35 +02:00
|
|
|
if (parent) {
|
2024-05-22 09:32:17 +02:00
|
|
|
if (0) printf("[get_user_tree_model_child] here is %s content : ", parent->text);
|
2024-05-16 17:20:44 +02:00
|
|
|
struct TreeNode_t *child = parent->child;
|
|
|
|
if (child) {list = gtk_string_list_new(NULL);}
|
|
|
|
while(child) {
|
|
|
|
gtk_string_list_append(list, child->text);
|
2024-05-22 08:10:52 +02:00
|
|
|
if (0) printf("%s ", child->text);
|
2024-05-16 17:20:44 +02:00
|
|
|
child = child->next;
|
|
|
|
}
|
2024-05-22 22:01:08 +02:00
|
|
|
} // else printf("hot.c GListModel* get_user_tree_model_child (struct TreeNode_t *parent) child = %d \n", parent);
|
2024-05-22 08:10:52 +02:00
|
|
|
if (0) printf("\n");
|
2024-05-16 17:20:44 +02:00
|
|
|
return G_LIST_MODEL(list);
|
|
|
|
}
|
|
|
|
|
2024-05-22 08:59:32 +02:00
|
|
|
GListModel* get_user_tree_model (GObject *item, gpointer root){
|
2024-05-16 17:20:44 +02:00
|
|
|
struct TreeNode_t *cur = (struct TreeNode_t *)root;
|
|
|
|
struct TreeNode_t *parent = root;
|
2024-05-22 21:33:35 +02:00
|
|
|
const gchar *string = gtk_string_object_get_string (GTK_STRING_OBJECT (item));
|
2024-05-16 17:20:44 +02:00
|
|
|
while (cur) {
|
|
|
|
if (strcmp(string, cur->text) == 0) break;
|
|
|
|
cur = cur->next;
|
|
|
|
if (cur == NULL) {cur = parent->child; parent = cur;}
|
|
|
|
}
|
2024-05-22 08:59:32 +02:00
|
|
|
if (0) printf("[get_user_user_tree_model] looked for %s in %s item\n", cur->text, string);
|
2024-05-22 21:33:35 +02:00
|
|
|
// ! WARNING ! TODO CUR EST L'ENFANT, MAINTENANT DONC, SI CUR EST UNE FEUILLE, JE N'ATTEINDRAI PAS SON ENFANT
|
2024-05-22 09:32:17 +02:00
|
|
|
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;
|
2024-05-15 11:41:58 +02:00
|
|
|
}
|
|
|
|
|
2024-05-22 08:59:32 +02:00
|
|
|
GtkScrolledWindow *get_user_rules_tree (){
|
2024-05-22 09:32:17 +02:00
|
|
|
struct TreeNode_t *tree_root = create_user_tree_node("root");
|
|
|
|
struct TreeNode_t *move_random = create_user_tree_node("move random"); add_child_node(tree_root, move_random);
|
|
|
|
struct TreeNode_t *isole = create_user_tree_node("isolated object"); add_child_node(move_random, isole);
|
|
|
|
struct TreeNode_t *isole_1D = create_user_tree_node("isolated object move 1D"); add_child_node(isole, isole_1D);
|
|
|
|
struct TreeNode_t *isole_2D = create_user_tree_node("isolated object move 2D"); add_child_node(isole, isole_2D);
|
|
|
|
struct TreeNode_t *isole_3D = create_user_tree_node("isolated object move 3D"); add_child_node(isole, isole_3D);
|
2024-05-22 21:33:35 +02:00
|
|
|
struct TreeNode_t *translat_2D = create_user_tree_node("translation"); add_child_node(isole_2D, translat_2D);
|
|
|
|
struct TreeNode_t *rotat_2D = create_user_tree_node("rotation"); add_child_node(isole_2D, rotat_2D);
|
|
|
|
struct TreeNode_t *rotat_X_2D = create_user_tree_node("rotation axe X"); add_child_node(rotat_2D, rotat_X_2D);
|
|
|
|
struct TreeNode_t *rotat_Y_2D = create_user_tree_node("rotation axe Y"); add_child_node(rotat_2D, rotat_Y_2D);
|
|
|
|
struct TreeNode_t *translat_3D = create_user_tree_node("translation"); add_child_node(isole_3D, translat_3D);
|
|
|
|
struct TreeNode_t *rotat_3D = create_user_tree_node("rotation"); add_child_node(isole_3D, rotat_3D);
|
|
|
|
struct TreeNode_t *rotat_X_3D = create_user_tree_node("rotation axe X"); add_child_node(rotat_3D, rotat_X_3D);
|
|
|
|
struct TreeNode_t *rotat_Y_3D = create_user_tree_node("rotation axe Y"); add_child_node(rotat_3D, rotat_Y_3D);
|
|
|
|
struct TreeNode_t *rotat_Z_3D = create_user_tree_node("rotation axe Z"); add_child_node(rotat_3D, rotat_Z_3D);
|
2024-05-22 09:32:17 +02:00
|
|
|
struct TreeNode_t *relie = create_user_tree_node("part of object"); add_child_node(move_random, relie);
|
|
|
|
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);
|
2024-05-22 21:33:35 +02:00
|
|
|
struct TreeNode_t *regulate = create_user_tree_node("regulate"); add_child_node(tree_root, regulate);
|
|
|
|
struct TreeNode_t *control = create_user_tree_node("negative feedback (control)"); add_child_node(regulate, control);
|
|
|
|
struct TreeNode_t *enhance = create_user_tree_node("positive feedback (enhance)"); add_child_node(regulate, enhance);
|
2024-05-22 09:32:17 +02:00
|
|
|
struct TreeNode_t *no_payload = create_user_tree_node("free"); add_child_node(transport, no_payload);
|
|
|
|
struct TreeNode_t *charged = create_user_tree_node("charged"); add_child_node(transport, charged);
|
|
|
|
struct TreeNode_t *spontaneous = create_user_tree_node("spontaneous"); add_child_node(transform, spontaneous);
|
|
|
|
struct TreeNode_t *catalysed = create_user_tree_node("catalysed"); add_child_node(transform, catalysed);
|
2024-05-22 22:01:08 +02:00
|
|
|
struct TreeNode_t *n_importe = create_user_tree_node("n'importe"); add_child_node(catalysed, n_importe);
|
|
|
|
struct TreeNode_t *quoi = create_user_tree_node("quoi"); add_child_node(n_importe, quoi);
|
|
|
|
struct TreeNode_t *ma_qué = create_user_tree_node("ma_qué"); add_child_node(quoi, ma_qué);
|
2024-05-16 17:29:11 +02:00
|
|
|
|
|
|
|
GtkStringList *model = gtk_string_list_new(NULL);
|
|
|
|
gtk_string_list_append (model, tree_root->text);
|
2024-05-17 09:05:46 +02:00
|
|
|
GtkSignalListItemFactory *factory = GTK_SIGNAL_LIST_ITEM_FACTORY (gtk_signal_list_item_factory_new());
|
2024-05-22 08:59:32 +02:00
|
|
|
g_signal_connect (factory, "setup", G_CALLBACK(on_setup_user_tree_factory), NULL);
|
|
|
|
g_signal_connect (factory, "bind", G_CALLBACK(on_bind_user_tree_factory), NULL);
|
2024-05-22 07:44:50 +02:00
|
|
|
|
2024-05-16 17:29:11 +02:00
|
|
|
GtkTreeListModel *tree_model = gtk_tree_list_model_new(
|
|
|
|
G_LIST_MODEL (model),
|
|
|
|
FALSE, // Passthrough - False in actual usage with dynamic children retrieval
|
2024-05-22 21:33:35 +02:00
|
|
|
TRUE, // FALSE, // autoexpand
|
2024-05-22 08:59:32 +02:00
|
|
|
(GtkTreeListModelCreateModelFunc) &get_user_tree_model,
|
2024-05-16 17:29:11 +02:00
|
|
|
tree_root,
|
2024-05-22 08:59:32 +02:00
|
|
|
NULL // (GDestroyNotify) free_user_tree_node
|
2024-05-16 17:29:11 +02:00
|
|
|
);
|
2024-05-17 09:05:46 +02:00
|
|
|
|
2024-05-16 17:29:11 +02:00
|
|
|
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);
|
2024-05-22 08:10:52 +02:00
|
|
|
GtkWidget *list_view = gtk_list_view_new (GTK_SELECTION_MODEL (selection_model), GTK_LIST_ITEM_FACTORY (factory));
|
2024-05-22 09:32:17 +02:00
|
|
|
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new());
|
2024-05-22 21:33:35 +02:00
|
|
|
// Allocation height too small. Tried to allocate 1922x1030, but GtkNotebook 0x25cd4c0 needs at least 1922x1064.
|
|
|
|
// even if I remove (comment) the next line :
|
|
|
|
gtk_scrolled_window_set_child (scrolled_window, list_view);
|
2024-05-22 09:32:17 +02:00
|
|
|
gtk_scrolled_window_set_policy (scrolled_window, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
2024-05-22 21:33:35 +02:00
|
|
|
gtk_widget_set_vexpand (GTK_WIDGET (scrolled_window), TRUE);
|
|
|
|
gtk_widget_set_visible (GTK_WIDGET (scrolled_window), TRUE);
|
|
|
|
gtk_widget_set_visible (GTK_WIDGET (list_view), TRUE);
|
2024-05-22 09:32:17 +02:00
|
|
|
return scrolled_window;
|
2024-05-15 06:46:11 +02:00
|
|
|
}
|