diff --git a/Userland/Libraries/LibGfx/Rect.h b/Userland/Libraries/LibGfx/Rect.h index 878fd2392e..502fc0d679 100644 --- a/Userland/Libraries/LibGfx/Rect.h +++ b/Userland/Libraries/LibGfx/Rect.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2021, Andreas Kling + * Copyright (c) 2021, Sam Atkins * * 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 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 const& size) { set_x(x() + size.width() / 2); @@ -187,6 +204,13 @@ public: return rect; } + [[nodiscard]] Rect shrunken(T top, T right, T bottom, T left) const + { + Rect rect = *this; + rect.shrink(top, right, bottom, left); + return rect; + } + [[nodiscard]] Rect shrunken(Size const& size) const { Rect rect = *this; @@ -201,6 +225,13 @@ public: return rect; } + [[nodiscard]] Rect inflated(T top, T right, T bottom, T left) const + { + Rect rect = *this; + rect.inflate(top, right, bottom, left); + return rect; + } + [[nodiscard]] Rect inflated(Size const& size) const { Rect rect = *this;