mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 13:27:35 +00:00
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.
This commit is contained in:
parent
47531a42a9
commit
55dbfd24c0
2 changed files with 9 additions and 0 deletions
|
@ -71,6 +71,7 @@ void InputBox::build(InputType input_type)
|
||||||
|
|
||||||
switch (input_type) {
|
switch (input_type) {
|
||||||
case InputType::Text:
|
case InputType::Text:
|
||||||
|
case InputType::NonemptyText:
|
||||||
m_text_editor = label_editor_container.add<TextBox>();
|
m_text_editor = label_editor_container.add<TextBox>();
|
||||||
break;
|
break;
|
||||||
case InputType::Password:
|
case InputType::Password:
|
||||||
|
@ -113,6 +114,13 @@ void InputBox::build(InputType input_type)
|
||||||
};
|
};
|
||||||
m_text_editor->set_focus(true);
|
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());
|
set_rect(x(), y(), max_width + 140, widget->effective_preferred_size().height().as_int());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace GUI {
|
||||||
|
|
||||||
enum class InputType {
|
enum class InputType {
|
||||||
Text,
|
Text,
|
||||||
|
NonemptyText,
|
||||||
Password
|
Password
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue