From d50dd1d33c1b2ee8c68b8fbd82d0043886972a47 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 12 Nov 2014 16:05:49 -0500 Subject: [PATCH] gtk3-demo: Use better text margins We really want margins around the scrollable content, not around the viewport. Make it so by using textview-specific properties. This is unfortunately a little complicated for top/bottom. --- demos/gtk-demo/main.c | 47 +++++++++++++++++++++++++++++++++++++----- demos/gtk-demo/main.ui | 12 ++++------- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/demos/gtk-demo/main.c b/demos/gtk-demo/main.c index 601812640c..c555136e7b 100644 --- a/demos/gtk-demo/main.c +++ b/demos/gtk-demo/main.c @@ -772,19 +772,53 @@ load_file (const gchar *demoname, case 3: /* Reading program body */ gtk_text_buffer_insert (source_buffer, &start, p, -1); - gtk_text_buffer_insert (source_buffer, &start, "\n", 1); + if (lines[i+1] != NULL) + gtk_text_buffer_insert (source_buffer, &start, "\n", 1); break; } } + g_strfreev (lines); + fontify (source_buffer); - g_strfreev (lines); + gtk_text_buffer_create_tag (source_buffer, "top-margin", + "pixels-above-lines", 20, + NULL); + gtk_text_buffer_get_start_iter (source_buffer, &start); + end = start; + gtk_text_iter_forward_word_end (&end); + gtk_text_buffer_apply_tag_by_name (source_buffer, "top-margin", &start, &end); + + gtk_text_buffer_create_tag (source_buffer, "bottom-margin", + "pixels-below-lines", 20, + NULL); + gtk_text_buffer_get_end_iter (source_buffer, &end); + start = end; + gtk_text_iter_backward_word_start (&start); + gtk_text_buffer_apply_tag_by_name (source_buffer, "bottom-margin", &start, &end); + + gtk_text_view_set_buffer (GTK_TEXT_VIEW (source_view), source_buffer); + g_object_unref (source_buffer); + + gtk_text_buffer_create_tag (info_buffer, "top-margin", + "pixels-above-lines", 20, + NULL); + gtk_text_buffer_get_start_iter (info_buffer, &start); + end = start; + gtk_text_iter_forward_word_end (&end); + gtk_text_buffer_apply_tag_by_name (info_buffer, "top-margin", &start, &end); + + gtk_text_buffer_create_tag (info_buffer, "bottom-margin", + "pixels-below-lines", 20, + NULL); + gtk_text_buffer_get_end_iter (info_buffer, &end); + start = end; + gtk_text_iter_backward_word_start (&start); + gtk_text_buffer_apply_tag_by_name (info_buffer, "bottom-margin", &start, &end); gtk_text_view_set_buffer (GTK_TEXT_VIEW (info_view), info_buffer); g_object_unref (info_buffer); - gtk_text_view_set_buffer (GTK_TEXT_VIEW (source_view), source_buffer); - g_object_unref (source_buffer); } static void @@ -830,7 +864,10 @@ create_text (GtkWidget **view, GTK_SHADOW_NONE); *view = text_view = gtk_text_view_new (); - g_object_set (text_view, "margin", 20, NULL); + g_object_set (text_view, + "left-margin", 20, + "right-margin", 20, + NULL); gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE); gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (text_view), FALSE); diff --git a/demos/gtk-demo/main.ui b/demos/gtk-demo/main.ui index 900dc44926..f24989fc30 100644 --- a/demos/gtk-demo/main.ui +++ b/demos/gtk-demo/main.ui @@ -133,10 +133,8 @@ True True - 20 - 20 - 20 - 20 + 20 + 20 2 2 False @@ -170,10 +168,8 @@ True True - 20 - 20 - 20 - 20 + 20 + 20 False False