diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2011-03-22 14:53:21 -0400 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2011-03-23 10:00:01 -0400 |
commit | 6c3c26d9c3194fa6392a54f6347064d8adeb744c (patch) | |
tree | 82ceff9c5bbb4fdb1b28489c92ccd3c768435f3d /gtk/gtkswitch.c | |
parent | 24bba4cc56db7a75569063a0bdc09bffb0e21da5 (diff) | |
download | gtk+-6c3c26d9c3194fa6392a54f6347064d8adeb744c.tar.gz |
switch: hardcode a smaller font size for the switch label
This should not really be done here, but we can't override font size
from the theme just yet.
https://bugzilla.gnome.org/show_bug.cgi?id=645458
Diffstat (limited to 'gtk/gtkswitch.c')
-rw-r--r-- | gtk/gtkswitch.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c index b33a16825c..9b831c70c8 100644 --- a/gtk/gtkswitch.c +++ b/gtk/gtkswitch.c @@ -49,6 +49,7 @@ #include "gtkwidget.h" #include "gtkmarshalers.h" +#include <math.h> #define DEFAULT_SLIDER_WIDTH (36) #define DEFAULT_SLIDER_HEIGHT (22) @@ -537,12 +538,15 @@ gtk_switch_draw (GtkWidget *widget, GtkStyleContext *context; GdkRectangle handle; PangoLayout *layout; + PangoFontDescription *desc; + const PangoFontDescription *style_desc; PangoRectangle rect; gint label_x, label_y; GtkStateFlags state; GtkBorder padding; gint focus_width, focus_pad; gint x, y, width, height; + gint font_size, style_font_size; gtk_widget_style_get (widget, "focus-line-width", &focus_width, @@ -599,6 +603,21 @@ gtk_switch_draw (GtkWidget *widget, * the state */ layout = gtk_widget_create_pango_layout (widget, C_("switch", "ON")); + + /* FIXME: this should be really done in the theme, but overriding font size + * from it doesn't currently work. So we have to hardcode this here and + * below for the "OFF" label. + */ + desc = pango_font_description_new (); + + style_desc = gtk_style_context_get_font (context, state); + style_font_size = pango_font_description_get_size (style_desc); + font_size = MAX (style_font_size - 1 * PANGO_SCALE, ceil (style_font_size * PANGO_SCALE_SMALL)); + + pango_font_description_set_size (desc, font_size); + + pango_layout_set_font_description (layout, desc); + pango_layout_get_extents (layout, NULL, &rect); pango_extents_to_pixels (&rect, NULL); @@ -613,6 +632,8 @@ gtk_switch_draw (GtkWidget *widget, * glyphs then use WHITE CIRCLE (U+25CB) as the text for the state */ layout = gtk_widget_create_pango_layout (widget, C_("switch", "OFF")); + pango_layout_set_font_description (layout, desc); + pango_layout_get_extents (layout, NULL, &rect); pango_extents_to_pixels (&rect, NULL); @@ -634,6 +655,8 @@ gtk_switch_draw (GtkWidget *widget, gtk_switch_paint_handle (widget, cr, &handle); + pango_font_description_free (desc); + return FALSE; } |