Set Element layout to nil on destroy

update_gitlab_rules
uramer 2 years ago
parent 9e468e7b73
commit 38bceb653d

@ -189,8 +189,8 @@ namespace LuaUi
assert(!mRoot);
if (!mRoot)
{
mRoot = createWidget(mLayout, 0);
mLayer = setLayer(mRoot, mLayout);
mRoot = createWidget(layout(), 0);
mLayer = setLayer(mRoot, layout());
updateAttachment();
}
}
@ -199,16 +199,16 @@ namespace LuaUi
{
if (mRoot && mUpdate)
{
if (mRoot->widget()->getTypeName() != widgetType(mLayout))
if (mRoot->widget()->getTypeName() != widgetType(layout()))
{
destroyWidget(mRoot);
mRoot = createWidget(mLayout, 0);
mRoot = createWidget(layout(), 0);
}
else
{
updateWidget(mRoot, mLayout, 0);
updateWidget(mRoot, layout(), 0);
}
mLayer = setLayer(mRoot, mLayout);
mLayer = setLayer(mRoot, layout());
updateAttachment();
}
mUpdate = false;
@ -216,9 +216,11 @@ namespace LuaUi
void Element::destroy()
{
if (mRoot)
destroyWidget(mRoot);
if (!mRoot)
return;
destroyWidget(mRoot);
mRoot = nullptr;
mLayout = sol::make_object(mLayout.lua_state(), sol::nil);
sAllElements.erase(this);
}

@ -18,7 +18,7 @@ namespace LuaUi
WidgetExtension* mRoot;
WidgetExtension* mAttachedTo;
sol::table mLayout;
sol::object mLayout;
std::string mLayer;
bool mUpdate;
bool mDestroy;
@ -36,6 +36,7 @@ namespace LuaUi
private:
Element(sol::table layout);
sol::table layout() { return mLayout.as<sol::table>(); }
static std::map<Element*, std::shared_ptr<Element>> sAllElements;
void updateAttachment();
};

Loading…
Cancel
Save