From c0ada40e2c2a832688b358ac3244690dce7adeed Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 6 Aug 2023 12:44:16 +0200 Subject: [PATCH] libui: Add Rect::contains(Rect) --- libui/include/ui/Rect.h | 9 +++++++++ libui/src/Rect.cpp | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/libui/include/ui/Rect.h b/libui/include/ui/Rect.h index da6a2603..5c99f042 100644 --- a/libui/include/ui/Rect.h +++ b/libui/include/ui/Rect.h @@ -21,6 +21,15 @@ namespace ui */ bool contains(Point point); + /** + * @brief Check if another rectangle is contained in this one. + * + * @param point The rectangle to check. + * @return true The other rectangle is contained inside this one. + * @return false The other rectangle is not contained inside this one. + */ + bool contains(Rect rect); + /** * @brief Normalize a point to fit inside this rectangle. * diff --git a/libui/src/Rect.cpp b/libui/src/Rect.cpp index e96eb7e9..36f7f225 100644 --- a/libui/src/Rect.cpp +++ b/libui/src/Rect.cpp @@ -8,6 +8,15 @@ namespace ui (point.y <= (pos.y + height)); } + bool Rect::contains(Rect rect) + { + if (!contains(rect.pos)) return false; + Point rel = relative(rect.pos); + if ((rel.x + rect.width) > width) return false; + if ((rel.y + rect.height) > height) return false; + return true; + } + Point Rect::normalize(Point point) { if (point.x < pos.x) point.x = pos.x;