From 43220568b058861d08450793c3269914392d250c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 30 Aug 2021 22:03:04 +0200 Subject: [PATCH] LibGfx: Add Rect::centered_within(Rect) I've wanted this API a number of times but never added it. --- Userland/Libraries/LibGfx/Rect.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Userland/Libraries/LibGfx/Rect.h b/Userland/Libraries/LibGfx/Rect.h index 9398976c84..878fd2392e 100644 --- a/Userland/Libraries/LibGfx/Rect.h +++ b/Userland/Libraries/LibGfx/Rect.h @@ -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 const& other) { set_x(other.center().x() - width() / 2);