summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-08-30 22:18:20 +0200
committerAndreas Kling <kling@serenityos.org>2021-08-31 01:35:08 +0200
commit087bd7f767d706af2ac9357410b70bcb6db88b6d (patch)
tree1fe6f05bd1bbb28b4b7b1742b5fbedf8b1720bd3 /Userland/Libraries/LibGUI
parent43220568b058861d08450793c3269914392d250c (diff)
downloadserenity-087bd7f767d706af2ac9357410b70bcb6db88b6d.zip
Userland: Use Rect::centered_within() where useful
Diffstat (limited to 'Userland/Libraries/LibGUI')
-rw-r--r--Userland/Libraries/LibGUI/FileSystemModel.cpp3
-rw-r--r--Userland/Libraries/LibGUI/IconView.cpp3
-rw-r--r--Userland/Libraries/LibGUI/Window.cpp8
3 files changed, 4 insertions, 10 deletions
diff --git a/Userland/Libraries/LibGUI/FileSystemModel.cpp b/Userland/Libraries/LibGUI/FileSystemModel.cpp
index 144fd6ff63..861280583c 100644
--- a/Userland/Libraries/LibGUI/FileSystemModel.cpp
+++ b/Userland/Libraries/LibGUI/FileSystemModel.cpp
@@ -613,8 +613,7 @@ static RefPtr<Gfx::Bitmap> render_thumbnail(const StringView& path)
double scale = min(32 / (double)png_bitmap->width(), 32 / (double)png_bitmap->height());
auto thumbnail = Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRA8888, { 32, 32 });
- Gfx::IntRect destination = Gfx::IntRect(0, 0, (int)(png_bitmap->width() * scale), (int)(png_bitmap->height() * scale));
- destination.center_within(thumbnail->rect());
+ auto destination = Gfx::IntRect(0, 0, (int)(png_bitmap->width() * scale), (int)(png_bitmap->height() * scale)).centered_within(thumbnail->rect());
Painter painter(*thumbnail);
painter.draw_scaled_bitmap(destination, *png_bitmap, png_bitmap->rect());
diff --git a/Userland/Libraries/LibGUI/IconView.cpp b/Userland/Libraries/LibGUI/IconView.cpp
index f4333b2c36..0718515be4 100644
--- a/Userland/Libraries/LibGUI/IconView.cpp
+++ b/Userland/Libraries/LibGUI/IconView.cpp
@@ -433,8 +433,7 @@ void IconView::did_change_cursor_index(const ModelIndex& old_index, const ModelI
void IconView::get_item_rects(int item_index, ItemData& item_data, const Gfx::Font& font) const
{
auto item_rect = this->item_rect(item_index);
- item_data.icon_rect = { 0, 0, 32, 32 };
- item_data.icon_rect.center_within(item_rect);
+ item_data.icon_rect = Gfx::IntRect(0, 0, 32, 32).centered_within(item_rect);
item_data.icon_offset_y = -font.glyph_height() - 6;
item_data.icon_rect.translate_by(0, item_data.icon_offset_y);
diff --git a/Userland/Libraries/LibGUI/Window.cpp b/Userland/Libraries/LibGUI/Window.cpp
index 92d6dd570a..3156e0f04f 100644
--- a/Userland/Libraries/LibGUI/Window.cpp
+++ b/Userland/Libraries/LibGUI/Window.cpp
@@ -286,18 +286,14 @@ void Window::set_minimum_size(const Gfx::IntSize& size)
void Window::center_on_screen()
{
- auto window_rect = rect();
- window_rect.center_within(Desktop::the().rect());
- set_rect(window_rect);
+ set_rect(rect().centered_within(Desktop::the().rect()));
}
void Window::center_within(const Window& other)
{
if (this == &other)
return;
- auto window_rect = rect();
- window_rect.center_within(other.rect());
- set_rect(window_rect);
+ set_rect(rect().centered_within(other.rect()));
}
void Window::set_window_type(WindowType window_type)