[epiphany/wip/exalm/reader-font: 12/12] appearance-page: Use the actual reader mode fonts in the combo row




commit 77a5caf820ad30fa3f367a0d8fe6e1172b5f191f
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Feb 15 21:49:14 2021 +0500

    appearance-page: Use the actual reader mode fonts in the combo row

 src/preferences/prefs-appearance-page.c | 63 ++++++++++++++++++++++++++++++---
 1 file changed, 58 insertions(+), 5 deletions(-)
---
diff --git a/src/preferences/prefs-appearance-page.c b/src/preferences/prefs-appearance-page.c
index 6c28f2ff1..8fe1c6f7f 100644
--- a/src/preferences/prefs-appearance-page.c
+++ b/src/preferences/prefs-appearance-page.c
@@ -63,14 +63,48 @@ reader_font_style_get_name (HdyEnumValueObject *value,
 
   switch (hdy_enum_value_object_get_value (value)) {
     case EPHY_PREFS_READER_FONT_STYLE_SANS:
-      return g_strdup (_("Sans"));
+      return g_strdup_printf ("<span font-family=\"%s\">%s</span>", "sans", _("Sans"));
     case EPHY_PREFS_READER_FONT_STYLE_SERIF:
-      return g_strdup (_("Serif"));
+      return g_strdup_printf ("<span font-family=\"%s\">%s</span>", "serif", _("Serif"));
     default:
       return NULL;
   }
 }
 
+static GtkWidget *
+reader_font_style_create_list_widget (gpointer item,
+                                      gpointer user_data)
+{
+  g_autofree gchar *name = reader_font_style_get_name (item, NULL);
+
+  return g_object_new (GTK_TYPE_LABEL,
+                       "ellipsize", PANGO_ELLIPSIZE_END,
+                       "label", name,
+                       "use-markup", TRUE,
+                       "max-width-chars", 20,
+                       "valign", GTK_ALIGN_CENTER,
+                       "visible", TRUE,
+                       "xalign", 0.0,
+                       NULL);
+}
+
+static GtkWidget *
+reader_font_style_create_current_widget (gpointer item,
+                                         gpointer user_data)
+{
+  g_autofree gchar *name = reader_font_style_get_name (item, NULL);
+
+  return g_object_new (GTK_TYPE_LABEL,
+                       "ellipsize", PANGO_ELLIPSIZE_END,
+                       "halign", GTK_ALIGN_END,
+                       "label", name,
+                       "use-markup", TRUE,
+                       "valign", GTK_ALIGN_CENTER,
+                       "visible", TRUE,
+                       "xalign", 0.0,
+                       NULL);
+}
+
 static gboolean
 reader_font_style_get_mapping (GValue   *value,
                                GVariant *variant,
@@ -246,6 +280,26 @@ on_default_zoom_spin_button_value_changed (GtkSpinButton *spin,
   g_settings_set_double (EPHY_SETTINGS_WEB, EPHY_PREFS_WEB_DEFAULT_ZOOM_LEVEL, value);
 }
 
+static void
+setup_font_row (PrefsAppearancePage *appearance_page)
+{
+  g_autoptr (GListStore) store = g_list_store_new (HDY_TYPE_ENUM_VALUE_OBJECT);
+  g_autoptr (GEnumClass) enum_class = g_type_class_ref (EPHY_TYPE_PREFS_READER_FONT_STYLE);
+
+  for (guint i = 0; i < enum_class->n_values; i++) {
+    g_autoptr(HdyEnumValueObject) obj = hdy_enum_value_object_new (&enum_class->values[i]);
+
+    g_list_store_append (store, obj);
+  }
+
+  hdy_combo_row_bind_model (HDY_COMBO_ROW (appearance_page->reader_mode_font_style),
+                            G_LIST_MODEL (store),
+                            (GtkListBoxCreateWidgetFunc) reader_font_style_create_list_widget,
+                            (GtkListBoxCreateWidgetFunc) reader_font_style_create_current_widget,
+                            NULL,
+                            NULL);
+}
+
 static void
 setup_appearance_page (PrefsAppearancePage *appearance_page)
 {
@@ -282,9 +336,8 @@ setup_appearance_page (PrefsAppearancePage *appearance_page)
   /* ======================================================================== */
   /* ========================== Reader Mode ================================= */
   /* ======================================================================== */
-  hdy_combo_row_set_for_enum (HDY_COMBO_ROW (appearance_page->reader_mode_font_style),
-                              EPHY_TYPE_PREFS_READER_FONT_STYLE,
-                              reader_font_style_get_name, NULL, NULL);
+
+  setup_font_row (appearance_page);
 
   g_settings_bind_with_mapping (reader_settings,
                                 EPHY_PREFS_READER_FONT_STYLE,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]