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 665560 - gtk_label_set_width_chars() has no effect
gtk_label_set_width_chars() has no effect
Status: RESOLVED INVALID
Product: gtk+
Classification: Platform
Component: Widget: GtkLabel
3.2.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2011-12-05 00:13 UTC by John Lindgren
Modified: 2011-12-26 07:08 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test program (562 bytes, text/x-csrc)
2011-12-05 00:13 UTC, John Lindgren
Details
Screenshot with GTK+ 2.x (4.54 KB, image/png)
2011-12-05 00:15 UTC, John Lindgren
Details
Screenshot with GTK+ 3.x (6.36 KB, image/png)
2011-12-05 00:17 UTC, John Lindgren
Details
Test case that waits for window to be realized (742 bytes, text/x-csrc)
2011-12-05 02:11 UTC, John Lindgren
Details
Test case that waits for the window to be mapped (738 bytes, text/x-csrc)
2011-12-05 02:19 UTC, John Lindgren
Details
Second test case that waits for the window to be mapped but does *not* work (798 bytes, text/x-csrc)
2011-12-05 03:03 UTC, John Lindgren
Details

Description John Lindgren 2011-12-05 00:13:52 UTC
Created attachment 202777 [details]
Test program

In GTK+ 2.x, you can use gtk_label_set_ellipsize() and then
gtk_label_set_width_chars() to make a GtkLabel fit within a certain width. 
In GTK+ 3.x, this no longer works.

Running Arch Linux x86_64 with gtk2 2.24.8-2 and gtk3 3.2.2-2.

I am attaching a simple test program.  Please look at the screenshots of the
same program compiled with GTK+ 2.x and with GTK+ 3.x and note the difference.
Comment 1 John Lindgren 2011-12-05 00:15:40 UTC
Created attachment 202778 [details]
Screenshot with GTK+ 2.x
Comment 2 John Lindgren 2011-12-05 00:17:06 UTC
Created attachment 202779 [details]
Screenshot with GTK+ 3.x
Comment 3 Colomban Wendling 2011-12-05 01:40:45 UTC
Just as a note, this is not completely true.  What you experience here is that an unrealized (unmapped?) GtkWindow now tries to honor the widget's natural size rather than it's minimal one.

Setting the label after the window got realized will work as you expected, either using gtk_widget_set_size_request() or gtk_label_set_width_chars().

Maybe what GtkLabel should do is to honor the GtkWidget::{width,height}-request and GtkLabel::width-chars in its natural size computing since these are explicit overrides of the defaults values.  If the application did override the defaults, GtkLabel could probably safely guess the author knows what she's doing and don't try to me smarter than her.
Comment 4 John Lindgren 2011-12-05 02:01:01 UTC
Waiting for the window to be realized seems like an ugly workaround to me, but I will give it a try.
Comment 5 John Lindgren 2011-12-05 02:11:44 UTC
Created attachment 202789 [details]
Test case that waits for window to be realized

Waiting for the window to be realized doesn't help.  I will see if waiting for the window to be mapped makes any difference.
Comment 6 John Lindgren 2011-12-05 02:19:04 UTC
Created attachment 202790 [details]
Test case that waits for the window to be mapped

Waiting for the window to be mapped before setting the text of the label seems to be a workaround.
Comment 7 John Lindgren 2011-12-05 03:03:02 UTC
Created attachment 202791 [details]
Second test case that waits for the window to be mapped but does *not* work

It gets a little more complicated: if the window is not resizable (that is, gtk_window_set_resizable (FALSE) has been called), the workaround of waiting for the window to be mapped no longer works.
Comment 8 John Lindgren 2011-12-05 16:29:43 UTC
Hi, this can be closed, as apparently I was misunderstanding the purpose of gtk_label_set_width_chars().  Apparently (and contrary to the documentation), gtk_label_set_width_chars() sets the *minimum* width of the label, while gtk_label_set_max_width_chars() sets the default/natural size.  For more info, see this mail and the preceding thread:

http://mail.gnome.org/archives/gtk-app-devel-list/2011-December/msg00023.html
Comment 9 Tristan Van Berkom 2011-12-26 07:08:19 UTC
Closing as an invalid entry, thanks for following up.