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 653108 - Setting the wrap-width on a cell renderer wraps the text at the wrong place
Setting the wrap-width on a cell renderer wraps the text at the wrong place
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Widget: GtkTreeView
3.22.x
Other Linux
: Normal normal
: ---
Assigned To: gtktreeview-bugs
gtktreeview-bugs
https://gitlab.gnome.org/GNOME/gtk/is...
Depends on:
Blocks:
 
 
Reported: 2011-06-21 15:30 UTC by Emilio Pozuelo Monfort
Modified: 2018-03-14 21:41 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
testcase.ui (1.22 KB, text/plain)
2011-06-21 15:31 UTC, Emilio Pozuelo Monfort
Details
testcase.c (1.82 KB, text/plain)
2011-06-21 15:33 UTC, Emilio Pozuelo Monfort
Details
Screenshot of the testcase running with gtk+3 (buggy) (7.55 KB, image/png)
2011-06-21 15:34 UTC, Emilio Pozuelo Monfort
Details
Screenshot of the testcase running with gtk+2 (7.83 KB, image/png)
2011-06-21 15:35 UTC, Emilio Pozuelo Monfort
Details

Description Emilio Pozuelo Monfort 2011-06-21 15:30:58 UTC
If you set the width in a GtkCellRendererText, it will wrap the text at the wrong place, but it will request the right height (compared to what gtk+2 did), making it look ugly because there's a lot of empty vertical space.

E.g., for the same text and width, gtk+ 2 would do something like

/----------\
|Happy     |
|birthday  |
|to you,   |
|my friend |
\----------/

But gtk+ 3 does

/------------------\
|                  |
|Happy birthday    |
|to you, my friend |
|                  |
\------------------/

See the attached testcase and the screenshots made when running it against gtk+ 2 and 3.
Comment 1 Emilio Pozuelo Monfort 2011-06-21 15:31:55 UTC
Created attachment 190369 [details]
testcase.ui
Comment 2 Emilio Pozuelo Monfort 2011-06-21 15:33:13 UTC
Created attachment 190370 [details]
testcase.c

Build with:
gcc `pkg-config --cflags --libs gtk+-2.0` -Wall -O0 -g -o testcase testcase.c
Comment 3 Emilio Pozuelo Monfort 2011-06-21 15:34:29 UTC
Created attachment 190371 [details]
Screenshot of the testcase running with gtk+3 (buggy)
Comment 4 Emilio Pozuelo Monfort 2011-06-21 15:35:13 UTC
Created attachment 190372 [details]
Screenshot of the testcase running with gtk+2
Comment 5 Emilio Pozuelo Monfort 2011-06-22 10:14:22 UTC
I've reverted some of the gtkcellrenderertext.c get_layout() code and it's fixed it:

diff --git a/gtk/gtkcellrenderertext.c b/gtk/gtkcellrenderertext.c
index c5eed2e..6f807b7 100644
--- a/gtk/gtkcellrenderertext.c
+++ b/gtk/gtkcellrenderertext.c
@@ -1629,20 +1629,7 @@ get_layout (GtkCellRendererText *celltext,
 
   if (priv->wrap_width != -1)
     {
-      PangoRectangle rect;
-      gint           width, text_width;
-
-      pango_layout_get_extents (layout, NULL, &rect);
-      text_width = rect.width;
-
-      if (cell_area)
-       width = (cell_area->width - xpad * 2) * PANGO_SCALE;
-      else
-       width = priv->wrap_width * PANGO_SCALE;
-
-      width = MIN (width, text_width);
-
-      pango_layout_set_width (layout, width);
+      pango_layout_set_width (layout, priv->wrap_width * PANGO_SCALE);
       pango_layout_set_wrap (layout, priv->wrap_mode);
     }
   else


This is probably a hack, but probably points out a bug in the new size calculation there. That's from

commit e2a82c70b4cb8f59451f8b00dfce33a4f23ff998
Author: Tristan Van Berkom <tristan.van.berkom@gmail.com>
Date:   Wed Aug 18 19:36:51 2010 -0400

    Added/Implemented GtkCellSizeRequestIface
    
    This patch adds height-for-width geometry management
    for cell renderers while still responding to the old
    gtk_cell_renderer_get_size() apis with virtual return values
    (obtained by soliciting the new height-for-width cell renderer
    apis).
Comment 6 Emilio Pozuelo Monfort 2011-06-22 10:40:42 UTC
That is obviously a hack and fixes the height, but breaks e.g. automatically reflowing of text. A proper fix is needed.
Comment 7 Tristan Van Berkom 2011-06-22 17:49:34 UTC
(In reply to comment #0)
> If you set the width in a GtkCellRendererText, it will wrap the text at the
> wrong place, but it will request the right height (compared to what gtk+2 did),
> making it look ugly because there's a lot of empty vertical space.
> 
> E.g., for the same text and width, gtk+ 2 would do something like
> 
> /----------\
> |Happy     |
> |birthday  |
> |to you,   |
> |my friend |
> \----------/
> 
> But gtk+ 3 does
> 
> /------------------\
> |                  |
> |Happy birthday    |
> |to you, my friend |
> |                  |
> \------------------/

Yes, we are aware of this, height-for-width treeviews dont work yet,
however it is not a problem with cell renderers, GtkCellRenderer and
GtkCellArea *do* do height-for-width, but the treeview does not calculate
it all yet for all the variable height-for-width rows.

So, explanation of why it appears as it does above:

   in GTK2, you tell it the wrap width, it wraps to that width
   and then requires the height and width it needs

   in GTK3, if you tell the minimum wrap width that will be a good
   clue to not overwrap... however the height for the minimum width
   will be allocated to every row of the treeview.


To fix this problem what needs to be done (vaguely speaking, we've went
over it before Kris and I and some details might change):

   o GtkTreeView needs to keep track of which rows it requested

   o When GtkTreeView requests a batch of rows at a time

   o Request all the widths of the batch first

   o If the new width is larger then the last batch of row widths,
     then invalidate *all previously requested heights* (which 
     were requested for a different previous width).

   o Once we've requested a full batch that does not push the width
     of the view, start requesting height for width of each row

   o Whenever the width of the treeview is changed (by user resizing
     or whatever), then all the heights of every row must be invalidated
     and they should be requested at the new width.


That's more-or-less what treeview needs to do to offer real
height-for-width rows.
Comment 8 Domenico Ferrari 2013-05-17 15:27:55 UTC
The bug still affects version 3.8.1
Comment 9 Tomáš Hnyk 2015-04-30 12:42:52 UTC
Still afftects 3.14 AFAIK and it makes windows using wrapping look ugly: https://gna.org/support/download.php?file_id=24328 - I would love if somebody could fix this, I lack the skills:-(.
Comment 10 Matthias Clasen 2018-02-10 04:59:22 UTC
We're moving to gitlab! As part of this move, we are moving bugs to NEEDINFO if they haven't seen activity in more than a year. If this issue is still important to you and still relevant with GTK+ 3.22 or master, please reopen it and we will migrate it to gitlab.
Comment 11 Tomáš Hnyk 2018-02-10 13:16:19 UTC
Still an issue, new bug https://gitlab.gnome.org/GNOME/gtk/issues/12
Comment 12 Tomáš Hnyk 2018-02-10 19:14:57 UTC
Would you please include a link to the new bug so that it can be followed?
Comment 13 Tomáš Hnyk 2018-02-10 19:15:57 UTC
Oh, never mind, I put it in the comment above myself,sorry.