From 951a4292684d57a10acdc0672cc907608496358b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Lormeau?= Date: Mon, 29 Jun 2020 14:15:27 +0200 Subject: [PATCH] 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. --- Libraries/LibGUI/SpinBox.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Libraries/LibGUI/SpinBox.cpp b/Libraries/LibGUI/SpinBox.cpp index 86bd10cfbb..45d61f28c0 100644 --- a/Libraries/LibGUI/SpinBox.cpp +++ b/Libraries/LibGUI/SpinBox.cpp @@ -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(); }