GtkTextView top/bottom margin?

3.2k Views Asked by At

I would like to know the correct and generally accepted way of adding a top and bottom margin to a GtkTextView that is inside of a GtkScrolledWindow. There are functions to set the left and right margin, which I am using:

gtk_text_view_set_left_margin(GTK_TEXT_VIEW(editor_text_view), 2);
gtk_text_view_set_right_margin(GTK_TEXT_VIEW(editor_text_view), 2);

But I can't seem to find any documentation on top and bottom. I've tried changing the border width of the GtkTextView with gtk_container_set_border_width but the border is not painted with the background color of the GtkTextView.

Basically - what I have is on the left and what I want is on the right.

Screenshot of what I have Screenshot of what I want

3

There are 3 best solutions below

1
On

I just had to solve similar issue and I nested the text view in GtkAlignment - that gave me an option to set padding for all sides.

1
On

I'm using Ubuntu Natty with gtk+-3.2.3. and those CSS properties don't have any affect for some reason.

But you can use: gtk_text_view_set_border_window_size( )

Along with: GTK_TEXT_WINDOW_TOP and GTK_TEXT_WINDOW_BOTTOM

And the border color will match the background of the GtkTextView.

http://developer.gnome.org/gtk3/3.4/GtkTextView.html#gtk-text-view-set-border-window-size

2
On

You should use CSS for this things in GTK+ 3:

http://developer.gnome.org/gtk3/3.3/GtkCssProvider.html

Maybe you can use the view class:

.view {
    padding: 3px;
}

Or only apply the style to the GtkTextView:

GtkTextView {
    padding: 3px;
}