mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:47:35 +00:00
Userland: Use Rect::centered_within() where useful
This commit is contained in:
parent
43220568b0
commit
087bd7f767
9 changed files with 15 additions and 34 deletions
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue