1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-07 12:54:00 +00:00

Fix element detachment logic

This commit is contained in:
uramer 2024-03-14 18:08:38 +01:00
parent 2f40491065
commit 68ed771816
2 changed files with 9 additions and 10 deletions

View File

@ -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;
}

View File

@ -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();
}