summaryrefslogtreecommitdiff
path: root/gtk/gtkbuiltinicon.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2016-01-17 21:02:18 -0500
committerMatthias Clasen <mclasen@redhat.com>2016-01-17 21:02:18 -0500
commitda30858ee416ec5a64579cb6a770efe44fb83789 (patch)
tree5c11e7b2f58d0c7b748e30f8028a1fcc9527a22b /gtk/gtkbuiltinicon.c
parent9c3907dab016d9c1477f2bcd1bd64a6452fd3f78 (diff)
downloadgtk+-da30858ee416ec5a64579cb6a770efe44fb83789.tar.gz
builtin icon: set a baseline
Most uses of builtin icons (check and radio buttons, expanders, etc) are placed next to labels, so they should be properly positioned wrt to the baseline. Lacking anything better, give the builtin icons a baseline that places the center of the icon at the strikethrough position.
Diffstat (limited to 'gtk/gtkbuiltinicon.c')
-rw-r--r--gtk/gtkbuiltinicon.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/gtk/gtkbuiltinicon.c b/gtk/gtkbuiltinicon.c
index 8e543e5f11..8b99573446 100644
--- a/gtk/gtkbuiltinicon.c
+++ b/gtk/gtkbuiltinicon.c
@@ -63,6 +63,10 @@ gtk_builtin_icon_get_preferred_size (GtkCssGadget *gadget,
gint *natural_baseline)
{
GtkBuiltinIconPrivate *priv = gtk_builtin_icon_get_instance_private (GTK_BUILTIN_ICON (gadget));
+ GtkWidget *widget;
+ PangoContext *pango_context;
+ PangoFontMetrics *metrics;
+ int strikethrough;
double min_size;
guint property;
@@ -73,27 +77,42 @@ gtk_builtin_icon_get_preferred_size (GtkCssGadget *gadget,
min_size = _gtk_css_number_value_get (gtk_css_style_get_value (gtk_css_gadget_get_style (gadget), property), 100);
if (min_size > 0.0)
{
- *minimum = *natural = 0;
- return;
+ *minimum = *natural = min_size;
}
-
- if (priv->default_size_property)
+ else if (priv->default_size_property)
{
GValue value = G_VALUE_INIT;
/* Do it a bit more complicated here so we get warnings when
- * somebody sets a non-int proerty. */
+ * somebody sets a non-int proerty.
+ */
g_value_init (&value, G_TYPE_INT);
gtk_widget_style_get_property (gtk_css_gadget_get_owner (gadget),
priv->default_size_property,
&value);
*minimum = *natural = g_value_get_int (&value);
g_value_unset (&value);
- return;
}
+ else
+ {
+ *minimum = *natural = priv->default_size;
+ }
+
+ widget = gtk_css_gadget_get_owner (gadget);
+
+ pango_context = gtk_widget_get_pango_context (widget);
+ metrics = pango_context_get_metrics (pango_context,
+ pango_context_get_font_description (pango_context),
+ pango_context_get_language (pango_context));
+
+ strikethrough = pango_font_metrics_get_strikethrough_position (metrics);
+
+ if (minimum_baseline)
+ *minimum_baseline = *minimum * 0.5 + PANGO_PIXELS (strikethrough);
+ if (natural_baseline)
+ *natural_baseline = *minimum_baseline;
- *minimum = priv->default_size;
- *natural = priv->default_size;
+ pango_font_metrics_unref (metrics);
}
static void