Commit 3c2a759c authored by Matthias Clasen's avatar Matthias Clasen

gtk3-demo: Add a markup demo

parent b5a684de
......@@ -39,6 +39,7 @@ demos_base = \
listbox.c \
flowbox.c \
list_store.c \
markup.c \
menus.c \
offscreen_window.c \
offscreen_window2.c \
......
......@@ -145,6 +145,7 @@
<file>links.c</file>
<file>listbox.c</file>
<file>list_store.c</file>
<file>markup.c</file>
<file>menus.c</file>
<file>offscreen_window.c</file>
<file>offscreen_window2.c</file>
......@@ -201,4 +202,7 @@
<file>decor1.png</file>
<file>decor2.png</file>
</gresource>
<gresource prefix="/markup">
<file>markup.txt</file>
</gresource>
</gresources>
/* Text Widget/Markup
*
* GtkTextBuffer lets you define your own tags that can influence
* text formatting in a variety of ways. In this example, we show
* that GtkTextBuffer can load Pango markup and automatically generate
* suitable tags.
*/
#include <gtk/gtk.h>
GtkWidget *
do_markup (GtkWidget *do_widget)
{
static GtkWidget *window = NULL;
if (!window)
{
GtkWidget *view;
GtkWidget *sw;
GtkTextBuffer *buffer;
GtkTextIter iter;
GBytes *bytes;
const gchar *markup;
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, 400);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
gtk_window_set_title (GTK_WINDOW (window), "Markup");
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), 10);
gtk_text_view_set_right_margin (GTK_TEXT_VIEW (view), 10);
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_NEVER,
GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (window), sw);
gtk_container_add (GTK_CONTAINER (sw), view);
bytes = g_resources_lookup_data ("/markup/markup.txt", 0, NULL);
markup = (const gchar *)g_bytes_get_data (bytes, NULL);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
gtk_text_buffer_get_start_iter (buffer, &iter);
gtk_text_buffer_insert_markup (buffer, &iter, markup, -1);
g_bytes_unref (bytes);
gtk_widget_show_all (sw);
}
if (!gtk_widget_get_visible (window))
gtk_widget_show (window);
else
gtk_widget_destroy (window);
return window;
}
Text sizes: <span size="xx-small">tiny</span> <span size="x-small">very small</span> <span size="small">small</span> <span size="medium">normal</span> <span size="large">large</span> <span size="x-large">very large</span> <span size="xx-large">huge</span>
Colorful <span underline="low" underline-color="blue"><span underline="double" underline-color="red">under</span>lines</span>
Colorful <span strikethrough="true" strikethrough-color="magenta">strikethroughs</span>
Text <span color="gray">c<span color="green">o</span>l<span color="tomato">o</span>rs</span>
More superscripts: 2<span rise="8000" size="smaller">2<span rise="14000" size="smaller">2</span></span>
<span letter_spacing="3000">Letterspacing</span>
Shortcuts: <tt>Monospace</tt> – <b>Bold</b> – <i>Italic</i> – <big>Big</big> – <small>Small</small> – <u>Underlined</u> – <s>Strikethrough</s> – Super<sup>script</sup> – Sub<sub>script</sub>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment