Commit 59e7571a authored by Tristan Van Berkom's avatar Tristan Van Berkom

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)
parent 32d365f4
...@@ -3250,7 +3250,8 @@ gtk_label_ensure_layout (GtkLabel *label, gboolean guess_wrap_width) ...@@ -3250,7 +3250,8 @@ gtk_label_ensure_layout (GtkLabel *label, gboolean guess_wrap_width)
else if (guess_wrap_width == FALSE && else if (guess_wrap_width == FALSE &&
widget->allocation.width > 1 && widget->allocation.height > 1) 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); gtk_misc_get_padding (GTK_MISC (label), &xpad, &ypad);
if (angle == 90 || angle == 270) if (angle == 90 || angle == 270)
...@@ -3258,6 +3259,12 @@ gtk_label_ensure_layout (GtkLabel *label, gboolean guess_wrap_width) ...@@ -3258,6 +3259,12 @@ gtk_label_ensure_layout (GtkLabel *label, gboolean guess_wrap_width)
else else
width = widget->allocation.width - xpad * 2; 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_wrap (priv->layout, priv->wrap_mode);
pango_layout_set_width (priv->layout, MAX (width, 1) * PANGO_SCALE); pango_layout_set_width (priv->layout, MAX (width, 1) * PANGO_SCALE);
} }
...@@ -3843,18 +3850,6 @@ get_layout_location (GtkLabel *label, ...@@ -3843,18 +3850,6 @@ get_layout_location (GtkLabel *label,
pango_layout_get_extents (priv->layout, NULL, &logical); 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) if (priv->have_transform)
{ {
PangoContext *context = gtk_widget_get_pango_context (widget); PangoContext *context = gtk_widget_get_pango_context (widget);
...@@ -3879,8 +3874,6 @@ get_layout_location (GtkLabel *label, ...@@ -3879,8 +3874,6 @@ get_layout_location (GtkLabel *label,
x = MIN (x, widget->allocation.x + widget->allocation.width - xpad); x = MIN (x, widget->allocation.x + widget->allocation.width - xpad);
/* bgo#315462 - For single-line labels, *do* align the requisition with /* bgo#315462 - For single-line labels, *do* align the requisition with
* respect to the allocation, even if we are under-allocated. For multi-line * 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 * labels, always show the top of the text when they are under-allocated. The
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment