1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:07:45 +00:00

LibGfx: Add Rect::centered_within(Rect)

I've wanted this API a number of times but never added it.
This commit is contained in:
Andreas Kling 2021-08-30 22:03:04 +02:00
parent de0861581e
commit 43220568b0

View file

@ -641,6 +641,14 @@ public:
center_vertically_within(other);
}
[[nodiscard]] Rect centered_within(Rect const& other) const
{
Rect rect { *this };
rect.center_horizontally_within(other);
rect.center_vertically_within(other);
return rect;
}
void center_horizontally_within(Rect<T> const& other)
{
set_x(other.center().x() - width() / 2);