[gtk+/gtk-3-22] gtk-demo: Add a demo for tabs
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-3-22] gtk-demo: Add a demo for tabs
- Date: Tue, 29 Nov 2016 21:40:03 +0000 (UTC)
commit 197eaaacb7dbff0b2cb168c6bc85e3ccae4e943d
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Nov 29 16:39:21 2016 -0500
gtk-demo: Add a demo for tabs
One of the least-appreciated features in pango.
It deserves a demo.
demos/gtk-demo/Makefile.am | 1 +
demos/gtk-demo/demo.gresource.xml | 1 +
demos/gtk-demo/tabs.c | 63 +++++++++++++++++++++++++++++++++++++
3 files changed, 65 insertions(+), 0 deletions(-)
---
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am
index acabe1f..acc1f99 100644
--- a/demos/gtk-demo/Makefile.am
+++ b/demos/gtk-demo/Makefile.am
@@ -64,6 +64,7 @@ demos_base = \
spinbutton.c \
spinner.c \
stack.c \
+ tabs.c \
textmask.c \
textview.c \
textscroll.c \
diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml
index 7a44d6d..a6f8200 100644
--- a/demos/gtk-demo/demo.gresource.xml
+++ b/demos/gtk-demo/demo.gresource.xml
@@ -192,6 +192,7 @@
<file>stack.c</file>
<file>spinbutton.c</file>
<file>spinner.c</file>
+ <file>tabs.c</file>
<file>textview.c</file>
<file>textscroll.c</file>
<file>theming_style_classes.c</file>
diff --git a/demos/gtk-demo/tabs.c b/demos/gtk-demo/tabs.c
new file mode 100644
index 0000000..c1b511d
--- /dev/null
+++ b/demos/gtk-demo/tabs.c
@@ -0,0 +1,63 @@
+/* Text View/Tabs
+ *
+ * GtkTextView can position text at fixed positions, using tabs.
+ */
+
+#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+
+GtkWidget *
+do_tabs (GtkWidget *do_widget)
+{
+ static GtkWidget *window = NULL;
+
+ if (!window)
+ {
+ GtkWidget *view;
+ GtkWidget *sw;
+ GtkTextBuffer *buffer;
+ PangoTabArray *tabs;
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title (GTK_WINDOW (window), "Tabs");
+ 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_container_set_border_width (GTK_CONTAINER (window), 0);
+
+ view = gtk_text_view_new ();
+ gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD);
+ gtk_text_view_set_left_margin (GTK_TEXT_VIEW (view), 20);
+ gtk_text_view_set_right_margin (GTK_TEXT_VIEW (view), 20);
+
+ tabs = pango_tab_array_new (3, TRUE);
+ pango_tab_array_set_tab (tabs, 0, PANGO_TAB_LEFT, 0);
+ pango_tab_array_set_tab (tabs, 1, PANGO_TAB_LEFT, 150);
+ pango_tab_array_set_tab (tabs, 2, PANGO_TAB_LEFT, 300);
+ gtk_text_view_set_tabs (GTK_TEXT_VIEW (view), tabs);
+ pango_tab_array_free (tabs);
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
+ gtk_text_buffer_set_text (buffer, "one\ttwo\tthree\nfour\tfive\tsix\nseven\teight\tnine", -1);
+
+ 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 (window), sw);
+ gtk_container_add (GTK_CONTAINER (sw), view);
+
+ gtk_widget_show_all (sw);
+ }
+
+ 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]