[gtk+] gtk3-demo: Add another overlay demo
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] gtk3-demo: Add another overlay demo
- Date: Wed, 29 Jul 2015 02:49:03 +0000 (UTC)
commit 763bf27d9c5867328ab40872b3aaff77bc874769
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Jul 28 22:47:07 2015 -0400
gtk3-demo: Add another overlay demo
demos/gtk-demo/Makefile.am | 1 +
demos/gtk-demo/decor1.png | Bin 0 -> 17170 bytes
demos/gtk-demo/decor2.png | Bin 0 -> 17248 bytes
demos/gtk-demo/demo.gresource.xml | 5 ++
demos/gtk-demo/overlay.c | 4 +-
demos/gtk-demo/overlay2.c | 105 +++++++++++++++++++++++++++++++++++++
6 files changed, 113 insertions(+), 2 deletions(-)
---
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am
index f03f1c6..2067229 100644
--- a/demos/gtk-demo/Makefile.am
+++ b/demos/gtk-demo/Makefile.am
@@ -43,6 +43,7 @@ demos_base = \
offscreen_window.c \
offscreen_window2.c \
overlay.c \
+ overlay2.c \
panes.c \
pickers.c \
pixbufs.c \
diff --git a/demos/gtk-demo/decor1.png b/demos/gtk-demo/decor1.png
new file mode 100644
index 0000000..61d2edc
Binary files /dev/null and b/demos/gtk-demo/decor1.png differ
diff --git a/demos/gtk-demo/decor2.png b/demos/gtk-demo/decor2.png
new file mode 100644
index 0000000..6d5a6bf
Binary files /dev/null and b/demos/gtk-demo/decor2.png differ
diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml
index 2ac7dd5..ed879cc 100644
--- a/demos/gtk-demo/demo.gresource.xml
+++ b/demos/gtk-demo/demo.gresource.xml
@@ -149,6 +149,7 @@
<file>offscreen_window.c</file>
<file>offscreen_window2.c</file>
<file>overlay.c</file>
+ <file>overlay2.c</file>
<file>pagesetup.c</file>
<file>panes.c</file>
<file>pickers.c</file>
@@ -196,4 +197,8 @@
<gresource prefix="/filtermodel">
<file>filtermodel.ui</file>
</gresource>
+ <gresource prefix="/overlay2">
+ <file>decor1.png</file>
+ <file>decor2.png</file>
+ </gresource>
</gresources>
diff --git a/demos/gtk-demo/overlay.c b/demos/gtk-demo/overlay.c
index f6d67ed..5861e11 100644
--- a/demos/gtk-demo/overlay.c
+++ b/demos/gtk-demo/overlay.c
@@ -1,4 +1,4 @@
-/* Overlay
+/* Overlay/Interactive Overlay
*
* Shows widgets in static positions over a main widget.
*
@@ -33,7 +33,7 @@ do_overlay (GtkWidget *do_widget)
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window), 500, 510);
- gtk_window_set_title (GTK_WINDOW (window), "Overlay");
+ gtk_window_set_title (GTK_WINDOW (window), "Interactive Overlay");
overlay = gtk_overlay_new ();
grid = gtk_grid_new ();
diff --git a/demos/gtk-demo/overlay2.c b/demos/gtk-demo/overlay2.c
new file mode 100644
index 0000000..a119c92
--- /dev/null
+++ b/demos/gtk-demo/overlay2.c
@@ -0,0 +1,105 @@
+/* Overlay/Decorative Overlay
+ *
+ * Another example of an overlay with some decorative
+ * and some interactive controls.
+ */
+
+#include <gtk/gtk.h>
+
+static GtkTextTag *tag;
+
+static void
+margin_changed (GtkAdjustment *adjustment,
+ GtkTextView *text)
+{
+ gint value;
+
+ value = (gint)gtk_adjustment_get_value (adjustment);
+ gtk_text_view_set_left_margin (GTK_TEXT_VIEW (text), value);
+ g_object_set (tag, "pixels-above-lines", value, NULL);
+}
+
+GtkWidget *
+do_overlay2 (GtkWidget *do_widget)
+{
+ static GtkWidget *window = NULL;
+
+ if (!window)
+ {
+ GtkWidget *overlay;
+ GtkWidget *sw;
+ GtkWidget *text;
+ GtkWidget *image;
+ GtkWidget *scale;
+ GtkTextBuffer *buffer;
+ GtkTextIter start, end;
+ GtkAdjustment *adjustment;
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size (GTK_WINDOW (window), 500, 510);
+ gtk_window_set_title (GTK_WINDOW (window), "Decorative Overlay");
+
+ overlay = gtk_overlay_new ();
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ text = gtk_text_view_new ();
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text));
+
+ gtk_text_buffer_set_text (buffer, "Dear diary...", -1);
+
+ tag = gtk_text_buffer_create_tag (buffer, "top-margin",
+ "pixels-above-lines", 0,
+ NULL);
+ gtk_text_buffer_get_start_iter (buffer, &start);
+ end = start;
+ gtk_text_iter_forward_word_end (&end);
+ gtk_text_buffer_apply_tag (buffer, tag, &start, &end);
+
+ gtk_container_add (GTK_CONTAINER (window), overlay);
+ gtk_container_add (GTK_CONTAINER (overlay), sw);
+ gtk_container_add (GTK_CONTAINER (sw), text);
+
+ g_signal_connect (window, "destroy",
+ G_CALLBACK (gtk_widget_destroyed), &window);
+
+ image = gtk_image_new_from_resource ("/overlay2/decor1.png");
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), image);
+ gtk_overlay_set_overlay_pass_through (GTK_OVERLAY (overlay), image, TRUE);
+ gtk_widget_set_halign (image, GTK_ALIGN_START);
+ gtk_widget_set_valign (image, GTK_ALIGN_START);
+
+ image = gtk_image_new_from_resource ("/overlay2/decor2.png");
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), image);
+ gtk_overlay_set_overlay_pass_through (GTK_OVERLAY (overlay), image, TRUE);
+ gtk_widget_set_halign (image, GTK_ALIGN_END);
+ gtk_widget_set_valign (image, GTK_ALIGN_END);
+
+ adjustment = gtk_adjustment_new (0, 0, 100, 1, 1, 0);
+ g_signal_connect (adjustment, "value-changed",
+ G_CALLBACK (margin_changed), text);
+
+ scale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, adjustment);
+ gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
+ gtk_widget_set_size_request (scale, 120, -1);
+ gtk_widget_set_margin_start (scale, 20);
+ gtk_widget_set_margin_end (scale, 20);
+ gtk_widget_set_margin_bottom (scale, 20);
+ gtk_overlay_add_overlay (GTK_OVERLAY (overlay), scale);
+ gtk_widget_set_halign (scale, GTK_ALIGN_START);
+ gtk_widget_set_valign (scale, GTK_ALIGN_END);
+ gtk_widget_set_tooltip_text (scale, "Margin");
+
+ gtk_adjustment_set_value (adjustment, 100);
+
+ gtk_widget_show_all (overlay);
+ }
+
+ if (!gtk_widget_get_visible (window))
+ gtk_widget_show (window);
+ else
+ gtk_widget_destroy (window);
+
+ return window;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]