mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:48:14 +00:00
LibGUI: Allow more programmatic control over GUI::InputBox
This will be needed for WebDriver, which will require constructing and controlling dialogs manually. Currently, InputBox will only set its text value when the OK button is pressed. This changes InputBox to update its text when done(ExecResult::OK) is invoked in any way. This also makes the text_value() method public, allows for setting the text value, and allows for moving-in the initial text value.
This commit is contained in:
parent
db4fa36b58
commit
5b31a3dbc7
4 changed files with 23 additions and 6 deletions
|
@ -15,9 +15,9 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
InputBox::InputBox(Window* parent_window, String& text_value, StringView prompt, StringView title, StringView placeholder, InputType input_type)
|
||||
InputBox::InputBox(Window* parent_window, String text_value, StringView prompt, StringView title, StringView placeholder, InputType input_type)
|
||||
: Dialog(parent_window)
|
||||
, m_text_value(text_value)
|
||||
, m_text_value(move(text_value))
|
||||
, m_prompt(prompt)
|
||||
, m_placeholder(placeholder)
|
||||
{
|
||||
|
@ -36,6 +36,17 @@ Dialog::ExecResult InputBox::show(Window* parent_window, String& text_value, Str
|
|||
return result;
|
||||
}
|
||||
|
||||
void InputBox::set_text_value(String text_value)
|
||||
{
|
||||
m_text_editor->set_text(move(text_value));
|
||||
}
|
||||
|
||||
void InputBox::on_done(ExecResult result)
|
||||
{
|
||||
if (result == ExecResult::OK)
|
||||
m_text_value = m_text_editor->text();
|
||||
}
|
||||
|
||||
void InputBox::build(InputType input_type)
|
||||
{
|
||||
auto& widget = set_main_widget<Widget>();
|
||||
|
@ -86,7 +97,6 @@ void InputBox::build(InputType input_type)
|
|||
m_ok_button->set_text("OK");
|
||||
m_ok_button->on_click = [this](auto) {
|
||||
dbgln("GUI::InputBox: OK button clicked");
|
||||
m_text_value = m_text_editor->text();
|
||||
done(ExecResult::OK);
|
||||
};
|
||||
m_ok_button->set_default(true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue