libgimpwidgets: fix #10821 Problem with LabelSpin widget

For certain min/max values of the LabelSpin widget, in combination with
zero digits, it proves impossible to change the initial value.
The reason for this is that the step size may become less than 1.0.
In which case, stepping doesn't work because the number of digits is
set to zero.

Let's check for this situation and when digits is zero set the step
to 1.0 and make sure that page is at least the same value.

While testing this I also noticed another issue: when initializing
the upper value was set to 0.0 and the lower to 1.0 which leads to
a critical because lower > upper.
We fix this by switching the initial upper and lower values.
This commit is contained in:
Jacob Boerema 2024-04-16 21:44:12 -04:00
parent b71464804d
commit ae2cf562e8
1 changed files with 11 additions and 2 deletions

View File

@ -135,7 +135,7 @@ gimp_label_spin_class_init (GimpLabelSpinClass *klass)
g_object_class_install_property (object_class, PROP_LOWER,
g_param_spec_double ("lower", NULL,
"Minimum value",
-G_MAXDOUBLE, G_MAXDOUBLE, 1.0,
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
@ -149,7 +149,7 @@ gimp_label_spin_class_init (GimpLabelSpinClass *klass)
g_object_class_install_property (object_class, PROP_UPPER,
g_param_spec_double ("upper", NULL,
"Max value",
-G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
-G_MAXDOUBLE, G_MAXDOUBLE, 1.0,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
@ -339,6 +339,7 @@ gimp_label_spin_update_settings (GimpLabelSpin *spin)
gdouble step;
gdouble page;
gint digits = priv->digits;
gboolean adjust_step = (digits == 0);
g_return_if_fail (GIMP_IS_LABEL_SPIN (spin));
@ -351,6 +352,14 @@ gimp_label_spin_update_settings (GimpLabelSpin *spin)
gimp_range_estimate_settings (lower, upper, &step, &page,
digits < 0 ? &digits: NULL);
if (adjust_step && digits == 0 && step < 1.0)
{
step = 1.0;
if (page < step)
page = step;
}
gimp_label_spin_set_increments (spin, step, page);
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (priv->spinbutton), (guint) digits);
gimp_label_spin_update_spin_width (spin, lower, upper, (guint) digits);