forked from AuroraMiddleware/gtk
label: Position the text properly
The PangoLayout needs to be positioned according to the content allocation of the gadget, not the widget's allocation.
This commit is contained in:
parent
2e362eafc7
commit
197e42efd8
@ -698,3 +698,38 @@ gtk_css_gadget_get_border_allocation (GtkCssGadget *gadget,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gtk_css_gadget_get_content_allocation (GtkCssGadget *gadget,
|
||||
GtkAllocation *allocation,
|
||||
int *baseline)
|
||||
{
|
||||
GtkCssGadgetPrivate *priv = gtk_css_gadget_get_instance_private (gadget);
|
||||
GtkBorder margin, border, padding, extents;
|
||||
GtkCssStyle *style;
|
||||
|
||||
g_return_if_fail (GTK_IS_CSS_GADGET (gadget));
|
||||
|
||||
style = gtk_css_gadget_get_style (gadget);
|
||||
get_box_margin (style, &margin);
|
||||
get_box_border (style, &border);
|
||||
get_box_padding (style, &padding);
|
||||
extents.top = margin.top + border.top + padding.top;
|
||||
extents.right = margin.right + border.right + padding.right;
|
||||
extents.bottom = margin.bottom + border.bottom + padding.bottom;
|
||||
extents.left = margin.left + border.left + padding.left;
|
||||
|
||||
if (allocation)
|
||||
{
|
||||
allocation->x = priv->allocated_size.x + extents.left;
|
||||
allocation->y = priv->allocated_size.y + extents.top;
|
||||
allocation->width = priv->allocated_size.width - extents.left - extents.right;
|
||||
allocation->height = priv->allocated_size.height - extents.top - extents.bottom;
|
||||
}
|
||||
if (baseline)
|
||||
{
|
||||
if (priv->allocated_baseline >= 0)
|
||||
*baseline = priv->allocated_baseline - extents.top;
|
||||
else
|
||||
*baseline = -1;
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +100,9 @@ void gtk_css_gadget_draw (GtkCssGadget
|
||||
void gtk_css_gadget_get_border_allocation (GtkCssGadget *gadget,
|
||||
GtkAllocation *allocation,
|
||||
int *baseline);
|
||||
void gtk_css_gadget_get_content_allocation (GtkCssGadget *gadget,
|
||||
GtkAllocation *allocation,
|
||||
int *baseline);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -3403,16 +3403,18 @@ gtk_label_update_layout_width (GtkLabel *label)
|
||||
|
||||
if (priv->ellipsize || priv->wrap)
|
||||
{
|
||||
GtkAllocation allocation;
|
||||
GtkBorder border;
|
||||
PangoRectangle logical;
|
||||
gint width, height;
|
||||
|
||||
gtk_css_gadget_get_content_allocation (priv->gadget, &allocation, NULL);
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
_gtk_misc_get_padding_and_border (GTK_MISC (label), &border);
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
width = gtk_widget_get_allocated_width (GTK_WIDGET (label)) - border.left - border.right;
|
||||
height = gtk_widget_get_allocated_height (GTK_WIDGET (label)) - border.top - border.bottom;
|
||||
width = allocation.width - border.left - border.right;
|
||||
height = allocation.height - border.top - border.bottom;
|
||||
|
||||
if (priv->have_transform)
|
||||
{
|
||||
@ -4011,12 +4013,13 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
req_width += border.left + border.right;
|
||||
req_height += border.top + border.bottom;
|
||||
|
||||
gtk_widget_get_allocation (widget, &allocation);
|
||||
gtk_css_gadget_get_content_allocation (priv->gadget,
|
||||
&allocation,
|
||||
&baseline);
|
||||
|
||||
x = floor (allocation.x + border.left + xalign * (allocation.width - req_width) - logical.x);
|
||||
|
||||
baseline_offset = 0;
|
||||
baseline = gtk_widget_get_allocated_baseline (widget);
|
||||
if (baseline != -1 && !priv->have_transform)
|
||||
{
|
||||
layout_baseline = pango_layout_get_baseline (priv->layout) / PANGO_SCALE;
|
||||
|
Loading…
Reference in New Issue
Block a user