diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2019-01-15 22:16:05 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2019-01-15 22:16:05 +0000 |
commit | 5c50e48156c6edbc2923bb3702f60349d8184057 (patch) | |
tree | cd4e88ce64e45d9f22a90d7983f11bd3ec47da91 /gtk/gtkswitch.c | |
parent | c7af3e61e249c98712b10eff7757a5b0b0d4cc95 (diff) | |
download | gtk+-5c50e48156c6edbc2923bb3702f60349d8184057.tar.gz |
Add fallback glyphs for GtkSwitch states
Even though the IEC power glyphs are part of Unicode 9.0 (released in
2016) not all fonts have them.
To avoid showing the hexbox of doom when the system font does not have
the glyphs we'd like to use, add a fallback pair, using the old glyphs
we suggested when the labels were translatable.
Diffstat (limited to 'gtk/gtkswitch.c')
-rw-r--r-- | gtk/gtkswitch.c | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/gtk/gtkswitch.c b/gtk/gtkswitch.c index abc37ab863..cb361c1292 100644 --- a/gtk/gtkswitch.c +++ b/gtk/gtkswitch.c @@ -281,6 +281,54 @@ gtk_switch_activate (GtkSwitch *sw) } static void +gtk_switch_update_state_labels (GtkSwitch *sw) +{ + /* Glyphs for the ON state, in descending order of preference */ + const char *on_glyphs[] = { + "⏽", /* U+23FD POWER ON SYMBOL */ + "❙", /* U+2759 MEDIUM VERTICAL BAR */ + }; + + /* Glyphs for the OFF state, in descending order of preference */ + const char *off_glyphs[] = { + "⭘", /* U+2B58 HEAVY CIRCLE */ + "○", /* U+25CB WHITE CIRCLE */ + }; + + GtkSwitchPrivate *priv = gtk_switch_get_instance_private (sw); + GtkWidget *widget = GTK_WIDGET (sw); + int i; + + for (i = 0; i < G_N_ELEMENTS (on_glyphs); i++) + { + PangoLayout *layout = gtk_widget_create_pango_layout (widget, on_glyphs[i]); + + if (pango_layout_get_unknown_glyphs_count (layout) == 0) + { + gtk_label_set_text (GTK_LABEL (priv->on_label), on_glyphs[i]); + g_object_unref (layout); + break; + } + + g_object_unref (layout); + } + + for (i = 0; i < G_N_ELEMENTS (off_glyphs); i++) + { + PangoLayout *layout = gtk_widget_create_pango_layout (widget, off_glyphs[i]); + + if (pango_layout_get_unknown_glyphs_count (layout) == 0) + { + gtk_label_set_text (GTK_LABEL (priv->off_label), off_glyphs[i]); + g_object_unref (layout); + break; + } + + g_object_unref (layout); + } +} + +static void gtk_switch_measure (GtkWidget *widget, GtkOrientation orientation, int for_size, @@ -639,14 +687,17 @@ gtk_switch_init (GtkSwitch *self) gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture)); priv->pan_gesture = gesture; - priv->on_label = gtk_label_new ("⏽"); + + priv->on_label = gtk_label_new (""); gtk_widget_set_parent (priv->on_label, GTK_WIDGET (self)); - priv->off_label = gtk_label_new ("⭘"); + priv->off_label = gtk_label_new (""); gtk_widget_set_parent (priv->off_label, GTK_WIDGET (self)); priv->slider = gtk_gizmo_new ("slider", NULL, NULL, NULL); gtk_widget_set_parent (priv->slider, GTK_WIDGET (self)); + + gtk_switch_update_state_labels (self); } /** |