Vertical position of text in under-allocated labels

2007-12-17 Thread Federico Mena Quintero
Hi,

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 this:
http://bugzilla.gnome.org/show_bug.cgi?id=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.

Does this make sense?  I'll cook a patch to test it, but first I wanted
to confirm with people who have given more thought to this.

  Federico
attachment: no-focus.pngattachment: focus.png___
gtk-devel-list mailing list
gtk-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-devel-list


Re: Vertical position of text in under-allocated labels

2007-12-17 Thread Federico Mena Quintero
.. And here is a patch which fixes the problem in main-menu.

  Federico
2007-12-17  Federico Mena Quintero  [EMAIL PROTECTED]

	* gtk/gtklabel.c (get_layout_location): For single-line labels,
	align the requisition to the allocation unconditionally, even if
	we are under-allocated.  For multi-line labels, try to show the
	top of the text as before.  Fixes
	https://bugzilla.novell.com/show_bug.cgi?id=310710

diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index cd6c5ac..6e38a7d 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -2362,9 +2362,17 @@ get_layout_location (GtkLabel  *label,
   else
 x = MIN (x, widget-allocation.x + widget-allocation.width - misc-xpad);
 
-  y = floor (widget-allocation.y + (gint)misc-ypad 
- + MAX (((widget-allocation.height - widget-requisition.height) * misc-yalign),
-	 0));
+  /* For single-line labels, *do* align the requisition with respect to the allocation, even
+   * if we are under-allocated.  For multi-line labels, always show the top of the text when
+   * they are under-allocated.
+   */
+  if (pango_layout_get_line_count (label-layout) == 1)
+y = floor (widget-allocation.y + (gint)misc-ypad 
+	   + (widget-allocation.height - widget-requisition.height) * misc-yalign);
+  else
+y = floor (widget-allocation.y + (gint)misc-ypad 
+	   + MAX (((widget-allocation.height - widget-requisition.height) * misc-yalign),
+		  0));
 
   if (xp)
 *xp = x;
___
gtk-devel-list mailing list
gtk-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-devel-list