GNOME Bugzilla – Bug 524166
Underallocated GtkLabel should honor its allocation/alignment
Last modified: 2008-03-24 18:26:11 UTC
We have a problem in gnome-main-menu which is (understandably) a corner case in GtkLabel ( https://bugzilla.novell.com/show_bug.cgi?id=310710 ) First, please see no-focus.png (attached). That is main-menu's "Computer" button and a button from the task list applet. You'll see that the labels don't line up, and the "Computer" text appears clipped (the descender of the "p" is gone). This happens for the following reasons: * The "Computer" button has normal values for focus padding and focus line width. In focus.png (attached) you can see the focused button; the button must be focusable for a11y reasons. * The task list sets the style of its buttons to have zero-width and zero-padding for the focus (and its buttons don't seem to be focusable at all). * The "Computer" label ends up getting an allocation which shorter than its requisition in the Y direction. When GtkLabel comes to gtklabel.c:get_layout_location(), specifically here: y = floor (widget->allocation.y + (gint)misc->ypad + MAX (((widget->allocation.height - widget->requisition.height) * misc->yalign), 0)); It ends up always positioning the label text at or below its allocation.y. This is usually the right thing, but gives bad results when the label is under-allocated *and* centered: the end result definitely doesn't *look* centered --- there's visually enough room for the text inside the button. I did a little digging and found bug #71742 That's when GtkLabel was made to show as much of the text as possible when it is under-allocated. Søren's patch indeed seems to do the right thing for the label's horizontal position, but I think for the vertical position it could very well just center the requisition within the allocation (or use whatever the alignment specifies). This may only work well for single-line labels, and it would fix the problem for the Computer button. For multi-line labels, I think the rationale of showing the top of the text is better.
Created attachment 107933 [details] no-focus.png
Created attachment 107934 [details] focus.png
Created attachment 107935 [details] [review] gtk+-bgo524166-bnc310710-underallocated-gtklabel-position.diff This is the patch which we have in openSUSE 10.3 and fixes the problem.
Thanks for the bug report. This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find. *** This bug has been marked as a duplicate of 315462 ***