mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:37:35 +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:
parent
de0861581e
commit
43220568b0
1 changed files with 8 additions and 0 deletions
|
@ -641,6 +641,14 @@ public:
|
||||||
center_vertically_within(other);
|
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)
|
void center_horizontally_within(Rect<T> const& other)
|
||||||
{
|
{
|
||||||
set_x(other.center().x() - width() / 2);
|
set_x(other.center().x() - width() / 2);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue