ébauche de structuration

This commit is contained in:
Jean Sirmai 2024-04-27 14:59:32 +02:00
parent 6a2f0fd2ca
commit f10b52e7dd
Signed by: jean
GPG Key ID: FB3115C340E057E3
4 changed files with 18 additions and 48 deletions

View File

@ -15,20 +15,22 @@ OPTIMIZE = -O2
all: all:
exec exec
exec.o: main.c Makefile exec.o:
$(CC) $(CFLAGS) $(WARNINGS) $(DEBUG) $(OPTIMIZE) -o $@ main.c $(CC) $(CFLAGS) $(WARNINGS) $(DEBUG) $(OPTIMIZE) warm.c -o $@ main.c
clean: clean:
rm -f exec.o rm -f exec.o
# Builder will call this to install the application before running.
install: install:
echo "Installing is not supported" echo "Installing is not supported"
# Builder uses this target to run your application. run:
run: exec.o
./exec.o ./exec.o
# gcc $( pkg-config --cflags gtk4 ) -o exec main.c $( pkg-config --libs gtk4 ) # gcc $( pkg-config --cflags gtk4 ) -o exec main.c $( pkg-config --libs gtk4 )
# https://www.gnu.org/software/make/manual/ # https://www.gnu.org/software/make/manual/
@ -79,7 +81,5 @@ run: exec.o
# A target can also be the name of an action to carry out, such as clean # A target can also be the name of an action to carry out, such as clean
# accessoirement : https://blog.stephane-robert.info/docs/makefile/ & /docs/task/
# https://blog.stephane-robert.info/docs/makefile/
# https://blog.stephane-robert.info/docs/task/

BIN
exec.o

Binary file not shown.

42
main.c
View File

