]> git.datanom.net - enfusegtk.git/blame - src/main.c
Basic
[enfusegtk.git] / src / main.c
CommitLineData
85dffabd
MR
1#include <gtk/gtk.h>
2
3static void
4print_hello (GtkWidget *widget,
5 gpointer data)
6{
7 gchar* msg = (gchar*) data;
8
9 g_print ("%s\n", msg);
10}
11
12static void
13activate (GtkApplication *app,
14 gpointer user_data)
15{
16 GtkWidget *window;
17 GtkWidget *grid;
18 GtkWidget *button;
19
20 /* create a new window, and set its title */
21 window = gtk_application_window_new (app);
22 gtk_window_set_title (GTK_WINDOW (window), "Window");
23 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
24
25 /* Here we construct the container that is going pack our buttons */
26 grid = gtk_grid_new ();
27
28 /* Pack the container in the window */
29 gtk_container_add (GTK_CONTAINER (window), grid);
30
31 button = gtk_button_new_with_label ("Button 1");
32 g_signal_connect (button, "clicked", G_CALLBACK (print_hello), "Hello World #1");
33
34 /* Place the first button in the grid cell (0, 0), and make it fill
35 * just 1 cell horizontally and vertically (ie no spanning)
36 */
37 gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1);
38
39 button = gtk_button_new_with_label ("Button 2");
40 g_signal_connect (button, "clicked", G_CALLBACK (print_hello), "Hello World #2");
41
42 /* Place the second button in the grid cell (1, 0), and make it fill
43 * just 1 cell horizontally and vertically (ie no spanning)
44 */
45 gtk_grid_attach (GTK_GRID (grid), button, 1, 0, 1, 1);
46
47 button = gtk_button_new_with_label ("Quit");
48 g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
49
50 /* Place the Quit button in the grid cell (0, 1), and make it
51 * span 2 columns.
52 */
53 gtk_grid_attach (GTK_GRID (grid), button, 0, 1, 2, 1);
54
55 /* Now that we are done packing our widgets, we show them all
56 * in one go, by calling gtk_widget_show_all() on the window.
57 * This call recursively calls gtk_widget_show() on all widgets
58 * that are contained in the window, directly or indirectly.
59 */
60 gtk_widget_show_all (window);
61
62}
63
64int
65main (int argc,
66 char **argv)
67{
68 GtkApplication *app;
69 int status;
70
71 app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
72 g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
73 status = g_application_run (G_APPLICATION (app), argc, argv);
74 g_object_unref (app);
75
76 return status;
77}
78
This page took 0.054191 seconds and 5 git commands to generate.