8

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

Sean Bright
  • 118,630
  • 17
  • 138
  • 146
  • I doubt if `set_{left,right}_margin()` is what you want, as they can be overridden as the documentation states. I wonder if the border background color can be made to match the text background? FWIW, you can get the gdk windows associated with the four border areas (and set their widths individually), so maybe the colors can be made to match. – ergosys Dec 26 '11 at 23:06
  • In 2022 you do have `top margin` and `bottom margin`: https://docs.gtk.org/gtk3/method.TextView.set_top_margin.html https://docs.gtk.org/gtk3/method.TextView.set_bottom_margin.html – Melroy van den Berg Feb 27 '22 at 23:23

3 Answers3

4

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;
}
manuq
  • 182
  • 1
  • 5
2

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

mike
  • 1,135
  • 4
  • 22
  • 39
  • Sometimes this works, sometimes it doesn't. In my Ubuntu Mate virtual machine it does match the background, in my Fedora one it doesn't. – GTK 1.2.6 fanboy Mar 31 '20 at 20:51
1

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.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670