mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-28 12:09:53 +00:00
Handle moving element into another element layout
This commit is contained in:
parent
cf84386cc2
commit
86ea12a458
1 changed files with 22 additions and 14 deletions
|
@ -88,6 +88,23 @@ namespace LuaUi
|
|||
root = root->getParent();
|
||||
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);
|
||||
void updateWidget(WidgetExtension* ext, const sol::table& layout, uint64_t depth);
|
||||
|
@ -112,13 +129,10 @@ namespace LuaUi
|
|||
sol::object child = content.at(i);
|
||||
if (child.is<Element>())
|
||||
{
|
||||
std::shared_ptr<Element> element = child.as<std::shared_ptr<Element>>();
|
||||
if (ext != element->mRoot)
|
||||
WidgetExtension* root = pluckElementRoot(child);
|
||||
if (ext != root)
|
||||
destroyChild(ext);
|
||||
if (!element->mRoot)
|
||||
throw std::logic_error("Using a destroyed element as a layout child");
|
||||
result[i] = element->mRoot;
|
||||
element->mRoot->updateCoord();
|
||||
result[i] = root;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -141,15 +155,8 @@ namespace LuaUi
|
|||
{
|
||||
sol::object child = content.at(i);
|
||||
if (child.is<Element>())
|
||||
{
|
||||
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();
|
||||
}
|
||||
result[i] = pluckElementRoot(child);
|
||||
else
|
||||
{
|
||||
result[i] = createWidget(child.as<sol::table>(), depth);
|
||||
}
|
||||
}
|
||||
|
@ -275,6 +282,7 @@ namespace LuaUi
|
|||
mRoot = createWidget(layout(), 0);
|
||||
*it = mRoot;
|
||||
parent->setChildren(children);
|
||||
mRoot->updateCoord();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue