Skip to content

Commit

Permalink
[SUTK] Added Container::alwaysFitParent()
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi688 committed Sep 9, 2024
1 parent 773742b commit 3b13823
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sutk/include/sutk/Container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
8 changes: 8 additions & 0 deletions sutk/source/Container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3b13823

Please sign in to comment.