diff --git a/Userland/Libraries/LibGUI/InputBox.cpp b/Userland/Libraries/LibGUI/InputBox.cpp index f3c73e3106..3ea6f03a2e 100644 --- a/Userland/Libraries/LibGUI/InputBox.cpp +++ b/Userland/Libraries/LibGUI/InputBox.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2021, Jakob-Niklas See * * SPDX-License-Identifier: BSD-2-Clause */ @@ -14,10 +15,11 @@ namespace GUI { -InputBox::InputBox(Window* parent_window, String& text_value, const StringView& prompt, const StringView& title) +InputBox::InputBox(Window* parent_window, String& text_value, const StringView& prompt, const StringView& title, const StringView& placeholder) : Dialog(parent_window) , m_text_value(text_value) , m_prompt(prompt) + , m_placeholder(placeholder) { set_title(title); build(); @@ -27,9 +29,9 @@ InputBox::~InputBox() { } -int InputBox::show(Window* parent_window, String& text_value, const StringView& prompt, const StringView& title) +int InputBox::show(Window* parent_window, String& text_value, const StringView& prompt, const StringView& title, const StringView& placeholder) { - auto box = InputBox::construct(parent_window, text_value, prompt, title); + auto box = InputBox::construct(parent_window, text_value, prompt, title, placeholder); box->set_resizable(false); if (parent_window) box->set_icon(parent_window->icon()); @@ -64,6 +66,9 @@ void InputBox::build() m_text_editor->set_fixed_height(19); m_text_editor->set_text(m_text_value); + if (!m_placeholder.is_null()) + m_text_editor->set_placeholder(m_placeholder); + auto& button_container_outer = widget.add(); button_container_outer.set_fixed_height(20); button_container_outer.set_layout(); diff --git a/Userland/Libraries/LibGUI/InputBox.h b/Userland/Libraries/LibGUI/InputBox.h index fda103a366..1bc1d877d0 100644 --- a/Userland/Libraries/LibGUI/InputBox.h +++ b/Userland/Libraries/LibGUI/InputBox.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2021, Jakob-Niklas See * * SPDX-License-Identifier: BSD-2-Clause */ @@ -15,16 +16,17 @@ class InputBox : public Dialog { public: virtual ~InputBox() override; - static int show(Window* parent_window, String& text_value, const StringView& prompt, const StringView& title); + static int show(Window* parent_window, String& text_value, const StringView& prompt, const StringView& title, const StringView& placeholder = {}); private: - explicit InputBox(Window* parent_window, String& text_value, const StringView& prompt, const StringView& title); + explicit InputBox(Window* parent_window, String& text_value, const StringView& prompt, const StringView& title, const StringView& placeholder); String text_value() const { return m_text_value; } void build(); String m_text_value; String m_prompt; + String m_placeholder; RefPtr