This commit is contained in:
Jean Sirmai 2024-04-28 08:38:55 +02:00
parent a65f586892
commit 40cde41b69
Signed by: jean
GPG Key ID: FB3115C340E057E3
7 changed files with 91 additions and 113 deletions

53
cold.c
View File

@ -3,17 +3,13 @@
void print_text(GtkWidget *widget, gpointer data) {g_print (data);} void print_text(GtkWidget *widget, gpointer data) {g_print (data);}
void button_0(GtkWindow *window, GtkWidget *grid, int x, int y, int w, int h){ void click_print_do (GtkWindow *window, GtkWidget *grid,
GtkWidget *button_0 = gtk_button_new_with_label ("Quit"); char *label, char *text, int x, int y, int w, int h){
g_signal_connect (button_0, "clicked", G_CALLBACK (print_text), "bye !...\n"); GtkWidget *button = gtk_button_new_with_label (label);
g_signal_connect_swapped (button_0, "clicked", G_CALLBACK (gtk_window_destroy), window); gtk_grid_attach (GTK_GRID (grid), button, x, y, w, h);
gtk_grid_attach (GTK_GRID (grid), button_0, x, y, w, h); g_signal_connect (button, "clicked", G_CALLBACK (print_text), text);
} if (window)
g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_window_destroy), window);
void button_1(GtkWidget *grid, int x, int y, int w, int h){
GtkWidget *button_1 = gtk_button_new_with_label ("bouton (I)");
g_signal_connect (button_1, "clicked", G_CALLBACK (print_text), "n°1\n");
gtk_grid_attach (GTK_GRID (grid), button_1, x, y, w, h);
} }
void window_bar(GtkWindow *window, char *title){ void window_bar(GtkWindow *window, char *title){
@ -27,3 +23,38 @@ void window_grid(GtkWindow *window){
gtk_window_set_child (window, grid); gtk_window_set_child (window, grid);
} }
/*----------------------------------------------------------------------------*/
/* GtkBox GtkGrid GtkRevealer GtkStack
* GtkOverlay GtkPaned GtkExpander GtkFixed */
/* GtkBox
* int spacing = 8;
* box = gtk_box_new (0, spacing);
* 0 = GTK_ORIENTATION_HORIZONTAL, 1 = GTK_ORIENTATION_VERTICAL
* gtk_widget_set_halign (box, GTK_ALIGN_FILL);
* gtk_widget_set_valign (box, GTK_ALIGN_CENTER); * START CENTER END FILL *
* gtk_window_set_child (GTK_WINDOW (window), box);
* gtk_box_append (GTK_BOX (box), button); */
/* grid = gtk_grid_new ();
gtk_window_set_child (GTK_WINDOW (window), grid);
button = gtk_button_new_with_label (" I "); n fois
gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1); n fois */
/* TODO or NOT TODO
*
* GtkRevealer *revealer = gtk_revealer_new();
* gtk_revealer_set_child (GTK_ ? (revealer), box);
* gtk_revealer_set_transition_type (revealer, GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
*
*/
// GtkWidget *overlay = gtk_overlay_new();
// gtk_overlay_set_buildable_id (GTK_BUILDABLE(overlay), "overlay id");
// printf("overlay %s\n", gtk_buildable_get_buildable_id (GTK_BUILDABLE(overlay)));
// how do I attach a widget to a page ?

11
cold.h
View File

@ -2,15 +2,8 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
void print_text(GtkWidget *widget, gpointer data); void print_text(GtkWidget *widget, gpointer data);
void button_0(GtkWindow *window, GtkWidget *grid, int x, int y, int w, int h); void click_print_do (GtkWindow *window, GtkWidget *grid,
void button_1(GtkWidget *grid, int x, int y, int w, int h); char *label, char *text, int x, int y, int w, int h);
void window_bar(GtkWindow *window, char *title); void window_bar(GtkWindow *window, char *title);
void window_grid(GtkWindow *window); void window_grid(GtkWindow *window);
/*
GtkWidget *button_2 = gtk_button_new_with_label ("II");
GtkWidget *button_3 = gtk_button_new_with_label ("III");
GtkWidget *button_4 = gtk_button_new_with_label ("IV");
GtkWidget *button_5 = gtk_button_new_with_label ("V");
*/
// GtkToggleButton *tb1 = GTK_TOGGLE_BUTTON (gtk_button_new_with_label ("tb1"));

BIN
exec.o

Binary file not shown.

45
hot.h
View File

@ -1,3 +1,48 @@
#include <stdio.h> #include <stdio.h>
#include <gtk-4.0/gtk/gtk.h> #include <gtk-4.0/gtk/gtk.h>
#include "warm.h"
#include "cold.h"
void activate (GtkApplication *app, gpointer user_data) {
GtkWindow *window = GTK_WINDOW (gtk_application_window_new (app));
GtkWidget *grid = gtk_grid_new();
click_print_do (NULL, grid, "(I)", "n°1\n", 0,0,1,1);
click_print_do (NULL, grid, "(II)", "n°2\n", 1,0,1,1);
click_print_do (window, grid, "Quit", "bye !...\n", 2,0,1,2);
GtkWidget *switcher = gtk_stack_switcher_new();
// GtkWidget *sidebar = gtk_stack_sidebar_new();
GtkStack *stack = GTK_STACK (gtk_stack_new());
GtkWidget *page_0 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
GtkWidget *page_1 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
GtkWidget *box_1 = gtk_box_new (0, 6); // 6 = spacing
window_bar (window, "window");
gtk_window_set_child (window, grid);
gtk_stack_add_titled (stack, page_0, "n°0", "A");
gtk_stack_add_titled (stack, page_1, "n°1", "B");
GtkStackPage *page_2 = gtk_stack_add_titled (stack, box_1, "any name", "C");
gtk_stack_page_set_name (page_2, "n°2");
// gtk_grid_attach (GTK_GRID (grid_1), button_5, 0, 0, 1, 1);
gtk_orientable_set_orientation (GTK_ORIENTABLE (switcher), GTK_ORIENTATION_VERTICAL);
gtk_orientable_set_orientation (GTK_ORIENTABLE (switcher), GTK_ORIENTATION_HORIZONTAL);
gtk_stack_switcher_set_stack (GTK_STACK_SWITCHER (switcher), stack);
// gtk_stack_sidebar_set_stack (GTK_STACK_SIDEBAR (sidebar), stack);
GtkSelectionModel *stack_selection_model = gtk_stack_get_pages (stack);
gtk_selection_model_select_item (stack_selection_model, 2, 1);
printf("selected page name is [%s] (how do I get its title ?)\n",
gtk_stack_get_visible_child_name (stack));
// gtk_stack_set_transition_type (GTK_STACK (stack), GTK_STACK_TRANSITION_TYPE_CROSSFADE);
gtk_grid_attach (GTK_GRID (grid), switcher, 0, 2, 2, 1);
gtk_window_present (GTK_WINDOW (window));
}

83
main.c
View File

@ -1,51 +1,6 @@
#include <gtk/gtk.h>
#include "hot.h" #include "hot.h"
#include "warm.h"
#include "cold.h"
int main (int argc, char **argv)
static void activate (GtkApplication *app, gpointer user_data) {
GtkWindow *window = GTK_WINDOW (gtk_application_window_new (app));
GtkWidget *switcher = gtk_stack_switcher_new();
// GtkWidget *sidebar = gtk_stack_sidebar_new();
GtkStack *stack = GTK_STACK (gtk_stack_new());
GtkWidget *page_0 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
GtkWidget *page_1 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
GtkWidget *grid = gtk_grid_new();
GtkWidget *box_1 = gtk_box_new (0, 6); // 6 = spacing
window_bar (window, "window");
gtk_window_set_child (window, grid);
button_0 (window, grid, 1,0,1,1);
button_1 (grid, 0,0,1,1);
gtk_stack_add_titled (stack, page_0, "n°0", "A");
gtk_stack_add_titled (stack, page_1, "n°1", "B");
GtkStackPage *page_2 = gtk_stack_add_titled (stack, box_1, "any name", "C");
gtk_stack_page_set_name (page_2, "n°2");
// gtk_grid_attach (GTK_GRID (grid_1), button_5, 0, 0, 1, 1);
gtk_orientable_set_orientation (GTK_ORIENTABLE (switcher), GTK_ORIENTATION_VERTICAL);
gtk_orientable_set_orientation (GTK_ORIENTABLE (switcher), GTK_ORIENTATION_HORIZONTAL);
gtk_stack_switcher_set_stack (GTK_STACK_SWITCHER (switcher), stack);
// gtk_stack_sidebar_set_stack (GTK_STACK_SIDEBAR (sidebar), stack);
GtkSelectionModel *stack_selection_model = gtk_stack_get_pages (stack);
gtk_selection_model_select_item (stack_selection_model, 2, 1);
printf("selected page name is [%s] (how do I get its title ?)\n",
gtk_stack_get_visible_child_name (stack));
// gtk_stack_set_transition_type (GTK_STACK (stack), GTK_STACK_TRANSITION_TYPE_CROSSFADE);
gtk_grid_attach (GTK_GRID (grid), switcher, 0, 2, 2, 1);
gtk_window_present (GTK_WINDOW (window));
}
int
main (int argc,
char **argv)
{ {
GtkApplication *app; GtkApplication *app;
int status; int status;
@ -57,39 +12,3 @@ main (int argc,
return status; return status;
} }
/* GtkBox GtkGrid GtkRevealer GtkStack
* GtkOverlay GtkPaned GtkExpander GtkFixed */
/* GtkBox
* int spacing = 8;
* box = gtk_box_new (0, spacing);
* 0 = GTK_ORIENTATION_HORIZONTAL, 1 = GTK_ORIENTATION_VERTICAL
* gtk_widget_set_halign (box, GTK_ALIGN_FILL);
* gtk_widget_set_valign (box, GTK_ALIGN_CENTER); * START CENTER END FILL *
* gtk_window_set_child (GTK_WINDOW (window), box);
* gtk_box_append (GTK_BOX (box), button); */
/* grid = gtk_grid_new ();
gtk_window_set_child (GTK_WINDOW (window), grid);
button = gtk_button_new_with_label (" I "); n fois
gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1); n fois */
/* TODO or NOT TODO
*
* GtkRevealer *revealer = gtk_revealer_new();
* gtk_revealer_set_child (GTK_ ? (revealer), box);
* gtk_revealer_set_transition_type (revealer, GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
*
*/
// GtkWidget *overlay = gtk_overlay_new();
// gtk_overlay_set_buildable_id (GTK_BUILDABLE(overlay), "overlay id");
// printf("overlay %s\n", gtk_buildable_get_buildable_id (GTK_BUILDABLE(overlay)));
// how do I attach a widget to a page ?

1
warm.c
View File

@ -1,4 +1,3 @@
//#pragma once
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <gtk-4.0/gtk/gtk.h> #include <gtk-4.0/gtk/gtk.h>

11
warm.h
View File

@ -12,14 +12,5 @@
#include <unistd.h> #include <unistd.h>
#include <glib-2.0/glib.h> #include <glib-2.0/glib.h>
#include <gtk-4.0/gtk/gtk.h> #include <gtk-4.0/gtk/gtk.h>
#include "cold.h"
/*
extern GtkWidget *button_0;
extern GtkWidget *button_1;
extern GtkWidget *button_2;
extern GtkWidget *button_3;
extern GtkWidget *button_4;
extern GtkWidget *button_5;
void print_text(char *text);
*/