This commit is contained in:
Jean Sirmai 2024-04-26 19:40:19 +02:00
parent a9444597dc
commit 80603caff0
Signed by: jean
GPG Key ID: FB3115C340E057E3
5 changed files with 150 additions and 42 deletions

View File

@ -1,4 +1,9 @@
all: Getting_Started_with_GTK
SHELL = /bin/sh
.SUFFIXES:
.SUFFIXES: .c .o
.PHONY = run
.PHONY = clean
.PHONY: Makefile
CC=gcc
@ -7,20 +12,74 @@ WARNINGS = -Wall
DEBUG = -ggdb -fno-omit-frame-pointer
OPTIMIZE = -O2
all:
exec
Getting_Started_with_GTK: main.c
exec.o: main.c Makefile
$(CC) $(CFLAGS) $(WARNINGS) $(DEBUG) $(OPTIMIZE) -o $@ main.c
clean:
rm -f Getting_Started_with_GTK
rm -f exec
rm -f exec.o
# Builder will call this to install the application before running.
install:
echo "Installing is not supported"
# Builder uses this target to run your application.
run:
./exec
run: exec.o
./exec.o
# gcc $( pkg-config --cflags gtk4 ) -o exec main.c $( pkg-config --libs gtk4 )
# https://www.gnu.org/software/make/manual/
# Makefiles contain five kinds of things:
# explicit rules, implicit rules, variable definitions, directives and comments.
# Variables automatiques --------------------------------------------------
# $@ fait référence à la cible de la règle (au nom de la cible).
# $< fait référence à la première dépendance.
# $? fait référence aux noms de touess les dépendances plus récentes que la cible.
# = les fichiers qui ont été modifiés après la compilation de code la plus récente
# $^ fait référence aux noms de touess les dépendances avec des espaces entre eux.
# Variables implicites -------------------------------------------------
# VPATH Équivalent utilitaire de la variable PATH de Bash. Vide par défaut.
# Les chemins sont séparés par le signe deux-points (:).
# CC Le programme pour compiler des fichiers C.
# La valeur par défaut est cc. (Habituellement, cc pointe vers gcc.)
# CPP Le programme qui exécute le préprocesseur C.
# La valeur par défaut est $ (CC) -E.
# LEX Le programme qui transforme les grammaires lexicales en code source.
# La valeur par défaut est lex. (Vous devriez remplacer cela par flex.)
# LINT Le programme qui lint votre code source. La valeur par défaut est lint.
# RM La commande pour supprimer un fichier. La valeur par défaut est rm -f.
# CFLAGS Contient tous les indicateurs du compilateur C (cc).
# CPPFLAGS tous les indicateurs du préprocesseur C.
# .PHONY Spécifie des cibles qui ne ressemblent pas au nom d'un fichier.
# Un exemple est la cible "make clean" ; où clean est une valeur de .PHONY
# Syntaxe de Base
# Règles : Une règle se compose d'une cible, des dépendances et des commandes.
# Elle est généralement structurée comme suit :
# cible: dépendances
# commande
#
# La cible (target) est le fichier à générer,
# les dépendances (prerequisites) sont les fichiers requis pour construire la cible
# et les commandes (recipe) sont les instructions exécutées pour créer la cible.
#
# A simple makefile consists of “rules” with the following shape:
# target ... : prerequisites ...
# recipe
# ...
# A target is usually the name of a file that is generated by a program;
# examples of targets are executable or object files.
# A target can also be the name of an action to carry out, such as clean
# https://blog.stephane-robert.info/docs/makefile/
# https://blog.stephane-robert.info/docs/task/
// gcc $( pkg-config --cflags gtk4 ) -o exec main.c $( pkg-config --libs gtk4 )

BIN
exec

Binary file not shown.

BIN
exec.o Executable file

Binary file not shown.

119
main.c
View File

