mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-16 15:14:17 +00:00
scale, spinbutton: Avoid -0.0
This is a very longstanding bug; time to finally put it to rest. https://bugzilla.gnome.org/show_bug.cgi?id=118959
This commit is contained in:
parent
7f06f2818a
commit
f23e99b063
@ -1933,6 +1933,19 @@ gtk_scale_real_get_layout_offsets (GtkScale *scale,
|
||||
*y = value_alloc.y;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
weed_out_neg_zero (gchar *str, gint digits)
|
||||
{
|
||||
if (str[0] == '-')
|
||||
{
|
||||
gchar neg_zero[8];
|
||||
snprintf (neg_zero, 8, "%0.*f", digits, -0.0);
|
||||
if (strcmp (neg_zero, str) == 0)
|
||||
memmove (str, str + 1, strlen (str) - 1);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Emits #GtkScale::format-value signal to format the value,
|
||||
* if no user signal handlers, falls back to a default format.
|
||||
@ -1950,7 +1963,10 @@ gtk_scale_format_value (GtkScale *scale,
|
||||
if (fmt)
|
||||
return fmt;
|
||||
else
|
||||
return g_strdup_printf ("%0.*f", scale->priv->digits, value);
|
||||
{
|
||||
fmt = g_strdup_printf ("%0.*f", scale->priv->digits, value);
|
||||
return weed_out_neg_zero (fmt, scale->priv->digits);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1115,6 +1115,19 @@ measure_string_width (PangoLayout *layout,
|
||||
return width;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
weed_out_neg_zero (gchar *str, gint digits)
|
||||
{
|
||||
if (str[0] == '-')
|
||||
{
|
||||
gchar neg_zero[8];
|
||||
snprintf (neg_zero, 8, "%0.*f", digits, -0.0);
|
||||
if (strcmp (neg_zero, str) == 0)
|
||||
memmove (str, str + 1, strlen (str) - 1);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
gtk_spin_button_format_for_value (GtkSpinButton *spin_button,
|
||||
gdouble value)
|
||||
@ -1122,7 +1135,7 @@ gtk_spin_button_format_for_value (GtkSpinButton *spin_button,
|
||||
GtkSpinButtonPrivate *priv = spin_button->priv;
|
||||
gchar *buf = g_strdup_printf ("%0.*f", priv->digits, value);
|
||||
|
||||
return buf;
|
||||
return weed_out_neg_zero (buf, priv->digits);
|
||||
}
|
||||
|
||||
gint
|
||||
|
Loading…
Reference in New Issue
Block a user