summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2011-01-20 01:30:34 -0500
committerMatthias Clasen <mclasen@redhat.com>2011-01-20 01:30:34 -0500
commitb29af18a268d595f84d0904ea97c67d03e2b984b (patch)
treea692adba61d5ad5c316bb192ad71885447a83e96 /examples
parent99812be7d70ddffc825ed031ea29435b0466a4bf (diff)
downloadgtk+-b29af18a268d595f84d0904ea97c67d03e2b984b.tar.gz
Add a GtkBuilder section to the tutorial
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am5
-rw-r--r--examples/builder.c40
-rw-r--r--examples/builder.ui45
3 files changed, 89 insertions, 1 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 440197fd0e..25539e12ee 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -56,4 +56,7 @@ noinst_PROGRAMS = \
window-default \
bloatpad \
grid-packing \
- drawing
+ drawing \
+ builder
+
+EXTRA_DIST = builder.ui
diff --git a/examples/builder.c b/examples/builder.c
new file mode 100644
index 0000000000..a05646fdbe
--- /dev/null
+++ b/examples/builder.c
@@ -0,0 +1,40 @@
+#include <gtk/gtk.h>
+
+static void
+print_hello (GtkWidget *widget,
+ gpointer data)
+{
+ g_print ("Hello World\n");
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ GtkBuilder *builder;
+ GObject *window;
+ GObject *button;
+
+ gtk_init (&argc, &argv);
+
+ /* Construct a GtkBuilder instance and load our UI description */
+ builder = gtk_builder_new ();
+ gtk_builder_add_from_file (builder, "builder.ui", NULL);
+
+ /* Connect signal handlers to the constructed widgets. */
+ window = gtk_builder_get_object (builder, "window");
+ g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
+
+ button = gtk_builder_get_object (builder, "button1");
+ g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
+
+ button = gtk_builder_get_object (builder, "button2");
+ g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
+
+ button = gtk_builder_get_object (builder, "quit");
+ g_signal_connect (button, "clicked", G_CALLBACK (gtk_main_quit), NULL);
+
+ gtk_main ();
+
+ return 0;
+}
diff --git a/examples/builder.ui b/examples/builder.ui
new file mode 100644
index 0000000000..6321c93ca0
--- /dev/null
+++ b/examples/builder.ui
@@ -0,0 +1,45 @@
+<interface>
+ <object id="window" class="GtkWindow">
+ <property name="visible">True</property>
+ <property name="title">Grid</property>
+ <property name="border-width">10</property>
+ <child>
+ <object id="grid" class="GtkGrid">
+ <property name="visible">True</property>
+ <child>
+ <object id="button1" class="GtkButton">
+ <property name="visible">True</property>
+ <property name="label">Button 1</property>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object id="button2" class="GtkButton">
+ <property name="visible">True</property>
+ <property name="label">Button 2</property>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object id="quit" class="GtkButton">
+ <property name="visible">True</property>
+ <property name="label">Quit</property>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">1</property>
+ <property name="width">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ </packing>
+ </child>
+ </object>
+</interface>