From 55dbfd24c069a967a5ae6f364c3879b05b3db207 Mon Sep 17 00:00:00 2001 From: Karol Baraniecki Date: Sat, 14 Jan 2023 15:14:47 -0700 Subject: [PATCH] LibGUI: Allow the InputBox to be of NonemptyText type It seems like a lot (most?) places where InputBoxes are used check if the retrieved string isn't empty anyway - make this be reflected in the user interface, by disabling (graying out) the "OK" button when nothing is entered, so empty input isn't a viable option at all. --- Userland/Libraries/LibGUI/InputBox.cpp | 8 ++++++++ Userland/Libraries/LibGUI/InputBox.h | 1 + 2 files changed, 9 insertions(+) diff --git a/Userland/Libraries/LibGUI/InputBox.cpp b/Userland/Libraries/LibGUI/InputBox.cpp index aae71d07b6..e809a33cf6 100644 --- a/Userland/Libraries/LibGUI/InputBox.cpp +++ b/Userland/Libraries/LibGUI/InputBox.cpp @@ -71,6 +71,7 @@ void InputBox::build(InputType input_type) switch (input_type) { case InputType::Text: + case InputType::NonemptyText: m_text_editor = label_editor_container.add(); break; case InputType::Password: @@ -113,6 +114,13 @@ void InputBox::build(InputType input_type) }; m_text_editor->set_focus(true); + if (input_type == InputType::NonemptyText) { + m_text_editor->on_change = [this] { + m_ok_button->set_enabled(!m_text_editor->text().is_empty()); + }; + m_text_editor->on_change(); + } + set_rect(x(), y(), max_width + 140, widget->effective_preferred_size().height().as_int()); } diff --git a/Userland/Libraries/LibGUI/InputBox.h b/Userland/Libraries/LibGUI/InputBox.h index 83d56d5579..fa28edfe20 100644 --- a/Userland/Libraries/LibGUI/InputBox.h +++ b/Userland/Libraries/LibGUI/InputBox.h @@ -14,6 +14,7 @@ namespace GUI { enum class InputType { Text, + NonemptyText, Password };