From 3b13823b5d1c69fef368406560a467cd587019c5 Mon Sep 17 00:00:00 2001 From: ravi688 Date: Mon, 9 Sep 2024 23:18:50 +0530 Subject: [PATCH] [SUTK] Added Container::alwaysFitParent() --- sutk/include/sutk/Container.hpp | 4 ++++ sutk/source/Container.cpp | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/sutk/include/sutk/Container.hpp b/sutk/include/sutk/Container.hpp index e4a86ee9..949e817d 100644 --- a/sutk/include/sutk/Container.hpp +++ b/sutk/include/sutk/Container.hpp @@ -110,6 +110,10 @@ namespace SUTK void setPosition(Vec2Df pos) { m_rect.setPosition(pos); onResize(m_rect, true, false); } void setSize(Vec2Df size) { m_rect.setSize(size); onResize(m_rect, false, true); } + // If called with true, then this Container's rect is always in-sync with its parent's rect, + // That also means, this container's rect's position will always be { 0, 0 } (in local coordinates of its parent's rect) + void alwaysFitInParent() noexcept; + // anchor rect getters AnchorRect* getAnchorRect() const noexcept { return m_anchorRect; } diff --git a/sutk/source/Container.cpp b/sutk/source/Container.cpp index ebddb155..af78cb49 100644 --- a/sutk/source/Container.cpp +++ b/sutk/source/Container.cpp @@ -77,6 +77,14 @@ namespace SUTK return contains(globalCoords); } + void Container::alwaysFitInParent() noexcept + { + Container* parent = getParent(); + if(parent != NULL) + setRect({ { 0.0f, 0.0f }, parent->getSize() }); + getAnchorRect()->setRect({ 0.0f, 0.0f, 1.0f, 1.0f }); + } + u32 Container::getDepth() const noexcept { if(getParent() == NULL)