From af8662daeebabeab20cf8403867259495de6c3bd Mon Sep 17 00:00:00 2001 From: uramer Date: Sun, 10 Mar 2024 14:05:37 +0100 Subject: [PATCH] Detach Lua Elements properly from their parent --- components/lua_ui/element.cpp | 8 ++++---- components/lua_ui/widget.cpp | 6 ++++++ components/lua_ui/widget.hpp | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/components/lua_ui/element.cpp b/components/lua_ui/element.cpp index e509847a4c..b491acb7b3 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->widget()->detachFromWidget(); + ext->detachFromParent(); } void detachElements(WidgetExtension* ext) @@ -62,14 +62,14 @@ namespace LuaUi for (auto* child : ext->children()) { if (child->isRoot()) - child->widget()->detachFromWidget(); + child->detachFromParent(); else detachElements(child); } for (auto* child : ext->templateChildren()) { if (child->isRoot()) - child->widget()->detachFromWidget(); + child->detachFromParent(); else detachElements(child); } @@ -272,9 +272,9 @@ namespace LuaUi void Element::create(uint64_t depth) { - assert(!mRoot); if (mState == New) { + assert(!mRoot); mRoot = createWidget(layout(), true, depth); mLayer = setLayer(mRoot, layout()); updateRootCoord(mRoot); diff --git a/components/lua_ui/widget.cpp b/components/lua_ui/widget.cpp index 9550c9de73..be0ea70387 100644 --- a/components/lua_ui/widget.cpp +++ b/components/lua_ui/widget.cpp @@ -112,6 +112,12 @@ namespace LuaUi ext->widget()->attachToWidget(widget()); } + void WidgetExtension::detachFromParent() + { + mParent = nullptr; + widget()->detachFromWidget(); + } + WidgetExtension* WidgetExtension::findDeep(std::string_view flagName) { for (WidgetExtension* w : mChildren) diff --git a/components/lua_ui/widget.hpp b/components/lua_ui/widget.hpp index 591c885ce9..05359705a1 100644 --- a/components/lua_ui/widget.hpp +++ b/components/lua_ui/widget.hpp @@ -35,6 +35,7 @@ namespace LuaUi bool isRoot() const { return mElementRoot; } WidgetExtension* getParent() const { return mParent; } + void detachFromParent(); void reset();