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() void LuaAdapter::attachElement()
{ {
if (mElement.get()) if (!mElement.get())
mElement->attachToWidget(mContainer); 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() void LuaAdapter::detachElement()
{ {
if (mElement.get()) mContainer->setChildren({});
mElement->detachFromWidget(); if (mElement && mElement->mRoot)
mElement->mRoot->widget()->detachFromWidget();
mElement = nullptr; mElement = nullptr;
} }
} }

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

@ -53,6 +53,8 @@ namespace LuaUi
{ {
if (!ext->isRoot()) if (!ext->isRoot())
destroyWidget(ext); destroyWidget(ext);
else
ext->widget()->detachFromWidget();
} }
void detachElements(LuaUi::WidgetExtension* ext) void detachElements(LuaUi::WidgetExtension* ext)
@ -235,7 +237,6 @@ namespace LuaUi
Element::Element(sol::table layout) Element::Element(sol::table layout)
: mRoot(nullptr) : mRoot(nullptr)
, mAttachedTo(nullptr)
, mLayout(std::move(layout)) , mLayout(std::move(layout))
, mLayer() , mLayer()
, mUpdate(false) , mUpdate(false)
@ -257,7 +258,6 @@ namespace LuaUi
{ {
mRoot = createWidget(layout(), 0); mRoot = createWidget(layout(), 0);
mLayer = setLayer(mRoot, layout()); mLayer = setLayer(mRoot, layout());
updateAttachment();
updateRootCoord(mRoot); updateRootCoord(mRoot);
} }
} }
@ -281,7 +281,6 @@ namespace LuaUi
updateWidget(mRoot, layout(), 0); updateWidget(mRoot, layout(), 0);
} }
mLayer = setLayer(mRoot, layout()); mLayer = setLayer(mRoot, layout());
updateAttachment();
updateRootCoord(mRoot); updateRootCoord(mRoot);
} }
mUpdate = false; mUpdate = false;
@ -297,34 +296,4 @@ namespace LuaUi
} }
sAllElements.erase(this); 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* mRoot;
WidgetExtension* mAttachedTo;
sol::object mLayout; sol::object mLayout;
std::string mLayer; std::string mLayer;
bool mUpdate; bool mUpdate;
@ -31,14 +30,10 @@ namespace LuaUi
friend void clearUserInterface(); friend void clearUserInterface();
void attachToWidget(WidgetExtension* w);
void detachFromWidget();
private: private:
Element(sol::table layout); Element(sol::table layout);
sol::table layout() { return LuaUtil::cast<sol::table>(mLayout); } sol::table layout() { return LuaUtil::cast<sol::table>(mLayout); }
static std::map<Element*, std::shared_ptr<Element>> sAllElements; static std::map<Element*, std::shared_ptr<Element>> sAllElements;
void updateAttachment();
}; };
} }

Loading…
Cancel
Save