[gtk+] Fixed alignment of wrapping labels allocated a greater width than needed
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Fixed alignment of wrapping labels allocated a greater width than needed
- Date: Sat, 7 Aug 2010 02:54:26 +0000 (UTC)
commit 59e7571aae6f61984cc0e5737e482feb33ef9f20
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Fri Aug 6 22:44:11 2010 -0400
Fixed alignment of wrapping labels allocated a greater width than needed
When wrapping labels to allocation width, never set the label wrap
width to a size greater than needed for the label's text (closes bug 625715)
gtk/gtklabel.c | 23 ++++++++---------------
1 files changed, 8 insertions(+), 15 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index d712cc6..2f4c91e 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -3250,7 +3250,8 @@ gtk_label_ensure_layout (GtkLabel *label, gboolean guess_wrap_width)
else if (guess_wrap_width == FALSE &&
widget->allocation.width > 1 && widget->allocation.height > 1)
{
- gint xpad, ypad;
+ PangoRectangle rect;
+ gint xpad, ypad, natural_width;
gtk_misc_get_padding (GTK_MISC (label), &xpad, &ypad);
if (angle == 90 || angle == 270)
@@ -3258,6 +3259,12 @@ gtk_label_ensure_layout (GtkLabel *label, gboolean guess_wrap_width)
else
width = widget->allocation.width - xpad * 2;
+ /* dont set a wrap width wider than the label's natural width
+ * incase we're allocated more space than needed */
+ pango_layout_get_extents (priv->layout, NULL, &rect);
+ natural_width = PANGO_PIXELS (rect.width);
+ width = MIN (natural_width, width);
+
pango_layout_set_wrap (priv->layout, priv->wrap_mode);
pango_layout_set_width (priv->layout, MAX (width, 1) * PANGO_SCALE);
}
@@ -3843,18 +3850,6 @@ get_layout_location (GtkLabel *label,
pango_layout_get_extents (priv->layout, NULL, &logical);
- /* Do the wrap width delimiting before the transform
- */
- if (priv->wrap || priv->ellipsize || priv->width_chars > 0)
- {
- int width;
-
- width = pango_layout_get_width (priv->layout);
-
- if (width != -1)
- logical.width = MIN (width, logical.width);
- }
-
if (priv->have_transform)
{
PangoContext *context = gtk_widget_get_pango_context (widget);
@@ -3879,8 +3874,6 @@ get_layout_location (GtkLabel *label,
x = MIN (x, widget->allocation.x + widget->allocation.width - xpad);
-
-
/* 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]