[gtk+] gtk3-demo: Use better text margins
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] gtk3-demo: Use better text margins
- Date: Wed, 12 Nov 2014 21:06:44 +0000 (UTC)
commit d50dd1d33c1b2ee8c68b8fbd82d0043886972a47
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Nov 12 16:05:49 2014 -0500
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 6018126..c555136 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 (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);
+
+ 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);
}
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 900dc44..f24989f 100644
--- a/demos/gtk-demo/main.ui
+++ b/demos/gtk-demo/main.ui
@@ -133,10 +133,8 @@
<object class="GtkTextView" id="info-textview">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="margin_start">20</property>
- <property name="margin_end">20</property>
- <property name="margin_top">20</property>
- <property name="margin_bottom">20</property>
+ <property name="left-margin">20</property>
+ <property name="right-margin">20</property>
<property name="pixels_above_lines">2</property>
<property name="pixels_below_lines">2</property>
<property name="editable">False</property>
@@ -170,10 +168,8 @@
<object class="GtkTextView" id="source-textview">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="margin_start">20</property>
- <property name="margin_end">20</property>
- <property name="margin_top">20</property>
- <property name="margin_bottom">20</property>
+ <property name="left-margin">20</property>
+ <property name="right-margin">20</property>
<property name="editable">False</property>
<property name="cursor_visible">False</property>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]