Simplify detachFromParent

animationblending
Evil Eye 9 months ago
parent 8cbcb82dd4
commit 1d13f7db8f

@ -54,7 +54,7 @@ namespace LuaUi
if (!ext->isRoot())
destroyWidget(ext);
else
ext->detachFromParent(false);
ext->detachFromParent();
}
void detachElements(WidgetExtension* ext)

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

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

Loading…
Cancel
Save