@ -1,50 +1,69 @@
/* GtkBox GtkGrid GtkRevealer GtkStack
* GtkOverlay GtkPaned GtkExpander GtkFixed */
/* box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
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);
puis, après déclaration du bouton, 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 */
#include <gtk/gtk.h>
static void print (GtkWidget *widget, gpointer data) {g_print (data);}
static void activate (GtkApplication *app, gpointer user_data) {
GtkWidget *window;
GtkWidget *grid;
GtkWidget *button;
GtkHeaderBar *titlebar;
GtkWidget *button_0 = gtk_button_new_with_label ("Quit");
GtkWidget *button_1 = gtk_button_new_with_label ("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 *window = gtk_application_window_new (app);
GtkWidget *titlebar = gtk_header_bar_new();
// 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)));
GtkWidget *switcher = gtk_stack_switcher_new();
// GtkWidget *sidebar = gtk_stack_sidebar_new();
GtkStack *stack = GTK_STACK (gtk_stack_new());
GtkWidget *page_1 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
GtkWidget *page_2 = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
GtkWidget *grid = gtk_grid_new();
GtkWidget *box = gtk_box_new (0, 6); // 6 = spacing
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_widget_set_size_request (GTK_WINDOW (window), 100, 0);
titlebar = gtk_header_bar_new();
gtk_window_set_titlebar (GTK_WINDOW (window), titlebar);
grid = gtk_grid_new ();
gtk_widget_set_size_request (window, 60, 0);
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);
button = gtk_button_new_with_label ("I");
g_signal_connect (button, "clicked", G_CALLBACK (print), "I'm n°1\n");
gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1);
g_signal_connect (button_1, "clicked", G_CALLBACK (print), "I'm n°1\n");
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");
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);
gtk_grid_attach (GTK_GRID (grid), button_0, 0, 1, 2, 1);
gtk_box_append (GTK_BOX (box), button_3);
gtk_box_append (GTK_BOX (box), button_4);
gtk_grid_attach (GTK_GRID (grid), box, 0, 2, 2, 1);
button = gtk_button_new_with_label ("II");
g_signal_connect (button, "clicked", G_CALLBACK (print), "I'm n°2\n");
gtk_grid_attach (GTK_GRID (grid), button, 1, 0, 1, 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
button = gtk_button_new_with_label ("Quit");
g_signal_connect (button, "clicked", G_CALLBACK (print), "bye !...\n");
g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_window_destroy), window);
gtk_grid_attach (GTK_GRID (grid), button, 0, 1, 2, 1);
// GtkToggleButton *tb1 = GTK_TOGGLE_BUTTON (gtk_button_new_with_label ("tb1"));
gtk_stack_add_titled (stack, page_1, "name 1", "page A");
gtk_stack_add_titled (stack, page_2, "name 2", "page B");
gtk_orientable_set_orientation (GTK_ORIENTABLE (switcher), GTK_ORIENTATION_HORIZONTAL);
gtk_orientable_set_orientation (GTK_ORIENTABLE (switcher), GTK_ORIENTATION_VERTICAL);
gtk_stack_switcher_set_stack (GTK_STACK_SWITCHER (switcher), stack);
// gtk_stack_sidebar_set_stack (GTK_STACK_SIDEBAR (sidebar), stack);
gtk_stack_page_get_child (GTK_STACK_PAGE(page_1));
// gtk_stack_page_set_name (GTK_STACK_PAGE(page_1), "new name");
gtk_stack_set_visible_child_name (stack, "name 1");
printf("visible is page [%s] with name (%s)\n",
"?", // gtk_stack_page_get_title (GTK_STACK_PAGE(page_1)),
gtk_stack_get_visible_child_name (stack));
// gtk_stack_page_get_title (GTK_STACK_PAGE(page_1)));
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_window_present (GTK_WINDOW (window));
}
@ -63,3 +82,33 @@ main (int argc,
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);
*
*/