@ -1,66 +1,36 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "./warm.h" #include "warm.h"
static void print (GtkWidget *widget, gpointer data) {g_print (data);}
static void activate (GtkApplication *app, gpointer user_data) { static void activate (GtkApplication *app, gpointer user_data) {
GtkWidget *button_0 = gtk_button_new_with_label ("Quit"); GtkWidget *button_0 = gtk_button_new_with_label ("Quit");
GtkWidget *button_1 = gtk_button_new_with_label ("I"); GtkWidget *button_1 = gtk_button_new_with_label ("bouton (I)");
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");
char *text = "niofnein";
printf("in main.c : %s\n", text);
// print_text(text);
GtkWidget *window = gtk_application_window_new (app); GtkWidget *window = gtk_application_window_new (app);
GtkWidget *titlebar = gtk_header_bar_new(); GtkWidget *titlebar = gtk_header_bar_new();
GtkWidget *switcher = gtk_stack_switcher_new(); GtkWidget *switcher = gtk_stack_switcher_new();
// GtkWidget *sidebar = gtk_stack_sidebar_new(); // GtkWidget *sidebar = gtk_stack_sidebar_new();
GtkStack *stack = GTK_STACK (gtk_stack_new()); GtkStack *stack = GTK_STACK (gtk_stack_new());
GtkWidget *page_0 = gtk_paned_new(GTK_ORIENTATION_VERTICAL); GtkWidget *page_0 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
GtkWidget *page_1 = gtk_paned_new(GTK_ORIENTATION_VERTICAL); GtkWidget *page_1 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
GtkWidget *grid = gtk_grid_new(); GtkWidget *grid = gtk_grid_new();
// GtkWidget *grid_1 = gtk_grid_new();
GtkWidget *box = gtk_box_new (0, 6); // 6 = spacing
GtkWidget *box_1 = gtk_box_new (0, 6); // 6 = spacing GtkWidget *box_1 = gtk_box_new (0, 6); // 6 = spacing
gtk_window_set_title (GTK_WINDOW (window), "Window"); gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_widget_set_size_request (window, 60, 0);
gtk_window_set_titlebar (GTK_WINDOW (window), titlebar); // header_bar gtk_window_set_titlebar (GTK_WINDOW (window), titlebar); // header_bar
// gtk_window_set_overlay (GTK_WINDOW (window), overlay); // overlay
gtk_window_set_child (GTK_WINDOW (window), grid); gtk_window_set_child (GTK_WINDOW (window), grid);
g_signal_connect (button_1, "clicked", G_CALLBACK (print), "I'm n°1\n"); g_signal_connect (button_1, "clicked", G_CALLBACK (print_text), "n°1\n");
gtk_grid_attach (GTK_GRID (grid), button_1, 0, 0, 1, 1); gtk_grid_attach (GTK_GRID (grid), button_1, 0, 0, 1, 1);
g_signal_connect (button_2, "clicked", G_CALLBACK (print), "I'm n°2\n"); g_signal_connect (button_0, "clicked", G_CALLBACK (print_text), "bye !...\n");
gtk_grid_attach (GTK_GRID (grid), button_2, 1, 0, 1, 1);
g_signal_connect (button_0, "clicked", G_CALLBACK (print), "bye !...\n");
g_signal_connect_swapped (button_0, "clicked", G_CALLBACK (gtk_window_destroy), window); g_signal_connect_swapped (button_0, "clicked", G_CALLBACK (gtk_window_destroy), window);
gtk_grid_attach (GTK_GRID (grid), button_0, 0, 1, 2, 1); gtk_grid_attach (GTK_GRID (grid), button_0, 1, 0, 1, 1);
gtk_box_append (GTK_BOX (box), button_3);
gtk_box_append (GTK_BOX (box), button_4);
gtk_box_append (GTK_BOX (box_1), button_5);
gtk_grid_attach (GTK_GRID (grid), box, 0, 2, 2, 1);
// https://developer-old.gnome.org/gtk4/stable/GtkStack.html
// https://developer.gnome.org/documentation/index.html
// https://docs.gtk.org/gtk4/enum.AccessibleRole.html
gtk_stack_add_titled (stack, page_0, "n°0", "A"); gtk_stack_add_titled (stack, page_0, "n°0", "A");
gtk_stack_add_titled (stack, page_1, "n°1", "B"); gtk_stack_add_titled (stack, page_1, "n°1", "B");
GtkStackPage *page_2 = gtk_stack_add_titled (stack, box_1, "any name", "C"); GtkStackPage *page_2 = gtk_stack_add_titled (stack, box_1, "any name", "C");
gtk_stack_page_set_name (page_2, "n°2"); gtk_stack_page_set_name (page_2, "n°2");
// gtk_grid_attach (GTK_GRID (grid_1), button_5, 0, 0, 1, 1); // 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_VERTICAL);
gtk_orientable_set_orientation (GTK_ORIENTABLE (switcher), GTK_ORIENTATION_HORIZONTAL); gtk_orientable_set_orientation (GTK_ORIENTABLE (switcher), GTK_ORIENTATION_HORIZONTAL);
@ -74,7 +44,7 @@ static void activate (GtkApplication *app, gpointer user_data) {
gtk_stack_get_visible_child_name (stack)); gtk_stack_get_visible_child_name (stack));
// gtk_stack_set_transition_type (GTK_STACK (stack), GTK_STACK_TRANSITION_TYPE_CROSSFADE); // gtk_stack_set_transition_type (GTK_STACK (stack), GTK_STACK_TRANSITION_TYPE_CROSSFADE);
gtk_grid_attach (GTK_GRID (grid), switcher, 0, 3, 2, 1); gtk_grid_attach (GTK_GRID (grid), switcher, 0, 2, 2, 1);
gtk_window_present (GTK_WINDOW (window)); gtk_window_present (GTK_WINDOW (window));
} }

8
warm.c
View File

@ -1,15 +1,15 @@
#pragma once //#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>
button_0 = gtk_button_new_with_label ("Quit"); /* button_0 = gtk_button_new_with_label ("Quit");
GtkWidget *button_1 = gtk_button_new_with_label ("I"); GtkWidget *button_1 = gtk_button_new_with_label ("I");
GtkWidget *button_2 = gtk_button_new_with_label ("II"); GtkWidget *button_2 = gtk_button_new_with_label ("II");
GtkWidget *button_3 = gtk_button_new_with_label ("III"); GtkWidget *button_3 = gtk_button_new_with_label ("III");
GtkWidget *button_4 = gtk_button_new_with_label ("IV"); GtkWidget *button_4 = gtk_button_new_with_label ("IV");
GtkWidget *button_5 = gtk_button_new_with_label ("V"); GtkWidget *button_5 = gtk_button_new_with_label ("V");*/
// GtkToggleButton *tb1 = GTK_TOGGLE_BUTTON (gtk_button_new_with_label ("tb1")); // GtkToggleButton *tb1 = GTK_TOGGLE_BUTTON (gtk_button_new_with_label ("tb1"));
void print_text(char *text) {printf("in warm.c : %s\n", text);} void print_text(GtkWidget *widget, gpointer data) {g_print (data);}