Skip to content

Commit

Permalink
[SUTK] Added AnchorRect::moveToCenterOfChild() utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
ravi688 committed Oct 4, 2024
1 parent 3247bc2 commit 11b4b78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions sutk/include/sutk/AnchorRect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace SUTK
// But it doesn't relcalculate if you change the child's Rect after this function call.
// You have to call this function again if you do so.
void fitToChildRect() noexcept;
void moveToCenterOfChild() noexcept;

// setters

Expand Down
11 changes: 11 additions & 0 deletions sutk/source/AnchorRect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ namespace SUTK
setRect(anchorRect);
}

void AnchorRect::moveToCenterOfChild() noexcept
{
_com_assert(m_childRect != NULL);
_com_assert(m_parentRect != NULL);
Rect2Df childRect = m_childRect->getRect();
Vec2Df size = m_parentRect->getSize();
Rect2Df anchorRect;
anchorRect.setPosition(childRect.getCenter() / size);
setRect(anchorRect);
}

void AnchorRect::setRect(Rect2Df rect) noexcept
{
m_rect = rect;
Expand Down

0 comments on commit 11b4b78

Please sign in to comment.