LibGUI: SpinBox: update the displayed value when set_range() clamps it

Consider the following: upon instanciation of a GUI::SpinBox, its
internal value and displayed value are both 0. When calling `set_min(1)`
on it (same as `set_range(1, max())`), the internal value gets clamped
to 1 correctly, but "0" is still displayed by the widget.

The displayed value is now updated accordingly to the internal value
when it gets clamped.
This commit is contained in:
Benoît Lormeau 2020-06-29 14:15:27 +02:00 committed by Andreas Kling
parent 48cd26f12d
commit 951a429268
Notes: sideshowbarker 2024-07-19 05:19:44 +09:00

View file

@ -80,8 +80,11 @@ void SpinBox::set_range(int min, int max)
int old_value = m_value;
m_value = clamp(m_value, m_min, m_max);
if (on_change && m_value != old_value)
on_change(m_value);
if (m_value != old_value) {
m_editor->set_text(String::number(m_value));
if (on_change)
on_change(m_value);
}
update();
}