1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

LibGUI: Allow InputBox to show placeholder

If passed as an argument, showing an InputBox now supports to
set a placeholder text which will be shown in its TextBox.
This commit is contained in:
networkException 2021-07-06 16:47:44 +02:00 committed by Andreas Kling
parent f8798c154b
commit 72776b2f61
2 changed files with 12 additions and 5 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Jakob-Niklas See <git@nwex.de>
*
* 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<Widget>();
button_container_outer.set_fixed_height(20);
button_container_outer.set_layout<VerticalBoxLayout>();