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)
This commit is contained in:
Tristan Van Berkom 2010-08-06 22:44:11 -04:00
parent 32d365f476
commit 59e7571aae

View File

@ -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