Commit f23e99b0 authored by Matthias Clasen's avatar Matthias Clasen

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
parent 7f06f281
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment