From 6081dcc43cd274f308658ff53a02cbd5bb212d23 Mon Sep 17 00:00:00 2001 From: uramer Date: Sat, 21 Oct 2023 21:40:02 +0200 Subject: [PATCH] Work around MyGUI bug in a less destructive way --- components/lua_ui/widget.cpp | 20 ++++++++++++-------- components/lua_ui/widget.hpp | 2 ++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/components/lua_ui/widget.cpp b/components/lua_ui/widget.cpp index ff9f4d90a2..767d425453 100644 --- a/components/lua_ui/widget.cpp +++ b/components/lua_ui/widget.cpp @@ -92,15 +92,21 @@ namespace LuaUi w->widget()->detachFromWidget(); } + void WidgetExtension::updateVisible() + { + // workaround for MyGUI bug + // parent visibility doesn't affect added children + MyGUI::Widget* widget = this->widget(); + MyGUI::Widget* parent = widget->getParent(); + bool inheritedVisible = widget->getVisible() && (parent == nullptr || parent->getInheritedVisible()); + widget->setVisible(inheritedVisible); + } + void WidgetExtension::attach(WidgetExtension* ext) { ext->mParent = this; ext->mTemplateChild = false; ext->widget()->attachToWidget(mSlot->widget()); - // workaround for MyGUI bug - // parent visibility doesn't affect added children - ext->widget()->setVisible(!ext->widget()->getVisible()); - ext->widget()->setVisible(!ext->widget()->getVisible()); } void WidgetExtension::attachTemplate(WidgetExtension* ext) @@ -108,10 +114,6 @@ namespace LuaUi ext->mParent = this; ext->mTemplateChild = true; ext->widget()->attachToWidget(widget()); - // workaround for MyGUI bug - // parent visibility doesn't affect added children - ext->widget()->setVisible(!ext->widget()->getVisible()); - ext->widget()->setVisible(!ext->widget()->getVisible()); } WidgetExtension* WidgetExtension::findDeep(std::string_view flagName) @@ -256,6 +258,8 @@ namespace LuaUi void WidgetExtension::updateCoord() { + updateVisible(); + MyGUI::IntCoord oldCoord = mWidget->getCoord(); MyGUI::IntCoord newCoord = calculateCoord(); diff --git a/components/lua_ui/widget.hpp b/components/lua_ui/widget.hpp index 3dbc14b6c3..81698b0479 100644 --- a/components/lua_ui/widget.hpp +++ b/components/lua_ui/widget.hpp @@ -173,6 +173,8 @@ namespace LuaUi void focusLoss(MyGUI::Widget*, MyGUI::Widget*); std::optional> mOnCoordChange; + + void updateVisible(); }; class LuaWidget : public MyGUI::Widget, public WidgetExtension