7

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?

Peter T.B. Brett
  • 1,250
  • 11
  • 20

4 Answers4

2

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

Johan Dahlin
  • 25,300
  • 6
  • 40
  • 55
  • Yes, this is an obvious workaround, and was in fact suggested by one of the respondents to our bug report. I was hoping someone could recommend a solution that works *with* overlay scrollbars. :-) – Peter T.B. Brett Dec 24 '11 at 00:32
0

Likewise, a GtkTextView with no text to display requests a height of 0.

Probably you can create GtkTextView with some text inside. Like several spaces, and set empty value after creation.

fukanchik
  • 2,811
  • 24
  • 29
0

I would add code to dig out the current/default style information, use that to figure out the font baseline height, and then compute some rough size allocation based on that, around three lines as you mention.

unwind
  • 391,730
  • 64
  • 469
  • 606
  • I suspected that an approach along these lines might be necessary, and I was hoping that someone on StackOverflow had already figured out a nice recipe for doing it! – Peter T.B. Brett Dec 24 '11 at 00:33
0

Does it have to be a textview ? If you can use an eventbox instead, then you can make a cairo surface from it, render the text with pango, and then use pango_layout_get_size() to get the text height.

salsaman
  • 956
  • 6
  • 3