1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 08:35:09 +00:00

LibGUI: Add and use Window::center_on_screen()

Various applications were using the same slightly verbose code to center
themselves on the screen/desktop:

Gfx::IntRect window_rect { 0, 0, width, height };
window_rect.center_within(GUI::Desktop::the().rect());
window->set_rect(window_rect);

Which now becomes:

window->resize(width, height);
window->center_on_screen();
This commit is contained in:
Linus Groh 2020-08-15 16:32:11 +02:00 committed by Andreas Kling
parent 5f724b6ca1
commit 0cab3bca2f
6 changed files with 18 additions and 16 deletions

View file

@ -32,6 +32,7 @@
#include <LibCore/MimeData.h>
#include <LibGUI/Action.h>
#include <LibGUI/Application.h>
#include <LibGUI/Desktop.h>
#include <LibGUI/Event.h>
#include <LibGUI/Painter.h>
#include <LibGUI/Widget.h>
@ -212,6 +213,13 @@ void Window::set_rect(const Gfx::IntRect& a_rect)
m_main_widget->resize(window_rect.size());
}
void Window::center_on_screen()
{
auto window_rect = rect();
window_rect.center_within(Desktop::the().rect());
set_rect(window_rect);
}
void Window::set_window_type(WindowType window_type)
{
m_window_type = window_type;