From eb07668589385aee3088d9eac01fb53b1e223fe1 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Sun, 19 Sep 2021 20:43:56 +0100 Subject: [PATCH] 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. :^) --- Userland/Libraries/LibGfx/Rect.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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;