mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 13:05:07 +00:00
LibGUI: Implement nested event loops to support dialog boxes.
This patch adds a simple GMessageBox that can run in a nested event loop. Here's how you use it: GMessageBox box("Message text here", "Message window title"); int result = box.exec(); The next step is to make the WindowServer respect the modality flag of these windows and prevent interaction with other windows in the same process until the modal window has been closed.
This commit is contained in:
parent
55aa819077
commit
57ff293a51
29 changed files with 275 additions and 79 deletions
45
LibGUI/GMessageBox.cpp
Normal file
45
LibGUI/GMessageBox.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include <LibGUI/GMessageBox.h>
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GLabel.h>
|
||||
#include <LibGUI/GButton.h>
|
||||
|
||||
GMessageBox::GMessageBox(const String& text, const String& title, GObject* parent)
|
||||
: GDialog(parent)
|
||||
, m_text(text)
|
||||
{
|
||||
set_title(title);
|
||||
build();
|
||||
}
|
||||
|
||||
GMessageBox::~GMessageBox()
|
||||
{
|
||||
}
|
||||
|
||||
void GMessageBox::build()
|
||||
{
|
||||
auto* widget = new GWidget;
|
||||
set_main_widget(widget);
|
||||
|
||||
int text_width = widget->font().width(m_text);
|
||||
|
||||
set_rect(x(), y(), text_width + 80, 80);
|
||||
|
||||
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
widget->set_fill_with_background_color(true);
|
||||
|
||||
widget->layout()->set_margins({ 0, 15, 0, 15 });
|
||||
widget->layout()->set_spacing(15);
|
||||
|
||||
auto* label = new GLabel(m_text, widget);
|
||||
label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
label->set_preferred_size({ text_width, 16 });
|
||||
|
||||
auto* button = new GButton(widget);
|
||||
button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||
button->set_preferred_size({ 100, 16 });
|
||||
button->set_caption("OK");
|
||||
button->on_click = [this] (auto&) {
|
||||
dbgprintf("OK button clicked\n");
|
||||
done(0);
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue