GNOME Bugzilla – Bug 318276
GtkLabels not recalculating the text layout correctly.
Last modified: 2018-02-10 03:45:13 UTC
Please describe the problem: Gtk 2.6.8 win32 I have a GtkContainer derived class that uses gtk_widget_size_allocate to place and size a GtkLabel. The GtkLabels do not always appear to recalculate the text layout correctly (see wrong.png). If directly after the gtk_widget_size_allocate I do a gtk_widget_size_request then the layout is correct (see correct.png). In both instances the bounding for the GtkLabel is {0, 0, 67, 22}. Looking at the sources I think it could be that gtk_label_ensure_layout is called in gtk_label_size_request. Could the same call be placed in gtk_label_size_allocate, along the lines of... if ((allocation->width != widget->allocation.width) || (allocation->height != widget->allocation.height) { gtk_label_ensure_layout (label); } I have not been able to test this with modified GtkLabel sources though. Kind Regards Steps to reproduce: Actual results: Expected results: Does this happen every time? Yes Other information:
Created attachment 53223 [details] wrong.png
Created attachment 53224 [details] correct.png
is this bug still valid?
In the latest 2.8.14-rc1 from http://gladewin32.sourceforge.net it still is.
I've never reproduced this. Is it still valid? If so, can you provide a simple demo program that can exploit the bug?
Yes, it is still valid. You also sometimes see this with a GtkLabel in a GtkButton not repostioning correctly after the button is resized (I've seen this recently). The project I have been working on intermittently over the years is a library called curlyankles which does some weird and complicated stuff. I think you may find refences to this bug number in the code. You'll forgive me but over 2 years after this bug was raised I can't remember the exact nature of why it happens. I did research this at the time and remember trying out the initial posts fix which seemed to resolve the problem. You say you have not reproduced this, what have you tried? Thanks
Back to the intial post. Is the GtkLabel really reliant on its layout being calculated via its size_request rather than its size_allocate? I would have thought that the layout would be calculated in a new allocation rather than a request. I think this is where the error is. My gtkcontainer derivative is more like a GtkFixed which I don't think does a size request along the lines of a usual GtkContainers?
Is this -only- happening on Win32?
I believe I see this bug on LINUX (openSUSE) via use of PyGTK. See the mail list thread at http://www.daa.com.au/pipermail/pygtk/2011-February/019434.html Binding a method of - def label_size_allocate_hack(widget, allocation): "Callback which re-allocates the size of a label." layout = widget.get_layout() lw_old, lh_old = layout.get_size() # fixed width labels if lw_old / pango.SCALE == allocation.width: return # set wrap width to the pango.Layout of the labels layout.set_width(allocation.width * pango.SCALE) to the size-allocate event works around the issue and text displays correctly wrapped. label.connect_after("size-allocate", label_size_allocate_hack) This is shamelessly stolen from the StackOverflow thread at http://stackoverflow.com/questions/1893748/pygtk-dynamic-label-wrapping/1911179#1911179
We're moving to gitlab! As part of this move, we are closing bugs that haven't seen activity in more than 5 years. If this issue is still imporant to you and still relevant with GTK+ 3.22 or master, please consider creating a gitlab issue for it.