mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:37:34 +00:00
GDialog: If no parent window is provided, center dialog on screen.
This commit is contained in:
parent
3a2f10fbbe
commit
9d2b46f396
1 changed files with 5 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <LibGUI/GDialog.h>
|
#include <LibGUI/GDialog.h>
|
||||||
#include <LibGUI/GEventLoop.h>
|
#include <LibGUI/GEventLoop.h>
|
||||||
|
#include <LibGUI/GDesktop.h>
|
||||||
|
|
||||||
GDialog::GDialog(CObject* parent)
|
GDialog::GDialog(CObject* parent)
|
||||||
: GWindow(parent)
|
: GWindow(parent)
|
||||||
|
@ -16,12 +17,14 @@ int GDialog::exec()
|
||||||
{
|
{
|
||||||
ASSERT(!m_event_loop);
|
ASSERT(!m_event_loop);
|
||||||
m_event_loop = make<GEventLoop>();
|
m_event_loop = make<GEventLoop>();
|
||||||
|
auto new_rect = rect();
|
||||||
if (parent() && parent()->is_window()) {
|
if (parent() && parent()->is_window()) {
|
||||||
auto& parent_window = *static_cast<GWindow*>(parent());
|
auto& parent_window = *static_cast<GWindow*>(parent());
|
||||||
auto new_rect = rect();
|
|
||||||
new_rect.center_within(parent_window.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();
|
show();
|
||||||
auto result = m_event_loop->exec();
|
auto result = m_event_loop->exec();
|
||||||
m_event_loop = nullptr;
|
m_event_loop = nullptr;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue