From e778c383bc175ac78fb20d92379050790272f3ff Mon Sep 17 00:00:00 2001 From: CasualYT31 <21147925+CasualYT31@users.noreply.github.com> Date: Sun, 27 Aug 2023 00:16:15 +0100 Subject: [PATCH] Fixed widgets not being updated in BoxLayout when a child widget's index was changed using setWidgetIndex (fixes #202) --- include/TGUI/Container.hpp | 2 +- include/TGUI/Widgets/BoxLayout.hpp | 14 ++++++++++++++ src/Widgets/BoxLayout.cpp | 10 ++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/TGUI/Container.hpp b/include/TGUI/Container.hpp index 748e39140..c88e626d7 100644 --- a/include/TGUI/Container.hpp +++ b/include/TGUI/Container.hpp @@ -345,7 +345,7 @@ TGUI_MODULE_EXPORT namespace tgui /// /// @return True when the index was changed, false if widget wasn't found in the container or index was too high ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - bool setWidgetIndex(const Widget::Ptr& widget, std::size_t index); + virtual bool setWidgetIndex(const Widget::Ptr& widget, std::size_t index); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/include/TGUI/Widgets/BoxLayout.hpp b/include/TGUI/Widgets/BoxLayout.hpp index 95faa3ccf..428dad708 100644 --- a/include/TGUI/Widgets/BoxLayout.hpp +++ b/include/TGUI/Widgets/BoxLayout.hpp @@ -137,6 +137,20 @@ TGUI_MODULE_EXPORT namespace tgui using Container::get; + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /// @brief Changes the index of a widget in this container + /// + /// Widgets are drawn in the order of the list, so widgets with a higher index will appear after others. + /// + /// @param widget Widget that is to be moved to a different index + /// @param index New index of the widget, corresponding to the widget position after the widget has been moved + /// + /// @return True when the index was changed, false if widget wasn't found in the container or index was too high + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + virtual bool setWidgetIndex(const Widget::Ptr& widget, std::size_t index) override; + using Container::setWidgetIndex; + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// protected: diff --git a/src/Widgets/BoxLayout.cpp b/src/Widgets/BoxLayout.cpp index 5d781ebf7..2b51e3346 100644 --- a/src/Widgets/BoxLayout.cpp +++ b/src/Widgets/BoxLayout.cpp @@ -131,6 +131,16 @@ namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + bool BoxLayout::setWidgetIndex(const Widget::Ptr& widget, std::size_t index) + { + const auto widgetIndexChanged = Container::setWidgetIndex(widget, index); + if (widgetIndexChanged) + updateWidgets(); + return widgetIndexChanged; + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void BoxLayout::rendererChanged(const String& property) { if (property == U"SpaceBetweenWidgets")