[gtk+] spin button: Limit the entry width to reasonable values



commit 4ab91f09cf0b225d399bcc0d19df9fc91aabbe5c
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Mar 5 23:41:10 2016 -0500

    spin button: Limit the entry width to reasonable values
    
    When opening the value editor for any GtkAdjustment properties
    in the inspector, the popover stretches out for miles, since
    it reserves enough space to draw MAXDOUBLE. This is not useful.
    Limit the space we reserve to 8 digits.

 gtk/gtkspinbutton.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index f24a98f..0219575 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -1132,20 +1132,21 @@ gtk_spin_button_get_text_width (GtkSpinButton *spin_button)
   gint width, w;
   PangoLayout *layout;
   gchar *str;
+  gdouble value;
 
   layout = pango_layout_copy (gtk_entry_get_layout (GTK_ENTRY (spin_button)));
 
   /* Get max of MIN_SPIN_BUTTON_WIDTH, size of upper, size of lower */
   width = MIN_SPIN_BUTTON_WIDTH;
 
-  str = gtk_spin_button_format_for_value (spin_button,
-                                          gtk_adjustment_get_upper (priv->adjustment));
+  value = CLAMP (gtk_adjustment_get_upper (priv->adjustment), -1e7, 1e7);
+  str = gtk_spin_button_format_for_value (spin_button, value);
   w = measure_string_width (layout, str);
   width = MAX (width, w);
   g_free (str);
 
-  str = gtk_spin_button_format_for_value (spin_button,
-                                          gtk_adjustment_get_lower (priv->adjustment));
+  value = CLAMP (gtk_adjustment_get_lower (priv->adjustment), -1e7, 1e7);
+  str = gtk_spin_button_format_for_value (spin_button, value);
   w = measure_string_width (layout, str);
   width = MAX (width, w);
   g_free (str);


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