From 68ed77181683da3e417341c8cebc24cab056dde7 Mon Sep 17 00:00:00 2001 From: uramer Date: Thu, 14 Mar 2024 18:08:38 +0100 Subject: [PATCH] Fix element detachment logic --- components/lua_ui/element.cpp | 9 --------- components/lua_ui/widget.cpp | 10 +++++++++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/components/lua_ui/element.cpp b/components/lua_ui/element.cpp index c239335abb..ffd763b40b 100644 --- a/components/lua_ui/element.cpp +++ b/components/lua_ui/element.cpp @@ -99,15 +99,6 @@ namespace LuaUi element->create(depth + 1); WidgetExtension* root = element->mRoot; assert(root); - WidgetExtension* parent = root->getParent(); - if (parent) - { - auto children = parent->children(); - std::erase(children, root); - parent->setChildren(children); - root->widget()->detachFromWidget(); - } - root->updateCoord(); return root; } diff --git a/components/lua_ui/widget.cpp b/components/lua_ui/widget.cpp index be0ea70387..e61c36c452 100644 --- a/components/lua_ui/widget.cpp +++ b/components/lua_ui/widget.cpp @@ -100,6 +100,8 @@ namespace LuaUi void WidgetExtension::attach(WidgetExtension* ext) { + if (ext->mParent != this) + ext->detachFromParent(); ext->mParent = this; ext->mTemplateChild = false; ext->widget()->attachToWidget(mSlot->widget()); @@ -114,7 +116,13 @@ namespace LuaUi void WidgetExtension::detachFromParent() { - mParent = nullptr; + if (mParent) + { + auto children = mParent->children(); + std::erase(children, this); + mParent->setChildren(children); + mParent = nullptr; + } widget()->detachFromWidget(); }