GDialog: If no parent window is provided, center dialog on screen.

This commit is contained in:
Andreas Kling 2019-05-10 22:22:03 +02:00
parent 3a2f10fbbe
commit 9d2b46f396

View file

@ -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;