mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-25 15:11:33 +00:00
Simplify detachFromParent
This commit is contained in:
parent
8cbcb82dd4
commit
1d13f7db8f
3 changed files with 14 additions and 15 deletions
|
@ -54,7 +54,7 @@ namespace LuaUi
|
||||||
if (!ext->isRoot())
|
if (!ext->isRoot())
|
||||||
destroyWidget(ext);
|
destroyWidget(ext);
|
||||||
else
|
else
|
||||||
ext->detachFromParent(false);
|
ext->detachFromParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void detachElements(WidgetExtension* ext)
|
void detachElements(WidgetExtension* ext)
|
||||||
|
|
|
@ -101,7 +101,15 @@ namespace LuaUi
|
||||||
void WidgetExtension::attach(WidgetExtension* ext)
|
void WidgetExtension::attach(WidgetExtension* ext)
|
||||||
{
|
{
|
||||||
if (ext->mParent != this)
|
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->mParent = this;
|
||||||
ext->mTemplateChild = false;
|
ext->mTemplateChild = false;
|
||||||
ext->widget()->attachToWidget(mSlot->widget());
|
ext->widget()->attachToWidget(mSlot->widget());
|
||||||
|
@ -114,18 +122,9 @@ namespace LuaUi
|
||||||
ext->widget()->attachToWidget(widget());
|
ext->widget()->attachToWidget(widget());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WidgetExtension::detachFromParent(bool updateParent)
|
void WidgetExtension::detachFromParent()
|
||||||
{
|
{
|
||||||
if (mParent)
|
mParent = nullptr;
|
||||||
{
|
|
||||||
if (updateParent)
|
|
||||||
{
|
|
||||||
auto children = mParent->children();
|
|
||||||
std::erase(children, this);
|
|
||||||
mParent->setChildren(children);
|
|
||||||
}
|
|
||||||
mParent = nullptr;
|
|
||||||
}
|
|
||||||
widget()->detachFromWidget();
|
widget()->detachFromWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace LuaUi
|
||||||
|
|
||||||
bool isRoot() const { return mElementRoot; }
|
bool isRoot() const { return mElementRoot; }
|
||||||
WidgetExtension* getParent() const { return mParent; }
|
WidgetExtension* getParent() const { return mParent; }
|
||||||
void detachFromParent(bool updateParent);
|
void detachFromParent();
|
||||||
|
|
||||||
void detachChildrenIf(auto&& predicate) { detachChildrenIf(predicate, mChildren); }
|
void detachChildrenIf(auto&& predicate) { detachChildrenIf(predicate, mChildren); }
|
||||||
void detachTemplateChildrenIf(auto&& predicate) { detachChildrenIf(predicate, mTemplateChildren); }
|
void detachTemplateChildrenIf(auto&& predicate) { detachChildrenIf(predicate, mTemplateChildren); }
|
||||||
|
@ -185,7 +185,7 @@ namespace LuaUi
|
||||||
{
|
{
|
||||||
if (predicate(*it))
|
if (predicate(*it))
|
||||||
{
|
{
|
||||||
(*it)->detachFromParent(false);
|
(*it)->detachFromParent();
|
||||||
it = children.erase(it);
|
it = children.erase(it);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue