🪲 KeepInParent property of ChildWindow should also be verified in keepInParent and setParent functions

0.8
Bruno Van de Velde 2017-09-21 01:05:51 +02:00
parent fb7033a7a4
commit 1c0950c8d3
2 changed files with 22 additions and 1 deletions

View File

@ -312,6 +312,14 @@ namespace tgui
sf::Vector2f getChildWidgetsOffset() const override; 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 /// @brief Returns whether the mouse position (which is relative to the parent widget) lies on top of the widget
/// ///

View File

@ -103,7 +103,8 @@ namespace tgui
float x = position.getValue().x; float x = position.getValue().x;
float y = position.getValue().y; 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) if (y < 0)
y = 0; y = 0;
@ -331,6 +332,9 @@ namespace tgui
void ChildWindow::keepInParent(bool enabled) void ChildWindow::keepInParent(bool enabled)
{ {
m_keepInParent = 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 bool ChildWindow::mouseOnWidget(sf::Vector2f pos) const
{ {
// Check if the mouse is on top of the title bar // Check if the mouse is on top of the title bar