mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-17 10:21:11 +00:00
Handle moving element into another element layout
This commit is contained in:
parent
cf84386cc2
commit
86ea12a458
@ -88,6 +88,23 @@ namespace LuaUi
|
|||||||
root = root->getParent();
|
root = root->getParent();
|
||||||
root->updateCoord();
|
root->updateCoord();
|
||||||
}
|
}
|
||||||
|
WidgetExtension* pluckElementRoot(const sol::object& child)
|
||||||
|
{
|
||||||
|
std::shared_ptr<Element> element = child.as<std::shared_ptr<Element>>();
|
||||||
|
WidgetExtension* root = element->mRoot;
|
||||||
|
if (!root)
|
||||||
|
throw std::logic_error("Using a destroyed element as a layout child");
|
||||||
|
WidgetExtension* parent = root->getParent();
|
||||||
|
if (parent)
|
||||||
|
{
|
||||||
|
auto children = parent->children();
|
||||||
|
std::remove(children.begin(), children.end(), root);
|
||||||
|
parent->setChildren(children);
|
||||||
|
root->widget()->detachFromWidget();
|
||||||
|
}
|
||||||
|
root->updateCoord();
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
WidgetExtension* createWidget(const sol::table& layout, uint64_t depth);
|
WidgetExtension* createWidget(const sol::table& layout, uint64_t depth);
|
||||||
void updateWidget(WidgetExtension* ext, const sol::table& layout, uint64_t depth);
|
void updateWidget(WidgetExtension* ext, const sol::table& layout, uint64_t depth);
|
||||||
@ -112,13 +129,10 @@ namespace LuaUi
|
|||||||
sol::object child = content.at(i);
|
sol::object child = content.at(i);
|
||||||
if (child.is<Element>())
|
if (child.is<Element>())
|
||||||
{
|
{
|
||||||
std::shared_ptr<Element> element = child.as<std::shared_ptr<Element>>();
|
WidgetExtension* root = pluckElementRoot(child);
|
||||||
if (ext != element->mRoot)
|
if (ext != root)
|
||||||
destroyChild(ext);
|
destroyChild(ext);
|
||||||
if (!element->mRoot)
|
result[i] = root;
|
||||||
throw std::logic_error("Using a destroyed element as a layout child");
|
|
||||||
result[i] = element->mRoot;
|
|
||||||
element->mRoot->updateCoord();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -141,15 +155,8 @@ namespace LuaUi
|
|||||||
{
|
{
|
||||||
sol::object child = content.at(i);
|
sol::object child = content.at(i);
|
||||||
if (child.is<Element>())
|
if (child.is<Element>())
|
||||||
{
|
result[i] = pluckElementRoot(child);
|
||||||
std::shared_ptr<Element> element = child.as<std::shared_ptr<Element>>();
|
|
||||||
if (!element->mRoot)
|
|
||||||
throw std::logic_error("Using a destroyed element as a layout child");
|
|
||||||
result[i] = element->mRoot;
|
|
||||||
element->mRoot->updateCoord();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
result[i] = createWidget(child.as<sol::table>(), depth);
|
result[i] = createWidget(child.as<sol::table>(), depth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,6 +282,7 @@ namespace LuaUi
|
|||||||
mRoot = createWidget(layout(), 0);
|
mRoot = createWidget(layout(), 0);
|
||||||
*it = mRoot;
|
*it = mRoot;
|
||||||
parent->setChildren(children);
|
parent->setChildren(children);
|
||||||
|
mRoot->updateCoord();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user