spinbutton: Fix a corner case

Fix a bug where a zero increment would make the value unsettable,
when the more natural operation is to allow any value to be set.
This commit is contained in:
Matthias Clasen
2024-04-04 14:11:10 +02:00
parent eeca751fdc
commit cd556c3811

View File

@@ -1524,17 +1524,18 @@ gtk_spin_button_snap (GtkSpinButton *spin_button,
double val)
{
double inc;
double tmp;
inc = gtk_adjustment_get_step_increment (spin_button->adjustment);
if (inc == 0)
return;
if (inc != 0)
{
double tmp;
tmp = (val - gtk_adjustment_get_lower (spin_button->adjustment)) / inc;
if (tmp - floor (tmp) < ceil (tmp) - tmp)
val = gtk_adjustment_get_lower (spin_button->adjustment) + floor (tmp) * inc;
else
val = gtk_adjustment_get_lower (spin_button->adjustment) + ceil (tmp) * inc;
tmp = (val - gtk_adjustment_get_lower (spin_button->adjustment)) / inc;
if (tmp - floor (tmp) < ceil (tmp) - tmp)
val = gtk_adjustment_get_lower (spin_button->adjustment) + floor (tmp) * inc;
else
val = gtk_adjustment_get_lower (spin_button->adjustment) + ceil (tmp) * inc;
}
gtk_spin_button_set_value (spin_button, val);
}