mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 23:25:20 +00:00
LibGUI: More work on GInputBox.
- If the GInputBox has a parent and the parent is a GWindow, center the input box window within the parent window. This looks quite nice. - Stop processing events in a nested event loop immediately after it's been asked to quit. - Fix GWidget::parent_widget() behavior for non-widget parents.
This commit is contained in:
@@ -36,9 +36,9 @@ void GInputBox::build()
|
||||
label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
label->set_preferred_size({ text_width, 16 });
|
||||
|
||||
auto* text_editor = new GTextEditor(GTextEditor::SingleLine, widget);
|
||||
text_editor->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
text_editor->set_preferred_size({ 0, 16 });
|
||||
m_text_editor = new GTextEditor(GTextEditor::SingleLine, widget);
|
||||
m_text_editor->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
m_text_editor->set_preferred_size({ 0, 16 });
|
||||
|
||||
auto* button_container_outer = new GWidget(widget);
|
||||
button_container_outer->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
@@ -47,30 +47,30 @@ void GInputBox::build()
|
||||
button_container_inner->set_layout(make<GBoxLayout>(Orientation::Horizontal));
|
||||
button_container_inner->layout()->set_spacing(8);
|
||||
|
||||
auto* cancel_button = new GButton(button_container_inner);
|
||||
cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
cancel_button->set_preferred_size({ 0, 16 });
|
||||
cancel_button->set_caption("Cancel");
|
||||
cancel_button->on_click = [&] (auto&) {
|
||||
fprintf(stderr, "GInputBox: Cancel button clicked\n");
|
||||
done(1);
|
||||
m_cancel_button = new GButton(button_container_inner);
|
||||
m_cancel_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
m_cancel_button->set_preferred_size({ 0, 16 });
|
||||
m_cancel_button->set_caption("Cancel");
|
||||
m_cancel_button->on_click = [this] (auto&) {
|
||||
dbgprintf("GInputBox: Cancel button clicked\n");
|
||||
done(ExecCancel);
|
||||
};
|
||||
|
||||
auto* ok_button = new GButton(button_container_inner);
|
||||
ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
ok_button->set_preferred_size({ 0, 16 });
|
||||
ok_button->set_caption("OK");
|
||||
ok_button->on_click = [&] (auto&) {
|
||||
fprintf(stderr, "GInputBox: OK button clicked\n");
|
||||
m_text_value = text_editor->text();
|
||||
done(0);
|
||||
m_ok_button = new GButton(button_container_inner);
|
||||
m_ok_button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
m_ok_button->set_preferred_size({ 0, 16 });
|
||||
m_ok_button->set_caption("OK");
|
||||
m_ok_button->on_click = [this] (auto&) {
|
||||
dbgprintf("GInputBox: OK button clicked\n");
|
||||
m_text_value = m_text_editor->text();
|
||||
done(ExecOK);
|
||||
};
|
||||
|
||||
text_editor->on_return_pressed = [&] (auto&) {
|
||||
ok_button->click();
|
||||
m_text_editor->on_return_pressed = [this] (auto&) {
|
||||
m_ok_button->click();
|
||||
};
|
||||
text_editor->on_escape_pressed = [&] (auto&) {
|
||||
cancel_button->click();
|
||||
m_text_editor->on_escape_pressed = [this] (auto&) {
|
||||
m_cancel_button->click();
|
||||
};
|
||||
text_editor->set_focus(true);
|
||||
m_text_editor->set_focus(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user