mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-07 08:29:58 +00:00
GDialog: If no parent window is provided, center dialog on screen.
This commit is contained in:
parent
3a2f10fbbe
commit
9d2b46f396
|
@ -1,5 +1,6 @@
|
|||
#include <LibGUI/GDialog.h>
|
||||
#include <LibGUI/GEventLoop.h>
|
||||
#include <LibGUI/GDesktop.h>
|
||||
|
||||
GDialog::GDialog(CObject* parent)
|
||||
: GWindow(parent)
|
||||
|
@ -16,12 +17,14 @@ int GDialog::exec()
|
|||
{
|
||||
ASSERT(!m_event_loop);
|
||||
m_event_loop = make<GEventLoop>();
|
||||
auto new_rect = rect();
|
||||
if (parent() && parent()->is_window()) {
|
||||
auto& parent_window = *static_cast<GWindow*>(parent());
|
||||
auto new_rect = rect();
|
||||
new_rect.center_within(parent_window.rect());
|
||||
set_rect(new_rect);
|
||||
} else {
|
||||
new_rect.center_within(GDesktop::the().rect());
|
||||
}
|
||||
set_rect(new_rect);
|
||||
show();
|
||||
auto result = m_event_loop->exec();
|
||||
m_event_loop = nullptr;
|
||||
|
|
Loading…
Reference in a new issue