From 1c0950c8d329871163b360d8d6efc95ed35a5900 Mon Sep 17 00:00:00 2001 From: Bruno Van de Velde Date: Thu, 21 Sep 2017 01:05:51 +0200 Subject: [PATCH] :beetle: KeepInParent property of ChildWindow should also be verified in keepInParent and setParent functions --- include/TGUI/Widgets/ChildWindow.hpp | 8 ++++++++ src/TGUI/Widgets/ChildWindow.cpp | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/TGUI/Widgets/ChildWindow.hpp b/include/TGUI/Widgets/ChildWindow.hpp index 5a1d73ce..b2ae3183 100644 --- a/include/TGUI/Widgets/ChildWindow.hpp +++ b/include/TGUI/Widgets/ChildWindow.hpp @@ -312,6 +312,14 @@ namespace tgui sf::Vector2f getChildWidgetsOffset() const override; + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @internal + /// This function is called when the widget is added to a container. + /// You should not call this function yourself. + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void setParent(Container* parent) override; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// @brief Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget /// diff --git a/src/TGUI/Widgets/ChildWindow.cpp b/src/TGUI/Widgets/ChildWindow.cpp index 73f8b754..83bb9b51 100644 --- a/src/TGUI/Widgets/ChildWindow.cpp +++ b/src/TGUI/Widgets/ChildWindow.cpp @@ -103,7 +103,8 @@ namespace tgui float x = position.getValue().x; float y = position.getValue().y; - if (m_parent && m_keepInParent && ((y < 0) || (y > m_parent->getSize().y - m_titleBarHeightCached) || (x < 0) || (x > m_parent->getSize().x - getSize().x))) + if (m_parent && m_keepInParent && (m_parent->getSize().x > 0) && (m_parent->getSize().y > 0) + && ((y < 0) || (y > m_parent->getSize().y - m_titleBarHeightCached) || (x < 0) || (x > m_parent->getSize().x - getSize().x))) { if (y < 0) y = 0; @@ -331,6 +332,9 @@ namespace tgui void ChildWindow::keepInParent(bool enabled) { m_keepInParent = enabled; + + if (enabled) + setPosition(m_position); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -349,6 +353,15 @@ namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void ChildWindow::setParent(Container* parent) + { + Container::setParent(parent); + if (m_keepInParent) + setPosition(m_position); + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + bool ChildWindow::mouseOnWidget(sf::Vector2f pos) const { // Check if the mouse is on top of the title bar