diff --git a/components/lua_ui/element.cpp b/components/lua_ui/element.cpp index ceaa746f15..f3f873a583 100644 --- a/components/lua_ui/element.cpp +++ b/components/lua_ui/element.cpp @@ -54,7 +54,7 @@ namespace LuaUi if (!ext->isRoot()) destroyWidget(ext); else - ext->detachFromParent(false); + ext->detachFromParent(); } void detachElements(WidgetExtension* ext) diff --git a/components/lua_ui/widget.cpp b/components/lua_ui/widget.cpp index 3804e70096..e7e1053ab7 100644 --- a/components/lua_ui/widget.cpp +++ b/components/lua_ui/widget.cpp @@ -101,7 +101,15 @@ namespace LuaUi void WidgetExtension::attach(WidgetExtension* ext) { if (ext->mParent != this) - ext->detachFromParent(true); + { + if (ext->mParent) + { + auto children = ext->mParent->children(); + std::erase(children, this); + ext->mParent->setChildren(children); + } + ext->detachFromParent(); + } ext->mParent = this; ext->mTemplateChild = false; ext->widget()->attachToWidget(mSlot->widget()); @@ -114,18 +122,9 @@ namespace LuaUi ext->widget()->attachToWidget(widget()); } - void WidgetExtension::detachFromParent(bool updateParent) + void WidgetExtension::detachFromParent() { - if (mParent) - { - if (updateParent) - { - auto children = mParent->children(); - std::erase(children, this); - mParent->setChildren(children); - } - mParent = nullptr; - } + mParent = nullptr; widget()->detachFromWidget(); } diff --git a/components/lua_ui/widget.hpp b/components/lua_ui/widget.hpp index 59ac997688..24962f6820 100644 --- a/components/lua_ui/widget.hpp +++ b/components/lua_ui/widget.hpp @@ -34,7 +34,7 @@ namespace LuaUi bool isRoot() const { return mElementRoot; } WidgetExtension* getParent() const { return mParent; } - void detachFromParent(bool updateParent); + void detachFromParent(); void detachChildrenIf(auto&& predicate) { detachChildrenIf(predicate, mChildren); } void detachTemplateChildrenIf(auto&& predicate) { detachChildrenIf(predicate, mTemplateChildren); } @@ -185,7 +185,7 @@ namespace LuaUi { if (predicate(*it)) { - (*it)->detachFromParent(false); + (*it)->detachFromParent(); it = children.erase(it); } else