[gtk+/gtk-2-16] bgo#315462 - Make GtkLabel deal with too-small height allocations gracefully



commit 67e0a44100a288fd3374f932ba976c64e744474f
Author: Federico Mena Quintero <federico novell com>
Date:   Tue May 12 19:12:55 2009 -0500

    bgo#315462 - Make GtkLabel deal with too-small height allocations gracefully
    
    Previously we would always align the top of the text with the label's allocation-plus-padding.
    However, this makes a single-line label inside a GtkButton look badly clipped when the button
    has a smaller allocation than its requisition.  So, for single-line labels we respect the
    alignment even if it doesn't fit within the label's allocation.  But for multi-line labels, we
    give preference to showing the first line, to give the user some context.
    
    Signed-off-by: Federico Mena Quintero <federico novell com>
---
 gtk/gtklabel.c |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 91ab5cc..3735b3b 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -2775,9 +2775,26 @@ get_layout_location (GtkLabel  *label,
     x = MIN (x, widget->allocation.x + widget->allocation.width - misc->xpad);
   x -= logical.x;
 
-  y = floor (widget->allocation.y + (gint)misc->ypad 
-             + MAX (((widget->allocation.height - widget->requisition.height) * misc->yalign),
-	     0));
+  /* bgo#315462 - 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.  The
+   * rationale is this:
+   *
+   * - Single-line labels appear in GtkButtons, and it is very easy to get them
+   *   to be smaller than their requisition.  The button may clip the label, but
+   *   the label will still be able to show most of itself and the focus
+   *   rectangle.  Also, it is fairly easy to read a single line of clipped text.
+   *
+   * - Multi-line labels should not be clipped to showing "something in the
+   *   middle".  You want to read the first line, at least, to get some context.
+   */
+  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;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]