[gtk+/gtk-2-24] Scale: Always sync ::digits to Range::round-digits



commit fd218fee464b5120b0eafbdc05d3af4a5b8b159b
Author: Daniel Boles <dboles src gnome org>
Date:   Sun Feb 19 09:25:31 2017 +0000

    Scale: Always sync ::digits to Range::round-digits
    
    The documents state that gtk_scale_set_digits() “causes the value of the
    adjustment to be rounded off to this number of digits, so the retrieved
    value matches the value the user saw.” Note the lack of any condition.
    
    But in fact, if draw-value was false, rounding was disabled on the base
    Range, so values that weren’t displayed weren’t rounded. This made the
    docs wrong and made an apparently cosmetic detail alter functionality.
    
    Fix by ensuring the number of digits set on Scale is always propagated
    along to gtk_range_set_round_digits(), thus rounding to it in all cases
    when the value changes, regardless of whether the value is displayed.
    
    This doesn’t address the other idea from Bugzilla: that changing the
    number of digits should clamp the _existing_ value if it’s more precise.
    This contradicts digits docs in the base Range, but the above from Scale
    can be read as implying it’ll happen. For now, that’s an open question.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=358970

 gtk/gtkscale.c |   34 ++++++++++++++++++----------------
 1 files changed, 18 insertions(+), 16 deletions(-)
---
diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c
index ccf589b..6c43af5 100644
--- a/gtk/gtkscale.c
+++ b/gtk/gtkscale.c
@@ -266,11 +266,18 @@ gtk_scale_class_init (GtkScaleClass *class)
                   G_TYPE_STRING, 1,
                   G_TYPE_DOUBLE);
 
+  /**
+   * GtkScale:digits:
+   *
+   * The number of decimal places to which the value is rounded when it is
+   * changed. This also sets the number of digits shown in the displayed value
+   * when using the default handler for the #GtkScale:format-value signal.
+   */
   g_object_class_install_property (gobject_class,
                                    PROP_DIGITS,
                                    g_param_spec_int ("digits",
                                                     P_("Digits"),
-                                                    P_("The number of decimal places that are displayed in 
the value"),
+                                                    P_("The number of decimal places to which the value is 
rounded"),
                                                     -1,
                                                     MAX_DIGITS,
                                                     1,
@@ -590,12 +597,11 @@ gtk_scale_new_with_range (GtkOrientation orientation,
 /**
  * gtk_scale_set_digits:
  * @scale: a #GtkScale
- * @digits: the number of decimal places to display, 
- *     e.g. use 1 to display 1.0, 2 to display 1.00, etc
- * 
- * Sets the number of decimal places that are displayed in the value.
- * Also causes the value of the adjustment to be rounded off to this
- * number of digits, so the retrieved value matches the value the user saw.
+ * @digits: the number of decimal places to which the value will be rounded
+ *
+ * Sets the number of decimal places to which the value is rounded when it is
+ * changed. This also sets the number of digits shown in the displayed value
+ * when using the default handler for the #GtkScale:format-value signal.
  */
 void
 gtk_scale_set_digits (GtkScale *scale,
@@ -612,9 +618,8 @@ gtk_scale_set_digits (GtkScale *scale,
   if (scale->digits != digits)
     {
       scale->digits = digits;
-      if (scale->draw_value)
-       range->round_digits = digits;
-      
+      range->round_digits = digits;
+
       _gtk_scale_clear_layout (scale);
       gtk_widget_queue_resize (GTK_WIDGET (scale));
 
@@ -626,9 +631,10 @@ gtk_scale_set_digits (GtkScale *scale,
  * gtk_scale_get_digits:
  * @scale: a #GtkScale
  *
- * Gets the number of decimal places that are displayed in the value.
+ * Gets the number of decimal places to which the value is rounded on change.
+ * This number is also used by the default #GtkScale:format-value handler.
  *
- * Returns: the number of decimal places that are displayed
+ * Returns: the number of decimal places
  */
 gint
 gtk_scale_get_digits (GtkScale *scale)
@@ -657,10 +663,6 @@ gtk_scale_set_draw_value (GtkScale *scale,
   if (scale->draw_value != draw_value)
     {
       scale->draw_value = draw_value;
-      if (draw_value)
-       GTK_RANGE (scale)->round_digits = scale->digits;
-      else
-       GTK_RANGE (scale)->round_digits = -1;
 
       _gtk_scale_clear_layout (scale);
 


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