summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2015-12-16 20:39:51 +0100
committerBenjamin Otte <otte@redhat.com>2015-12-16 20:39:51 +0100
commit197e42efd8a0c6adea9fd49f5469687349e887d4 (patch)
tree1bfc30e650c5f7770a2ad6184fbcbd9d48c41021
parent2e362eafc7a22e007fddb4ee9c76dfffdbbf02b7 (diff)
downloadgtk+-197e42efd8a0c6adea9fd49f5469687349e887d4.tar.gz
label: Position the text properly
The PangoLayout needs to be positioned according to the content allocation of the gadget, not the widget's allocation.
-rw-r--r--gtk/gtkcssgadget.c35
-rw-r--r--gtk/gtkcssgadgetprivate.h3
-rw-r--r--gtk/gtklabel.c11
3 files changed, 45 insertions, 4 deletions
diff --git a/gtk/gtkcssgadget.c b/gtk/gtkcssgadget.c
index ac355c5533..895855779d 100644
--- a/gtk/gtkcssgadget.c
+++ b/gtk/gtkcssgadget.c
@@ -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;
+ }
+}
diff --git a/gtk/gtkcssgadgetprivate.h b/gtk/gtkcssgadgetprivate.h
index 9d4b6e40ca..551064fde6 100644
--- a/gtk/gtkcssgadgetprivate.h
+++ b/gtk/gtkcssgadgetprivate.h
@@ -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
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index bcbd3410fb..e87139aa40 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -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;