1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:38:11 +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

@ -137,9 +137,8 @@ static bool prompt_to_stop_profiling()
auto window = GUI::Window::construct();
window->set_title("Profiling");
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-profiler.png"));
Gfx::IntRect window_rect { 0, 0, 320, 200 };
window_rect.center_within(GUI::Desktop::the().rect());
window->set_rect(window_rect);
window->resize(320, 200);
window->center_on_screen();
auto& widget = window->set_main_widget<GUI::Widget>();
widget.set_fill_with_background_color(true);
widget.set_layout<GUI::VerticalBoxLayout>();