diff --git a/src/Widgets/ChildWindow.cpp b/src/Widgets/ChildWindow.cpp index 8104fa526..5cfad386b 100644 --- a/src/Widgets/ChildWindow.cpp +++ b/src/Widgets/ChildWindow.cpp @@ -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}; @@ -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 diff --git a/tests/Widgets/ChildWindow.cpp b/tests/Widgets/ChildWindow.cpp index f23c030fc..512f6696e 100644 --- a/tests/Widgets/ChildWindow.cpp +++ b/tests/Widgets/ChildWindow.cpp @@ -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}); + } + } }