-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting a widget's index in a layout doesn't seem to update it until the layout is resized #202
Comments
I have a solution but I'm not sure if it's the right way to go. We could make I was not able to replicate the problem with any layout widget after making those changes. Here's a patch: diff --git a/include/TGUI/Container.hpp b/include/TGUI/Container.hpp
index 748e3914..c88e626d 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 95faa3cc..f6082f69 100644
--- a/include/TGUI/Widgets/BoxLayout.hpp
+++ b/include/TGUI/Widgets/BoxLayout.hpp
@@ -137,6 +137,9 @@ TGUI_MODULE_EXPORT namespace tgui
using Container::get;
+ bool setWidgetIndex(const Widget::Ptr& widget, std::size_t index) override;
+
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
protected:
diff --git a/src/Widgets/BoxLayout.cpp b/src/Widgets/BoxLayout.cpp
index 5d781ebf..244e794b 100644
--- a/src/Widgets/BoxLayout.cpp
+++ b/src/Widgets/BoxLayout.cpp
@@ -129,6 +129,12 @@ namespace tgui
return nullptr;
}
+ bool BoxLayout::setWidgetIndex(const Widget::Ptr& widget, std::size_t index) {
+ const auto ret = Container::setWidgetIndex(widget, index);
+ if (ret) updateWidgets();
+ return ret;
+ }
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void BoxLayout::rendererChanged(const String& property) It doesn't follow the style of the rest of the library's code yet, but I will create a proper PR that addresses that. Let me know what you think. |
…dex was changed using setWidgetIndex (fixes texus#202)
I've come across an issue with updating widget indices whilst developing my game, and I have been able to replicate it in isolation with the following code:
The expected outcome is that the buttons will be displayed in the following order, from top to bottom:
However, the buttons are instead displayed in their original order:
That is, until the layout is resized, either by manually resizing the window, resizing the layout itself programmatically (e.g.
setSize()
), or adding a widget to the layout to invoke a resize.I can also replicate this issue with a
HorizontalLayout
andHorizontalWrap
, but I cannot replicate it with any other container type. You can see that if you changeVerticalLayout
toGroup
, for example, Button2 will appear on top of the other two buttons, which is the intended outcome.Can replicate using the latest changes on the
1.x
branch (currently commit6c4879e
). Seems like this could be a simple fix so I'll do some digging now and report any findings and/or make a PR if I make any progress.The text was updated successfully, but these errors were encountered: