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 662043 - gtk_widget_set_size_request no longer works with GtkLabel
gtk_widget_set_size_request no longer works with GtkLabel
Status: RESOLVED NOTABUG
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-10-17 21:27 UTC by John Lindgren
Modified: 2012-01-03 06:26 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test program (556 bytes, text/x-csrc)
2011-10-17 21:27 UTC, John Lindgren
Details
Screenshot with GTK+ 2.x (1.69 KB, image/png)
2011-10-17 21:28 UTC, John Lindgren
Details
Screenshot with GTK+ 3.x (4.97 KB, image/png)
2011-10-17 21:28 UTC, John Lindgren
Details

Description John Lindgren 2011-10-17 21:27:56 UTC
Created attachment 199279 [details]
Test program

In GTK+ 2.x, you can use gtk_label_set_ellipsize() and then gtk_widget_set_size_request() 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.6-2 and gtk3 3.2.0-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-10-17 21:28:28 UTC
Created attachment 199280 [details]
Screenshot with GTK+ 2.x
Comment 2 John Lindgren 2011-10-17 21:28:57 UTC
Created attachment 199281 [details]
Screenshot with GTK+ 3.x
Comment 3 L. López 2011-11-27 12:27:27 UTC
I'm affected by this bug too.

In my (simplified)case: I have a label inside a non-resizable window and after some events the label changes his text.

If label's new size is greater than window size the window is resized to a wider one, breaking UI desing (label has ellipsize property on).

Any developer can throw some ideas here?
Comment 4 John Lindgren 2011-12-05 16:27:36 UTC
Hi, this can be closed, as apparently using gtk_widget_set_size_request() to set the width of a label is deprecated in GTK+ 3, and the new way is to use gtk_label_set_width_chars() and gtk_label_set_max_width_chars().  For more info, see this mail and the preceding thread:

http://mail.gnome.org/archives/gtk-app-devel-list/2011-December/msg00023.html
Comment 5 Tristan Van Berkom 2012-01-03 06:26:49 UTC
(In reply to comment #3)
> I'm affected by this bug too.
> 
> In my (simplified)case: I have a label inside a non-resizable window and after
> some events the label changes his text.
> 
> If label's new size is greater than window size the window is resized to a
> wider one, breaking UI desing (label has ellipsize property on).
> 
> Any developer can throw some ideas here?

Ok, this came up before...


gtk_widget_set_size_request() sets the "minimum possible size" of a
widget... any calls to this api will ensure that a widget is *at least*
as big as the request which was set.

In GTK+2, there was some code (IMO: ugly hack) where GtkLabel peeks
at the explicitly set minimum size request and actually limited the
GtkLabel's size for that case. Note that GtkLabel was the only culprit
of handling the user set minimum request explicitly and this has been
removed in GTK+3.

What you need to be using is "width-chars" and "max-width-chars"
conjunction with either ellipsize mode or wrap mode.

  width-chars: Will have essentially the same effect as 
               gtk_widget_set_size_request(), it will request enough
               space for 'n charachters' and uses an approximation
               which should show around the same amount of characters
               with any font resolution.

  max-width-chars: Will limit the natural size request of the label
                   to the width required by the said number of characters.


Note that in GTK+3 there is a difference between 'minimum size'
and 'natural size' definition, 'max-width-chars' limits the possible
natural size request while 'width-chars' forces a 'minimum size'.

A GtkWindow in GTK+-3, like GTK+-2, will constrain the window size
to the minimum request of it's contents (the window cannot be shrunk
but the user to a size less than the "minimum height for minimum width").

Unlike GTK+-2, a default size will be guessed automatically, the default
size of the window will be guessed as the "natural height for natural width".

If the window is not user-resizable, then some oddities apply, non-resizable
windows "shrink" automatically (I believe to the "minimum height for minimum
width", however that might now be the "natural height for natural width").

Hope this helps to clarify things for your application.