From 7c314f38554ab95e0380cced9cf352b606391f96 Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Sun, 16 Apr 2023 16:02:29 -0400 Subject: [PATCH] LibGUI: Let InputBox display an ImageWidget InputBox can now be given a bitmap to display alongside its prompt and editor. Prompts are now optional to allow for compact dialogs. --- Userland/Libraries/LibGUI/InputBox.cpp | 44 +++++++++++++++++++------- Userland/Libraries/LibGUI/InputBox.h | 10 +++--- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Userland/Libraries/LibGUI/InputBox.cpp b/Userland/Libraries/LibGUI/InputBox.cpp index 85e5e93353..9bcb68f2bf 100644 --- a/Userland/Libraries/LibGUI/InputBox.cpp +++ b/Userland/Libraries/LibGUI/InputBox.cpp @@ -8,38 +8,40 @@ #include #include +#include #include #include #include namespace GUI { -ErrorOr> InputBox::create(Window* parent_window, String text_value, StringView prompt, StringView title, InputType input_type) +ErrorOr> InputBox::create(Window* parent_window, String text_value, StringView prompt, StringView title, InputType input_type, RefPtr icon) { - auto box = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) InputBox(parent_window, text_value, TRY(String::from_utf8(title)), TRY(String::from_utf8(prompt)), input_type))); + auto box = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) InputBox(parent_window, text_value, TRY(String::from_utf8(title)), TRY(String::from_utf8(prompt)), input_type, move(icon)))); TRY(box->build()); return box; } -InputBox::InputBox(Window* parent_window, String text_value, String title, String prompt, InputType input_type) +InputBox::InputBox(Window* parent_window, String text_value, String title, String prompt, InputType input_type, RefPtr icon) : Dialog(parent_window) , m_text_value(move(text_value)) , m_prompt(move(prompt)) , m_input_type(input_type) + , m_icon(move(icon)) { set_title(move(title).to_deprecated_string()); set_resizable(false); set_auto_shrink(true); } -Dialog::ExecResult InputBox::show(Window* parent_window, String& text_value, StringView prompt, StringView title, InputType input_type, StringView placeholder) +Dialog::ExecResult InputBox::show(Window* parent_window, String& text_value, StringView prompt, StringView title, InputType input_type, StringView placeholder, RefPtr icon) { - return MUST(try_show(parent_window, text_value, prompt, title, input_type, placeholder)); + return MUST(try_show(parent_window, text_value, prompt, title, input_type, placeholder, move(icon))); } -ErrorOr InputBox::try_show(Window* parent_window, String& text_value, StringView prompt, StringView title, InputType input_type, StringView placeholder) +ErrorOr InputBox::try_show(Window* parent_window, String& text_value, StringView prompt, StringView title, InputType input_type, StringView placeholder, RefPtr icon) { - auto box = TRY(InputBox::create(parent_window, text_value, prompt, title, input_type)); + auto box = TRY(InputBox::create(parent_window, text_value, prompt, title, input_type, move(icon))); if (parent_window) box->set_icon(parent_window->icon()); box->set_placeholder(placeholder); @@ -86,15 +88,29 @@ ErrorOr InputBox::build() TRY(main_widget->try_set_layout(4, 6)); main_widget->set_fill_with_background_color(true); - auto input_container = TRY(main_widget->try_add()); - input_container->set_layout(); + auto top_container = TRY(main_widget->try_add()); + TRY(top_container->try_set_layout(0, 8)); - m_prompt_label = TRY(input_container->try_add