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.
This commit is contained in:
Matthias Clasen 2014-11-12 16:05:49 -05:00
parent bac7408be4
commit d50dd1d33c
2 changed files with 46 additions and 13 deletions

View File

@ -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);

View File

@ -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>