From ec29d3abae506df830506ca3d3a15a76c5a4192b Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Wed, 10 May 2023 17:01:19 -0400 Subject: [PATCH] LibGUI: Allow setting and clearing text in SpinBox --- Userland/Libraries/LibGUI/SpinBox.cpp | 8 ++++++++ Userland/Libraries/LibGUI/SpinBox.h | 1 + 2 files changed, 9 insertions(+) diff --git a/Userland/Libraries/LibGUI/SpinBox.cpp b/Userland/Libraries/LibGUI/SpinBox.cpp index 3886d4a594..9cf77e1446 100644 --- a/Userland/Libraries/LibGUI/SpinBox.cpp +++ b/Userland/Libraries/LibGUI/SpinBox.cpp @@ -78,6 +78,9 @@ void SpinBox::set_value(int value, AllowCallback allow_callback) void SpinBox::set_value_from_current_text() { + if (m_editor->text().is_empty()) + return; + auto value = m_editor->text().to_int(); if (value.has_value()) set_value(value.value()); @@ -85,6 +88,11 @@ void SpinBox::set_value_from_current_text() set_value(min()); } +void SpinBox::set_text(StringView text, AllowCallback allow_callback) +{ + m_editor->set_text(text, allow_callback); +} + void SpinBox::set_range(int min, int max, AllowCallback allow_callback) { VERIFY(min <= max); diff --git a/Userland/Libraries/LibGUI/SpinBox.h b/Userland/Libraries/LibGUI/SpinBox.h index 46098d79ec..c79ed42b35 100644 --- a/Userland/Libraries/LibGUI/SpinBox.h +++ b/Userland/Libraries/LibGUI/SpinBox.h @@ -19,6 +19,7 @@ public: int value() const { return m_value; } void set_value(int, AllowCallback = AllowCallback::Yes); void set_value_from_current_text(); + void set_text(StringView, AllowCallback = AllowCallback::Yes); int min() const { return m_min; } int max() const { return m_max; }