Use Element Content children for Settings UI

macos_ci_fix
uramer 1 year ago
parent 4ba2aca3d3
commit cf84386cc2

@ -44,14 +44,20 @@ namespace LuaUi
void LuaAdapter::attachElement()
{
if (mElement.get())
mElement->attachToWidget(mContainer);
if (!mElement.get())
return;
if (!mElement->mRoot)
throw std::logic_error("Attempting to use a destroyed UI Element");
mContainer->setChildren({ mElement->mRoot });
mElement->mRoot->updateCoord();
mContainer->updateCoord();
}
void LuaAdapter::detachElement()
{
if (mElement.get())
mElement->detachFromWidget();
mContainer->setChildren({});
if (mElement && mElement->mRoot)
mElement->mRoot->widget()->detachFromWidget();
mElement = nullptr;
}
}

@ -9,6 +9,7 @@ namespace LuaUi
{
MYGUI_RTTI_DERIVED(LuaContainer)
public:
MyGUI::IntSize calculateSize() override;
void updateCoord() override;

@ -53,6 +53,8 @@ namespace LuaUi
{
if (!ext->isRoot())
destroyWidget(ext);
else
ext->widget()->detachFromWidget();
}
void detachElements(LuaUi::WidgetExtension* ext)
@ -235,7 +237,6 @@ namespace LuaUi
Element::Element(sol::table layout)
: mRoot(nullptr)
, mAttachedTo(nullptr)
, mLayout(std::move(layout))
, mLayer()
, mUpdate(false)
@ -257,7 +258,6 @@ namespace LuaUi
{
mRoot = createWidget(layout(), 0);
mLayer = setLayer(mRoot, layout());
updateAttachment();
updateRootCoord(mRoot);
}
}
@ -281,7 +281,6 @@ namespace LuaUi
updateWidget(mRoot, layout(), 0);
}
mLayer = setLayer(mRoot, layout());
updateAttachment();
updateRootCoord(mRoot);
}
mUpdate = false;
@ -297,34 +296,4 @@ namespace LuaUi
}
sAllElements.erase(this);
}
void Element::attachToWidget(WidgetExtension* w)
{
if (mAttachedTo)
throw std::logic_error("A UI element can't be attached to two widgets at once");
mAttachedTo = w;
updateAttachment();
}
void Element::detachFromWidget()
{
if (mRoot)
mRoot->widget()->detachFromWidget();
if (mAttachedTo)
mAttachedTo->setChildren({});
mAttachedTo = nullptr;
}
void Element::updateAttachment()
{
if (!mRoot)
return;
if (mAttachedTo)
{
if (!mLayer.empty())
Log(Debug::Warning) << "Ignoring element's layer " << mLayer << " because it's attached to a widget";
mAttachedTo->setChildren({ mRoot });
mAttachedTo->updateCoord();
}
}
}

@ -17,7 +17,6 @@ namespace LuaUi
}
WidgetExtension* mRoot;
WidgetExtension* mAttachedTo;
sol::object mLayout;
std::string mLayer;
bool mUpdate;
@ -31,14 +30,10 @@ namespace LuaUi
friend void clearUserInterface();
void attachToWidget(WidgetExtension* w);
void detachFromWidget();
private:
Element(sol::table layout);
sol::table layout() { return LuaUtil::cast<sol::table>(mLayout); }
static std::map<Element*, std::shared_ptr<Element>> sAllElements;
void updateAttachment();
};
}

Loading…
Cancel
Save