125 lines
4.9 KiB
C
Executable File
125 lines
4.9 KiB
C
Executable File
#include <gtk/gtk.h>
|
|
|
|
static void print (GtkWidget *widget, gpointer data) {g_print (data);}
|
|
|
|
static void activate (GtkApplication *app, gpointer user_data) {
|
|
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 *button_5 = gtk_button_new_with_label ("V");
|
|
|
|
GtkWidget *window = gtk_application_window_new (app);
|
|
GtkWidget *titlebar = gtk_header_bar_new();
|
|
|
|
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 *grid_3 = gtk_grid_new();
|
|
GtkWidget *box = gtk_box_new (0, 6); // 6 = spacing
|
|
|
|
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_overlay (GTK_WINDOW (window), overlay); // overlay
|
|
gtk_window_set_child (GTK_WINDOW (window), grid);
|
|
|
|
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);
|
|
|
|
// https://developer-old.gnome.org/gtk4/stable/GtkStack.html
|
|
// https://developer.gnome.org/documentation/index.html
|
|
// https://docs.gtk.org/gtk4/enum.AccessibleRole.html
|
|
|
|
// GtkToggleButton *tb1 = GTK_TOGGLE_BUTTON (gtk_button_new_with_label ("tb1"));
|
|
gtk_stack_add_titled (stack, page_1, "n°0", "A");
|
|
gtk_stack_add_titled (stack, page_2, "n°1", "B");
|
|
GtkStackPage *page_3 = gtk_stack_add_titled (stack, grid_3, "n°2", "C");
|
|
gtk_grid_attach (GTK_GRID (grid_3), 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);
|
|
|
|
// gtk_stack_page_get_child (GTK_STACK_PAGE(page_1));
|
|
gtk_stack_page_set_name (GTK_STACK_PAGE(page_3), "new name");
|
|
|
|
GtkSelectionModel *stack_selection_model = gtk_stack_get_pages (stack);
|
|
gtk_selection_model_select_item (stack_selection_model, 2, 1);
|
|
// gtk_stack_set_visible_child_name (stack, "n°3");
|
|
|
|
printf("selected page name is [%s] (can't 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, 3, 2, 1);
|
|
gtk_window_present (GTK_WINDOW (window));
|
|
}
|
|
|
|
int
|
|
main (int argc,
|
|
char **argv)
|
|
{
|
|
GtkApplication *app;
|
|
int status;
|
|
|
|
app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
|
|
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
|
status = g_application_run (G_APPLICATION (app), argc, argv);
|
|
g_object_unref (app);
|
|
|
|
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 ?
|
|
|