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

LibGfx: Add per-side overloads of Rect::inflate() and ::shrink()

These are in CSS order (top, right, bottom, left) since LibWeb is the
reason I'm adding these. :^)
This commit is contained in:
Sam Atkins 2021-09-19 20:43:56 +01:00 committed by Andreas Kling
parent 0712036485
commit eb07668589

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -121,6 +122,14 @@ public:
set_height(height() + h);
}
void inflate(T top, T right, T bottom, T left)
{
set_x(x() - left);
set_width(width() + left + right);
set_y(y() - top);
set_height(height() + top + bottom);
}
void inflate(Size<T> const& size)
{
set_x(x() - size.width() / 2);
@ -137,6 +146,14 @@ public:
set_height(height() - h);
}
void shrink(T top, T right, T bottom, T left)
{
set_x(x() + left);
set_width(width() - (left + right));
set_y(y() + top);
set_height(height() - (top + bottom));
}
void shrink(Size<T> const& size)
{
set_x(x() + size.width() / 2);
@ -187,6 +204,13 @@ public:
return rect;
}
[[nodiscard]] Rect<T> shrunken(T top, T right, T bottom, T left) const
{
Rect<T> rect = *this;
rect.shrink(top, right, bottom, left);
return rect;
}
[[nodiscard]] Rect<T> shrunken(Size<T> const& size) const
{
Rect<T> rect = *this;
@ -201,6 +225,13 @@ public:
return rect;
}
[[nodiscard]] Rect<T> inflated(T top, T right, T bottom, T left) const
{
Rect<T> rect = *this;
rect.inflate(top, right, bottom, left);
return rect;
}
[[nodiscard]] Rect<T> inflated(Size<T> const& size) const
{
Rect<T> rect = *this;