From ae2cf562e8b57b53f5c43afbef1948ea5ce78d31 Mon Sep 17 00:00:00 2001 From: Jacob Boerema Date: Tue, 16 Apr 2024 21:44:12 -0400 Subject: [PATCH] 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. --- libgimpwidgets/gimplabelspin.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libgimpwidgets/gimplabelspin.c b/libgimpwidgets/gimplabelspin.c index 8506c54448..e94cd9c7ba 100644 --- a/libgimpwidgets/gimplabelspin.c +++ b/libgimpwidgets/gimplabelspin.c @@ -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);