[gtk/wip/fontchooser-language-filtering: 1/3] wip: Add more filtering to the fontchooser




commit 53e756a01b961c160be26b1237df65f815e74524
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Sep 8 19:51:12 2020 -0400

    wip: Add more filtering to the fontchooser

 gtk/gtkfontchooserwidget.c     | 35 ++++++++++++++++++++++++
 gtk/ui/gtkfontchooserwidget.ui | 60 ++++++++++++++++++++++++++++++++++++++----
 2 files changed, 90 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index 249e8fbca0..ffe5426a00 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -102,6 +102,7 @@ struct _GtkFontChooserWidget
   GtkWidget    *list_stack;
   GtkSingleSelection *selection;
   GtkCustomFilter      *custom_filter;
+  GtkCustomFilter      *monospace_filter;
   GtkFilterListModel   *filter_model;
 
   GtkWidget       *preview;
@@ -323,6 +324,38 @@ output_cb (GtkSpinButton *spin,
   return TRUE;
 }
 
+static gboolean
+monospace_filter_cb (gpointer item,
+                     gpointer data)
+{
+  PangoFontFamily *family;
+
+  if (PANGO_IS_FONT_FAMILY (item))
+    family = item;
+  else
+    family = pango_font_face_get_family (PANGO_FONT_FACE (item));
+
+  return pango_font_family_is_monospace (family);
+}
+
+static void
+monospace_check_changed (GtkCheckButton       *check,
+                         GParamSpec           *pspec,
+                         GtkFontChooserWidget *self)
+{
+  if (gtk_check_button_get_active (check))
+    {
+      gtk_custom_filter_set_filter_func (self->monospace_filter,
+                                         monospace_filter_cb,
+                                         NULL,
+                                         NULL);
+    }
+  else
+    {
+      gtk_custom_filter_set_filter_func (self->monospace_filter, NULL, NULL, NULL);
+    }
+}
+
 static void
 gtk_font_chooser_widget_update_marks (GtkFontChooserWidget *self)
 {
@@ -796,6 +829,7 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
   gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, filter_model);
   gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, selection);
   gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, custom_filter);
+  gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, monospace_filter);
   gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, preview);
   gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, preview2);
   gtk_widget_class_bind_template_child (widget_class, GtkFontChooserWidget, size_label);
@@ -817,6 +851,7 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, output_cb);
   gtk_widget_class_bind_template_callback (widget_class, selection_changed_cb);
   gtk_widget_class_bind_template_callback (widget_class, resize_by_scroll_cb);
+  gtk_widget_class_bind_template_callback (widget_class, monospace_check_changed);
 
   gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
   gtk_widget_class_set_css_name (widget_class, I_("fontchooser"));
diff --git a/gtk/ui/gtkfontchooserwidget.ui b/gtk/ui/gtkfontchooserwidget.ui
index acfbf57570..902555f745 100644
--- a/gtk/ui/gtkfontchooserwidget.ui
+++ b/gtk/ui/gtkfontchooserwidget.ui
@@ -21,6 +21,10 @@
               <object class="GtkCustomFilter" id="custom_filter">
               </object>
             </child>
+            <child>
+              <object class="GtkCustomFilter" id="monospace_filter">
+              </object>
+            </child>
           </object>
         </property>
       </object>
@@ -49,11 +53,57 @@
                 <property name="row-spacing">6</property>
                 <property name="column-spacing">6</property>
                 <child>
-                  <object class="GtkSearchEntry" id="search_entry">
-                    <property name="hexpand">1</property>
-                    <property name="activates-default">1</property>
-                    <property name="placeholder-text" translatable="yes">Search font name</property>
-                    <signal name="stop-search" handler="stop_search_cb" swapped="no"/>
+                  <object class="GtkBox">
+                    <style>
+                      <class name="linked"/>
+                    </style>
+                    <child>
+                      <object class="GtkSearchEntry" id="search_entry">
+                        <property name="hexpand">1</property>
+                        <property name="activates-default">1</property>
+                        <property name="placeholder-text" translatable="yes">Search font name</property>
+                        <signal name="stop-search" handler="stop_search_cb" swapped="no"/>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkMenuButton">
+                        <property name="icon-name">pan-down-symbolic</property>
+                        <property name="popover">
+                          <object class="GtkPopover">
+                            <child>
+                              <object class="GtkBox">
+                                <property name="orientation">vertical</property>
+                                <child>
+                                  <object class="GtkLabel">
+                                    <property name="label" translatable="yes">Filter by</property>
+                                    <property name="margin-bottom">10</property>
+                                    <style>
+                                      <class name="title-4"/>
+                                    </style>
+                                  </object>
+                                </child>
+                                <child>
+                                  <object class="GtkCheckButton" id="monospace_button">
+                                    <property name="label" translatable="yes">Monospace</property>
+                                    <signal name="notify::active" handler="monospace_check_changed"/>
+                                  </object>
+                                </child>
+                                <child>
+                                  <object class="GtkScrolledWindow">
+                                    <property name="hscrollbar-policy">never</property>
+                                    <property name="vscrollbar-policy">automatic</property>
+                                    <child>
+                                      <object class="GtkListView">
+                                      </object>
+                                    </child>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                        </property>
+                      </object>
+                    </child>
                     <layout>
                       <property name="column">0</property>
                       <property name="row">0</property>


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