After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 657621 - Calculate the wrong height of labels wrapping on words
Calculate the wrong height of labels wrapping on words
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Widget: GtkLabel
3.0.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
: 658351 660587 664898 671440 (view as bug list)
Depends on:
Blocks: 657616
 
 
Reported: 2011-08-29 13:21 UTC by Guillaume Desmottes
Modified: 2018-04-14 23:54 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test.c (2.51 KB, text/plain)
2011-08-31 08:47 UTC, Milan Crha
Details
Test case (842 bytes, text/x-python-script)
2012-12-08 22:03 UTC, Philip Chimento
Details

Description Guillaume Desmottes 2011-08-29 13:21:07 UTC
- Open libempathy-gtk/empathy-account-widget-irc.ui
- Display the vbox_irc widget
- As you can see there is a big space between label_password_note and the GtkExpander

That's because of the wrapping of word. If you disable it, the height of the label is fine. If you try adding or removing some words to the label you'll notice that his height growths/reduces for each word.
Comment 1 Milan Crha 2011-08-31 08:47:23 UTC
Created attachment 195275 [details]
test.c

Test program to demonstrate the issue. Run it and press couple times the "Add new label" button. The dialog is resized much more than is necessary. When I compile it with gtk2 then it doesn't suffer of such issue, but it doesn't rewrap when I change window with, whereas gtk3 does that, it only doesn't shrink the required size appropriately (I mean the dialog's size).

All that seems to me like GtkLabel is calculating its wrapped text size with incorrect label-size values, forcing into unneeded gaps in packing.

This is with gtk3-3.0.12-1 and gtk2-2.24.4-2.
Comment 2 Guillaume Desmottes 2011-09-12 13:49:29 UTC
*** Bug 658351 has been marked as a duplicate of this bug. ***
Comment 3 Guillaume Desmottes 2011-09-12 13:50:05 UTC
Also affect Empathy's contact tooltips:
http://ompldr.org/vYTg0cw
http://ompldr.org/vYTg0dA
Comment 4 Matthias Clasen 2011-09-12 19:48:14 UTC
I've described the underlying issue here in a blog post a while ago (unfortunately lost in the demise of fedora blog hosting...).
The remedy for now is to set a reasonable wrap-width on all wrapping labels.
Comment 5 Xavier Claessens 2011-09-22 12:50:34 UTC
Note that packing label into a GtkGrid instead of a GtkTable fixed this issue.
Comment 6 Benjamin Otte (Company) 2011-09-25 23:10:43 UTC
Yeah, GtkTable is stupid, it assigns the minimum size returned from gtk_widget_get_preferred_size() (why does that function even exist?) to all its children, which is getting more and more broken as widgets switch over more and more to proper width-for-height handling. And GtkTable will be deprecated for GTK 3.4 - it's properly replaced by GtkGrid.
Comment 7 Milan Crha 2011-10-24 12:57:13 UTC
(In reply to comment #4)
> I've described the underlying issue here in a blog post a while ago
> (unfortunately lost in the demise of fedora blog hosting...).
> The remedy for now is to set a reasonable wrap-width on all wrapping labels.

I cannot find the property, is it supposed to be GtkLabel::width-chars and/or GtkLabel::max-width-chars; the later doesn't influence the bad behaviour (while the documentation suggests it should, from my point of view), the former does influence it, but calculating the right value for the parent allocated space is not that trivial (I even do not know how to do that).

(In reply to comment #5)
> Note that packing label into a GtkGrid instead of a GtkTable fixed this issue.

My real widget chain in evolution itself is this:
   GtkLabel
   GtkVBox
   GtkBox
   EAlertBar (GtkInfoBar descendant)
   EMailShellContent (GtkBin descendant)
   GtkNotebook
   GtkVBox
   GtkPaned
   GtkVBox
   EShellWindow (GtkWindow descendant)

Thus there is no GtkTable, neither in my simplified test.c.
Comment 8 Milan Crha 2011-11-11 10:53:20 UTC
*** Bug 660587 has been marked as a duplicate of this bug. ***
Comment 9 Milan Crha 2011-11-29 13:14:29 UTC
*** Bug 664898 has been marked as a duplicate of this bug. ***
Comment 10 Matthew Barnes 2012-03-06 12:10:25 UTC
*** Bug 671440 has been marked as a duplicate of this bug. ***
Comment 11 Milan Crha 2012-03-12 17:02:55 UTC
OK, in Evolution it was its own fault. I just fixed it in [1]. It's not a case for test.c, though.

[1] git.gnome.org/browse/evolution/commit/?id=b561899
Comment 12 Philip Chimento 2012-12-08 22:03:57 UTC
Created attachment 231045 [details]
Test case

I've run into this issue in 3.4.3, also not connected with GtkTable. It seems that the label's height request is always the maximum height request that it would have if its width were squeezed to the minimum. You can work around this by calling gtk_widget_set_size_request(label, SOME_FIXED_VALUE, -1). Here's a Python script illustrating the problem and workaround.
Comment 13 Alan 2017-03-17 21:08:02 UTC
This bug seems to be the cause of https://bugzilla.gnome.org/show_bug.cgi?id=670496. Unfortunately the workaround documented in https://bugzilla.gnome.org/show_bug.cgi?id=657621#c12 (which was applied in zenity) doesn't seem to work anymore in 3.22.
Comment 14 Emmanuele Bassi (:ebassi) 2017-03-18 10:42:25 UTC
This bug should really be closed; the issue is that GtkDialog does not enforce a size related on the monitor size (because it's a broken heuristic) and thus people can set the contents of the dialog to exceed the size of the screen if they aren't careful with label size and word wrapping.

(In reply to Alan from comment #13)
> This bug seems to be the cause of
> https://bugzilla.gnome.org/show_bug.cgi?id=670496. Unfortunately the
> workaround documented in
> https://bugzilla.gnome.org/show_bug.cgi?id=657621#c12 (which was applied in
> zenity) doesn't seem to work anymore in 3.22.

Is Zenity setting the label text from the input without setting max-width-chars on the label it uses, and without setting wrapping to TRUE?
Comment 15 Alan 2017-03-18 14:13:30 UTC
> Is Zenity setting the label text from the input without setting
> max-width-chars on the label it uses, and without setting wrapping to TRUE?

It was setting wrapping to true, but not max-width-chars. Please not that for the dialog to get the right heigh, I not only had to set max-width-chars but also width-chars.
Comment 16 Matthias Clasen 2018-04-14 23:54:39 UTC
As announced a while ago, we are migrating to gitlab, and bugs that haven't seen activity in the last year or so will be not be migrated, but closed out in bugzilla.

If this bug is still relevant to you, you can open a new issue describing the symptoms and how to reproduce it with gtk 3.22.x or master in gitlab:

https://gitlab.gnome.org/GNOME/gtk/issues/new