Skip to content

Commit

Permalink
ChildWindow::setPosition didn't work properly when KeepInParent was set
Browse files Browse the repository at this point in the history
  • Loading branch information
texus committed Nov 16, 2023
1 parent 4049431 commit 418aed0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Widgets/ChildWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ namespace tgui

void ChildWindow::setPosition(const Layout2d& position)
{
bool positionMovedToKeepInParent = false;
if (m_keepInParent && m_parent && (m_parent->getSize().x > 0) && (m_parent->getSize().y > 0))
{
const Vector2f origin{getOrigin().x * getSize().x, getOrigin().y * getSize().y};
Expand All @@ -321,10 +322,12 @@ namespace tgui
else if (x > m_parent->getSize().x - getSize().x)
x = std::max(0.f, m_parent->getSize().x - getSize().x);

positionMovedToKeepInParent = true;
Container::setPosition({x + origin.x, y + origin.y});
}
}
else

if (!positionMovedToKeepInParent)
Container::setPosition(position);

// Calculate the distance from the right side that the buttons will need
Expand Down
17 changes: 17 additions & 0 deletions tests/Widgets/ChildWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,4 +522,21 @@ TEST_CASE("[ChildWindow]")
TEST_DRAW("ChildWindow_Textured.png")
}
}

SECTION("Bug Fixes")
{
SECTION("setPosition doesn't work with KeepInParent (https://forum.tgui.eu/index.php?topic=1082.0)")
{
auto parent = tgui::Panel::create({300, 200});
parent->setPosition({30, 25});
parent->add(childWindow);

childWindow->setSize({100, 80});
childWindow->setPosition({10, 5});
childWindow->setKeepInParent(true);

childWindow->setPosition({15, 20});
REQUIRE(childWindow->getPosition() == tgui::Vector2f{15, 20});
}
}
}

0 comments on commit 418aed0

Please sign in to comment.