[gtk+] GtkFontChooserWidget: Allow fractional font sizes



commit a8ed0dd4eef87dfeaa0263c115c35d74ed8019bc
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Aug 15 14:57:31 2014 -0400

    GtkFontChooserWidget: Allow fractional font sizes
    
    With this change, we let users enter up to 2 decimals in the entry,
    to specify font sizes exactly. The slider still rounds to whole
    numbers.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=665711

 gtk/gtkfontchooserwidget.c               |   18 ++++++++++++++++++
 gtk/resources/ui/gtkfontchooserwidget.ui |    3 ++-
 2 files changed, 20 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index 1edd2cd..e7d347d 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -262,6 +262,23 @@ size_change_cb (GtkAdjustment *adjustment,
   gtk_font_chooser_widget_take_font_desc (fontchooser, font_desc);
 }
 
+static gboolean
+output_cb (GtkSpinButton *spin,
+           gpointer       data)
+{
+  GtkAdjustment *adjustment;
+  gchar *text;
+  gdouble value;
+
+  adjustment = gtk_spin_button_get_adjustment (spin);
+  value = gtk_adjustment_get_value (adjustment);
+  text = g_strdup_printf ("%2.4g", value);
+  gtk_entry_set_text (GTK_ENTRY (spin), text);
+  g_free (text);
+
+  return TRUE;
+}
+
 static void
 gtk_font_chooser_widget_update_marks (GtkFontChooserWidget *fontchooser)
 {
@@ -516,6 +533,7 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, row_inserted_cb);
   gtk_widget_class_bind_template_callback (widget_class, row_deleted_cb);
   gtk_widget_class_bind_template_callback (widget_class, size_change_cb);
+  gtk_widget_class_bind_template_callback (widget_class, output_cb);
 }
 
 static void
diff --git a/gtk/resources/ui/gtkfontchooserwidget.ui b/gtk/resources/ui/gtkfontchooserwidget.ui
index c12bdab..c2c599d 100644
--- a/gtk/resources/ui/gtkfontchooserwidget.ui
+++ b/gtk/resources/ui/gtkfontchooserwidget.ui
@@ -155,8 +155,8 @@
             <property name="can_focus">True</property>
             <property name="hexpand">True</property>
             <property name="adjustment">slider_adjustment</property>
-            <property name="digits">0</property>
             <property name="draw_value">False</property>
+            <property name="round-digits">0</property>
             <signal name="scroll-event" handler="resize_by_scroll_cb" swapped="no"/>
           </object>
           <packing>
@@ -172,6 +172,7 @@
             <property name="can_focus">True</property>
             <property name="invisible_char">•</property>
             <property name="adjustment">spin_adjustment</property>
+            <signal name="output" handler="output_cb"/>
           </object>
           <packing>
             <property name="left_attach">1</property>


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