summaryrefslogtreecommitdiff
path: root/demos
diff options
context:
space:
mode:
authorIgnacio Casal Quinteiro <icq@gnome.org>2011-05-19 18:53:05 +0200
committerMatthias Clasen <mclasen@redhat.com>2011-06-12 23:27:18 -0400
commitcfb2a45f9aef90e82d5811ff2f3075bec7a52aaa (patch)
treee3565062e98978eb9f174c3c9cbd4c76d4062b1e /demos
parentf50da3babeecc34763933d1e515cfc1ba1da065a (diff)
downloadgtk+-cfb2a45f9aef90e82d5811ff2f3075bec7a52aaa.tar.gz
overlay: add initial version of gtkoverlay
Diffstat (limited to 'demos')
-rw-r--r--demos/gtk-demo/Makefile.am1
-rw-r--r--demos/gtk-demo/overlay.c181
2 files changed, 182 insertions, 0 deletions
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am
index 46b805a0bf..e4c45538df 100644
--- a/demos/gtk-demo/Makefile.am
+++ b/demos/gtk-demo/Makefile.am
@@ -30,6 +30,7 @@ demos = \
menus.c \
offscreen_window.c \
offscreen_window2.c \
+ overlay.c \
panes.c \
pickers.c \
pixbufs.c \
diff --git a/demos/gtk-demo/overlay.c b/demos/gtk-demo/overlay.c
new file mode 100644
index 0000000000..cbddd93cf6
--- /dev/null
+++ b/demos/gtk-demo/overlay.c
@@ -0,0 +1,181 @@
+/* Overlay
+ *
+ * Stack widgets in static positions over a main widget
+ */
+
+#include <gtk/gtk.h>
+
+GtkWidget *
+do_overlay (GtkWidget *do_widget)
+{
+ static GtkWidget *window = NULL;
+
+ if (!window)
+ {
+ GtkWidget *view;
+ GtkWidget *sw;
+ GtkWidget *overlay;
+ GtkWidget *entry;
+ GtkWidget *label;
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_screen (GTK_WINDOW (window),
+ gtk_widget_get_screen (do_widget));
+ gtk_window_set_default_size (GTK_WINDOW (window),
+ 450, 450);
+
+ g_signal_connect (window, "destroy",
+ G_CALLBACK (gtk_widget_destroyed), &window);
+
+ gtk_window_set_title (GTK_WINDOW (window), "Overlay");
+ gtk_container_set_border_width (GTK_CONTAINER (window), 0);
+
+ view = gtk_text_view_new ();
+
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_container_add (GTK_CONTAINER (sw), view);
+
+ overlay = gtk_overlay_new ();
+ gtk_container_add (GTK_CONTAINER (overlay), sw);
+ gtk_container_add (GTK_CONTAINER (window), overlay);
+
+ entry = gtk_entry_new ();
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), entry);
+ gtk_widget_set_halign (entry, GTK_ALIGN_END);
+ gtk_widget_set_valign (entry, GTK_ALIGN_END);
+
+ label = gtk_label_new ("Hello world");
+ gtk_widget_set_halign (label, GTK_ALIGN_END);
+ gtk_widget_set_valign (label, GTK_ALIGN_END);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), label);
+ gtk_widget_set_margin_left (label, 20);
+ gtk_widget_set_margin_right (label, 20);
+ gtk_widget_set_margin_top (label, 5);
+ gtk_widget_set_margin_bottom (label, 5);
+
+ entry = gtk_entry_new ();
+ gtk_widget_set_halign (entry, GTK_ALIGN_START);
+ gtk_widget_set_valign (entry, GTK_ALIGN_END);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), entry);
+
+ label = gtk_label_new ("Hello world");
+ gtk_widget_set_halign (label, GTK_ALIGN_START);
+ gtk_widget_set_valign (label, GTK_ALIGN_END);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), label);
+ gtk_widget_set_margin_left (label, 20);
+ gtk_widget_set_margin_right (label, 20);
+ gtk_widget_set_margin_top (label, 5);
+ gtk_widget_set_margin_bottom (label, 5);
+
+ entry = gtk_entry_new ();
+ gtk_widget_set_halign (entry, GTK_ALIGN_END);
+ gtk_widget_set_valign (entry, GTK_ALIGN_START);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), entry);
+
+ label = gtk_label_new ("Hello world");
+ gtk_widget_set_halign (label, GTK_ALIGN_END);
+ gtk_widget_set_valign (label, GTK_ALIGN_START);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), label);
+ gtk_widget_set_margin_left (label, 20);
+ gtk_widget_set_margin_right (label, 20);
+ gtk_widget_set_margin_top (label, 5);
+ gtk_widget_set_margin_bottom (label, 5);
+
+ entry = gtk_entry_new ();
+ gtk_widget_set_halign (entry, GTK_ALIGN_START);
+ gtk_widget_set_valign (entry, GTK_ALIGN_START);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), entry);
+
+ label = gtk_label_new ("Hello world");
+ gtk_widget_set_halign (label, GTK_ALIGN_START);
+ gtk_widget_set_valign (label, GTK_ALIGN_START);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), label);
+ gtk_widget_set_margin_left (label, 20);
+ gtk_widget_set_margin_right (label, 20);
+ gtk_widget_set_margin_top (label, 5);
+ gtk_widget_set_margin_bottom (label, 5);
+
+ entry = gtk_entry_new ();
+ gtk_widget_set_halign (entry, GTK_ALIGN_END);
+ gtk_widget_set_valign (entry, GTK_ALIGN_CENTER);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), entry);
+
+ label = gtk_label_new ("Hello world");
+ gtk_widget_set_halign (label, GTK_ALIGN_END);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), label);
+ gtk_widget_set_margin_left (label, 20);
+ gtk_widget_set_margin_right (label, 20);
+ gtk_widget_set_margin_top (label, 5);
+ gtk_widget_set_margin_bottom (label, 5);
+
+ entry = gtk_entry_new ();
+ gtk_widget_set_halign (entry, GTK_ALIGN_START);
+ gtk_widget_set_valign (entry, GTK_ALIGN_CENTER);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), entry);
+
+ label = gtk_label_new ("Hello world");
+ gtk_widget_set_halign (label, GTK_ALIGN_START);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), label);
+ gtk_widget_set_margin_left (label, 20);
+ gtk_widget_set_margin_right (label, 20);
+ gtk_widget_set_margin_top (label, 5);
+ gtk_widget_set_margin_bottom (label, 5);
+
+ entry = gtk_entry_new ();
+ gtk_widget_set_halign (entry, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (entry, GTK_ALIGN_START);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), entry);
+
+ label = gtk_label_new ("Hello world");
+ gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (label, GTK_ALIGN_START);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), label);
+ gtk_widget_set_margin_left (label, 20);
+ gtk_widget_set_margin_right (label, 20);
+ gtk_widget_set_margin_top (label, 5);
+ gtk_widget_set_margin_bottom (label, 5);
+
+ entry = gtk_entry_new ();
+ gtk_widget_set_halign (entry, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (entry, GTK_ALIGN_END);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), entry);
+
+ label = gtk_label_new ("Hello world");
+ gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (label, GTK_ALIGN_END);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), label);
+ gtk_widget_set_margin_left (label, 10);
+ gtk_widget_set_margin_right (label, 10);
+ gtk_widget_set_margin_top (label, 5);
+ gtk_widget_set_margin_bottom (label, 5);
+
+ entry = gtk_entry_new ();
+ gtk_widget_set_halign (entry, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (entry, GTK_ALIGN_CENTER);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), entry);
+
+ label = gtk_label_new ("Hello world");
+ gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), label);
+
+ gtk_widget_show_all (overlay);
+ }
+
+ if (!gtk_widget_get_visible (window))
+ {
+ gtk_widget_show (window);
+ }
+ else
+ {
+ gtk_widget_destroy (window);
+ window = NULL;
+ }
+
+ return window;
+}