From 20537e68e248a799bf485d1e92264166f3dde58e Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Wed, 10 Jan 2024 09:38:58 +0100 Subject: [PATCH] WIP: clean & comment --- include/ui.h | 5 ++- src/ui/bac-a-sable.c | 98 ++++++++++++++++++++++++++++++++++++++++++++ src/ui/tree.c | 76 ++-------------------------------- src/ui/window.c | 8 ++-- 4 files changed, 109 insertions(+), 78 deletions(-) create mode 100644 src/ui/bac-a-sable.c diff --git a/include/ui.h b/include/ui.h index 99fa3f8..627f151 100644 --- a/include/ui.h +++ b/include/ui.h @@ -124,5 +124,6 @@ void ui_toggle_sidebar (); void print_test_in_tree_dot_c(void); -GtkWidget *create_my_list_model(GtkBox *runlib_objects); -GtkWidget *create_a_button(GtkBox *runlib_objects); +GtkWidget *create_my_tree_model(GtkBox *runlib_objects); +GtkWidget *create_my_button_test(GtkBox *runlib_objects); +GtkWidget *create_my_list_view_test(GtkBox *runlib_objects); diff --git a/src/ui/bac-a-sable.c b/src/ui/bac-a-sable.c new file mode 100644 index 0000000..b506e09 --- /dev/null +++ b/src/ui/bac-a-sable.c @@ -0,0 +1,98 @@ +/* + * Gem-graph OpenGL experiments + * + * Desc: User interface functions + * + * Copyright (C) 2023 Jean Sirmai + * + * This file is part of Gem-graph. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#include "../../include/base.h" +#include "../../include/ui.h" + +enum { + FILE_NAME, + FILE_OFFSET, + FILE_SIZE, + FILE_DESCRIPTION, /* Not used by the view, maybe used elsewhere */ + COLOR, /* Just to show how the model can affect the view */ + N_COLUMNS +}; + +GtkWidget *create_my_list_view_test(GtkBox *runlib_objects) +{ + GtkListStore* model; + GtkWidget* view; + GtkTreeViewColumn* column; + GtkWidget* window; + + /* MODEL */ + model = gtk_list_store_new(N_COLUMNS, + G_TYPE_STRING, /* FILE_NAME */ + G_TYPE_UINT, /* FILE_OFFSET */ + G_TYPE_UINT, /* FILE_SIZE */ + G_TYPE_STRING, /* FILE_DESCRIPTION */ + G_TYPE_STRING /* COLOR */ + ); + gtk_list_store_insert_with_values(model, NULL, -1, + FILE_NAME, "test name", + FILE_OFFSET, 0, + FILE_SIZE, 10, + -1); + gtk_list_store_insert_with_values(model, NULL, -1, + FILE_NAME, "Dummy", + FILE_OFFSET, 123, + COLOR, "black", + -1); + gtk_list_store_insert_with_values(model, NULL, -1, + FILE_NAME, "another name", + COLOR, "blue", + -1); + + /* VIEW */ + view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); + g_object_unref(model); + + column = gtk_tree_view_column_new_with_attributes("Name", + gtk_cell_renderer_text_new(), + "text", FILE_NAME, + "background", COLOR, + NULL); + gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); + + column = gtk_tree_view_column_new_with_attributes("Offset", + gtk_cell_renderer_spin_new(), + "text", FILE_OFFSET, + NULL); + gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); + + column = gtk_tree_view_column_new_with_attributes("Size", + gtk_cell_renderer_text_new(), + "text", FILE_SIZE, + NULL); + gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); + + gtk_box_append(runlib_objects, view); + + return 0; +} + + diff --git a/src/ui/tree.c b/src/ui/tree.c index 38d36d1..a770d3e 100644 --- a/src/ui/tree.c +++ b/src/ui/tree.c @@ -83,7 +83,7 @@ static GListStore *create_node_recursive (GListStore *model, return NULL; } -GtkWidget *create_my_list_model(GtkBox *runlib_objects) +GtkWidget *create_my_tree_model(GtkBox *runlib_objects) { GListStore *my_list_model = NULL; GtkWidget *my_tree_box = NULL; @@ -122,8 +122,7 @@ GtkWidget *create_my_list_model(GtkBox *runlib_objects) return my_tree_view; } - -static gint xxx(GtkBox *runlib_objects); +//------------------------------------------------------------------------------ static void print_hello (GtkWidget *widget, @@ -134,7 +133,7 @@ print_hello (GtkWidget *widget, printf("From 'tree.c', > button clicked (n = %d)\n", nb); } -GtkWidget *create_a_button(GtkBox *runlib_objects) +GtkWidget *create_my_button_test(GtkBox *runlib_objects) { GtkWidget *button; const char *text = "Hello ! I'm the new button. Click me !"; @@ -145,76 +144,7 @@ GtkWidget *create_a_button(GtkBox *runlib_objects) g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL); - xxx(runlib_objects); - return button; } -enum { - FILE_NAME, - FILE_OFFSET, - FILE_SIZE, - FILE_DESCRIPTION, /* Not used by the view, maybe used elsewhere */ - COLOR, /* Just to show how the model can affect the view */ - N_COLUMNS -}; - -static gint xxx(GtkBox *runlib_objects) -{ - GtkListStore* model; - GtkWidget* view; - GtkTreeViewColumn* column; - GtkWidget* window; - - /* MODEL */ - model = gtk_list_store_new(N_COLUMNS, - G_TYPE_STRING, /* FILE_NAME */ - G_TYPE_UINT, /* FILE_OFFSET */ - G_TYPE_UINT, /* FILE_SIZE */ - G_TYPE_STRING, /* FILE_DESCRIPTION */ - G_TYPE_STRING /* COLOR */ - ); - gtk_list_store_insert_with_values(model, NULL, -1, - FILE_NAME, "test name", - FILE_OFFSET, 0, - FILE_SIZE, 10, - -1); - gtk_list_store_insert_with_values(model, NULL, -1, - FILE_NAME, "Dummy", - FILE_OFFSET, 123, - COLOR, "black", - -1); - gtk_list_store_insert_with_values(model, NULL, -1, - FILE_NAME, "another name", - COLOR, "blue", - -1); - - /* VIEW */ - view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); - g_object_unref(model); - - column = gtk_tree_view_column_new_with_attributes("Name", - gtk_cell_renderer_text_new(), - "text", FILE_NAME, - "background", COLOR, - NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); - - column = gtk_tree_view_column_new_with_attributes("Offset", - gtk_cell_renderer_spin_new(), - "text", FILE_OFFSET, - NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); - - column = gtk_tree_view_column_new_with_attributes("Size", - gtk_cell_renderer_text_new(), - "text", FILE_SIZE, - NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(view), column); - - gtk_box_append(runlib_objects, view); - - return 0; -} - // guix shell -m manifest.scm make clean && clear && time make run diff --git a/src/ui/window.c b/src/ui/window.c index 24adc2a..7137c96 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -50,6 +50,7 @@ float rotation_angles[N_AXIS] = { 0.0 }; // Rotation angles on each axis GtkWidget *gl_area = NULL; GtkWidget *my_tree = NULL; GtkWidget *my_button = NULL; +GtkWidget *my_list = NULL; GemGraphClientWindow *window; @@ -121,7 +122,7 @@ static void gem_graph_client_window_init(GemGraphClientWindow *self) //XXX TEMP ui_setup_glarea(window->run_glarea, window->run_controls); // printf("--------------------------------------------------------------------------------------\n\ -from : gem_graph_client_window_init(GemGraphClientWindow *self) in window.c (line 123)\n\ +from : gem_graph_client_window_init(GemGraphClientWindow *self) in window.c (line 124)\n\ > widgets examples in user/jean/01/GTK4/tree (learning)/The_Gnome_way/demos/gtk-demo <\n\ --------------------------------------------------------------------------------------\n"); @@ -149,8 +150,9 @@ void ui_set_stack(const char *mode) break; case 'r': gtk_menu_button_set_icon_name(window->main_button_mode, "system-run-symbolic"); - if (! my_tree) my_tree = create_my_list_model(window->runlib_objects); - if (! my_button) my_button = create_a_button(window->runlib_objects); + if (! my_tree) my_tree = create_my_tree_model(window->runlib_objects); // in tree.c + if (! my_button) my_button = create_my_button_test(window->runlib_objects); // in tree.c + if (! my_list) my_list = create_my_list_view_test(window->runlib_objects); // in "bac-a-sable.c" break; case 'p': gtk_menu_button_set_icon_name(window->main_button_mode, "x-office-presentation-symbolic");