Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically sizing a GtkTextView in a GtkScrolledWindow

Tags:

c

gtk

gtk2

I work on gschem, a free software tool for editing electronics schematic diagrams. Recently we have encountered a problem using a GtkScrolledWindow containing a GtkTextView.

Context

Recent versions of Ubuntu use overlay scrollbars, which mean that GtkScrolledWindows no longer set a minimum height that provides enough room for a legacy scrollbar (in fact, they have a minimum height of 0). Likewise, a GtkTextView with no text to display requests a height of 0. This means that one of the scrollable GtkTextViews in gschem has been being displayed as one pixel in height, and this is obviously unusable.

Screenshot showing broken

In the dialog box on the right of the screenshot shown above, note the invisible widget between the "Value:" label and the "Add" button.

This has been reported independently by several users -- see also the bug report.

Question

Obviously, we could fix this by doing:

g_object_set (textview, "height-request", 100, NULL);

However, this is pretty inelegant, and will break for users who set very large font sizes in pixels (e.g. users with vision problems or who use high-DPI screens).

Ideally, therefore, we want to set the minimum size of the GtkTextView relative to the default font size, e.g. tell it to "show at least three lines of text".

Can anyone suggest a sensible/elegant approach for doing this?

like image 362
Peter T.B. Brett Avatar asked Dec 12 '11 23:12

Peter T.B. Brett


1 Answers

Just disable the ubuntu overlay scrollbars in your application by doing:

putenv("LIBOVERLAY_SCROLLBAR=0");

Not ideal, but it's a quite good until you can find a more permanent solution. Alternatively just wait until Ubuntu disables overlay scrollbars...

like image 113
Johan Dahlin Avatar answered Sep 30 '22 20:09

Johan Dahlin