mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 14:07:43 +00:00
LibGUI: Add InputType enum to allow creating a password InputBox dialog
This commit is contained in:
parent
5745e8e18c
commit
81c183e06a
2 changed files with 22 additions and 9 deletions
|
@ -15,23 +15,23 @@
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
InputBox::InputBox(Window* parent_window, String& text_value, StringView const& prompt, StringView const& title, StringView const& placeholder)
|
InputBox::InputBox(Window* parent_window, String& text_value, StringView const& prompt, StringView const& title, StringView const& placeholder, InputType input_type)
|
||||||
: Dialog(parent_window)
|
: Dialog(parent_window)
|
||||||
, m_text_value(text_value)
|
, m_text_value(text_value)
|
||||||
, m_prompt(prompt)
|
, m_prompt(prompt)
|
||||||
, m_placeholder(placeholder)
|
, m_placeholder(placeholder)
|
||||||
{
|
{
|
||||||
set_title(title);
|
set_title(title);
|
||||||
build();
|
build(input_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
InputBox::~InputBox()
|
InputBox::~InputBox()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int InputBox::show(Window* parent_window, String& text_value, StringView const& prompt, StringView const& title, StringView const& placeholder)
|
int InputBox::show(Window* parent_window, String& text_value, StringView const& prompt, StringView const& title, StringView const& placeholder, InputType input_type)
|
||||||
{
|
{
|
||||||
auto box = InputBox::construct(parent_window, text_value, prompt, title, placeholder);
|
auto box = InputBox::construct(parent_window, text_value, prompt, title, placeholder, input_type);
|
||||||
box->set_resizable(false);
|
box->set_resizable(false);
|
||||||
if (parent_window)
|
if (parent_window)
|
||||||
box->set_icon(parent_window->icon());
|
box->set_icon(parent_window->icon());
|
||||||
|
@ -40,7 +40,7 @@ int InputBox::show(Window* parent_window, String& text_value, StringView const&
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputBox::build()
|
void InputBox::build(InputType input_type)
|
||||||
{
|
{
|
||||||
auto& widget = set_main_widget<Widget>();
|
auto& widget = set_main_widget<Widget>();
|
||||||
|
|
||||||
|
@ -62,7 +62,15 @@ void InputBox::build()
|
||||||
auto& label = label_editor_container.add<Label>(m_prompt);
|
auto& label = label_editor_container.add<Label>(m_prompt);
|
||||||
label.set_fixed_size(text_width, 16);
|
label.set_fixed_size(text_width, 16);
|
||||||
|
|
||||||
m_text_editor = label_editor_container.add<TextBox>();
|
switch (input_type) {
|
||||||
|
case InputType::Text:
|
||||||
|
m_text_editor = label_editor_container.add<TextBox>();
|
||||||
|
break;
|
||||||
|
case InputType::Password:
|
||||||
|
m_text_editor = label_editor_container.add<PasswordBox>();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
m_text_editor->set_fixed_height(19);
|
m_text_editor->set_fixed_height(19);
|
||||||
m_text_editor->set_text(m_text_value);
|
m_text_editor->set_text(m_text_value);
|
||||||
|
|
||||||
|
|
|
@ -11,19 +11,24 @@
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
|
enum class InputType {
|
||||||
|
Text,
|
||||||
|
Password
|
||||||
|
};
|
||||||
|
|
||||||
class InputBox : public Dialog {
|
class InputBox : public Dialog {
|
||||||
C_OBJECT(InputBox)
|
C_OBJECT(InputBox)
|
||||||
public:
|
public:
|
||||||
virtual ~InputBox() override;
|
virtual ~InputBox() override;
|
||||||
|
|
||||||
static int show(Window* parent_window, String& text_value, StringView const& prompt, StringView const& title, StringView const& placeholder = {});
|
static int show(Window* parent_window, String& text_value, StringView const& prompt, StringView const& title, StringView const& placeholder = {}, InputType input_type = InputType::Text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit InputBox(Window* parent_window, String& text_value, StringView const& prompt, StringView const& title, StringView const& placeholder);
|
explicit InputBox(Window* parent_window, String& text_value, StringView const& prompt, StringView const& title, StringView const& placeholder, InputType input_type);
|
||||||
|
|
||||||
String text_value() const { return m_text_value; }
|
String text_value() const { return m_text_value; }
|
||||||
|
|
||||||
void build();
|
void build(InputType input_type);
|
||||||
String m_text_value;
|
String m_text_value;
|
||||||
String m_prompt;
|
String m_prompt;
|
||||||
String m_placeholder;
|
String m_placeholder;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue