]> Pileus Git - ~andy/gtk/blob - examples/grid-packing.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / examples / grid-packing.c
1 #include <gtk/gtk.h>
2
3 static void
4 print_hello (GtkWidget *widget,
5              gpointer   data)
6 {
7   g_print ("Hello World\n");
8 }
9
10 int
11 main (int   argc,
12       char *argv[])
13 {
14   GtkWidget *window;
15   GtkWidget *grid;
16   GtkWidget *button;
17
18   /* This is called in all GTK applications. Arguments are parsed
19    * from the command line and are returned to the application.
20    */
21   gtk_init (&argc, &argv);
22
23   /* create a new window, and set its title */
24   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
25   gtk_window_set_title (GTK_WINDOW (window), "Grid");
26   g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
27   gtk_container_set_border_width (GTK_CONTAINER (window), 10);
28
29   /* Here we construct the container that is going pack our buttons */
30   grid = gtk_grid_new ();
31
32   /* Pack the container in the window */
33   gtk_container_add (GTK_CONTAINER (window), grid);
34
35   button = gtk_button_new_with_label ("Button 1");
36   g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
37
38   /* Place the first button in the grid cell (0, 0), and make it fill
39    * just 1 cell horizontally and vertically (ie no spanning)
40    */
41   gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1);
42
43   button = gtk_button_new_with_label ("Button 2");
44   g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
45
46   /* Place the second button in the grid cell (1, 0), and make it fill
47    * just 1 cell horizontally and vertically (ie no spanning)
48    */
49   gtk_grid_attach (GTK_GRID (grid), button, 1, 0, 1, 1);
50
51   button = gtk_button_new_with_label ("Quit");
52   g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
53
54   /* Place the Quit button in the grid cell (0, 1), and make it
55    * span 2 columns.
56    */
57   gtk_grid_attach (GTK_GRID (grid), button, 0, 1, 2, 1);
58
59   /* Now that we are done packing our widgets, we show them all
60    * in one go, by calling gtk_widget_show_all() on the window.
61    * This call recursively calls gtk_widget_show() on all widgets
62    * that are contained in the window, directly or indirectly.
63    */
64   gtk_widget_show_all (window);
65
66   /* All GTK applications must have a gtk_main(). Control ends here
67    * and waits for an event to occur (like a key press or a mouse event),
68    * until gtk_main_quit() is called.
69    */
70   gtk_main ();
71
72   return 0;
73 }