ref nodes work fine now but need to complete Widget::clone implementations and add clone() to Shape classes to actually clone the OpenGL data

This commit is contained in:
2017-02-02 18:26:59 +00:00
parent bcf95d5432
commit 06b19dc596
4 changed files with 127 additions and 51 deletions

View File

@@ -199,15 +199,45 @@ void Node::load_internal(const tinyxml2::XMLElement* x_node)
while (x_child)
{
//Node n;
m_children.emplace_back();
auto& n = m_children.back();
n.parent = this;
YGNodeInsertChild(y_node, n.y_node, YGNodeGetChildCount(y_node));
n.load_internal(x_child);
if (strcmp("ref", x_child->Name()) == 0)
{
auto ids = x_child->Attribute("id");
auto id = const_hash(ids);
auto& ref = (*m_manager)[id];
m_children.push_back(ref.clone());
m_children.back().parent = parent;
m_children.back().m_manager = m_manager;
YGNodeInsertChild(y_node, m_children.back().y_node, YGNodeGetChildCount(y_node));
}
else
{
m_children.emplace_back();
auto& n = m_children.back();
n.parent = this;
n.m_manager = m_manager;
YGNodeInsertChild(y_node, n.y_node, YGNodeGetChildCount(y_node));
n.load_internal(x_child);
}
x_child = x_child->NextSiblingElement();
}
}
Node Node::clone()
{
Node n;
YGNodeCopyStyle(n.y_node, y_node);
if (m_widget)
n.m_widget = m_widget->clone();
for (auto& c : m_children)
{
n.m_children.push_back(std::move(c.clone()));
auto& cn = n.m_children.back(); // child node reference
cn.parent = &n;
YGNodeInsertChild(n.y_node, cn.y_node, YGNodeGetChildCount(n.y_node));
}
return std::move(n);
}
bool LayoutManager::load(const char* path)
{
struct stat tmp_info;
@@ -225,7 +255,7 @@ bool LayoutManager::load(const char* path)
if (ret != tinyxml2::XMLError::XML_SUCCESS)
return false;
tinyxml2::XMLElement* current = xml.RootElement();
tinyxml2::XMLElement* current = xml.RootElement()->FirstChildElement();
while (current)
{
auto id_str = current->Attribute("id");
@@ -234,11 +264,13 @@ bool LayoutManager::load(const char* path)
printf("Layout node without id\n");
return false;
}
printf("Parsing layout: %s\n", id_str);
uint16_t id = const_hash(id_str);
auto& p = m_layouts.try_emplace(id);
if (p.second)
{
auto& node = p.first->second;
node.m_manager = this;
// try to copy the old size values
if (old.count(id))
{