Skip to content

Commit

Permalink
Fixed widgets not being updated in BoxLayout when a child widget's in…
Browse files Browse the repository at this point in the history
…dex was changed using setWidgetIndex (fixes #202)
  • Loading branch information
CasualYT31 authored and texus committed Aug 27, 2023
1 parent 6c4879e commit e778c38
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/TGUI/Container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
14 changes: 14 additions & 0 deletions include/TGUI/Widgets/BoxLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
10 changes: 10 additions & 0 deletions src/Widgets/BoxLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit e778c38

Please sign in to comment.