split layout.xml into multiple files loaded on demand, update changelog
This commit is contained in:
58
src/node.cpp
58
src/node.cpp
@@ -89,6 +89,13 @@ Node* Node::root()
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Node::set_manager(LayoutManager* manager)
|
||||
{
|
||||
m_manager = manager;
|
||||
for (auto& c : m_children)
|
||||
c->set_manager(manager);
|
||||
}
|
||||
|
||||
kEventResult Node::on_event(Event* e)
|
||||
{
|
||||
kEventResult ret = kEventResult::Available;
|
||||
@@ -346,6 +353,35 @@ const Node* Node::init_template(const char* id)
|
||||
return m_template;
|
||||
}
|
||||
|
||||
bool Node::init_template_file(const std::string& path, const std::string& id)
|
||||
{
|
||||
bool ret = false;
|
||||
App::I->ui_task([&]
|
||||
{
|
||||
LayoutManager m;
|
||||
if (m.load(path.c_str()))
|
||||
{
|
||||
auto t = m.get_ref(id.c_str())->m_children[0];
|
||||
for (auto& c : t->m_children)
|
||||
add_child(c->clone());
|
||||
YGNodeCopyStyle(y_node, t->y_node);
|
||||
t->clone_copy(this);
|
||||
ret = true;
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<Node> Node::load_template(const std::string& filename, const std::string& name) const
|
||||
{
|
||||
LayoutManager m;
|
||||
std::shared_ptr<Node> ret;
|
||||
if (m.load(filename.c_str()))
|
||||
ret = std::dynamic_pointer_cast<Node>(std::move(m.get_ref(name.c_str())->m_children[0]));
|
||||
m.unload();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Node::add_child(Node* n)
|
||||
{
|
||||
App::I->ui_task([&]
|
||||
@@ -354,7 +390,7 @@ void Node::add_child(Node* n)
|
||||
n->m_parent->remove_child(n);
|
||||
m_children.emplace_back(n);
|
||||
n->m_parent = this;
|
||||
n->m_manager = m_manager;
|
||||
n->set_manager(m_manager);
|
||||
n->m_destroyed = false;
|
||||
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
|
||||
n->added(this);
|
||||
@@ -370,7 +406,7 @@ void Node::add_child(Node* n, int index)
|
||||
n->m_parent->remove_child(n);
|
||||
m_children.emplace_back(n);
|
||||
n->m_parent = this;
|
||||
n->m_manager = m_manager;
|
||||
n->set_manager(m_manager);
|
||||
n->m_destroyed = false;
|
||||
YGNodeInsertChild(y_node, n->y_node, index);
|
||||
n->added(this);
|
||||
@@ -380,13 +416,13 @@ void Node::add_child(Node* n, int index)
|
||||
|
||||
void Node::add_child(std::shared_ptr<Node> n)
|
||||
{
|
||||
App::I->ui_task([&]
|
||||
App::I->ui_task([this,n]
|
||||
{
|
||||
if (n->m_parent)
|
||||
n->m_parent->remove_child(n.get());
|
||||
m_children.push_back(n);
|
||||
n->m_parent = this;
|
||||
n->m_manager = m_manager;
|
||||
n->set_manager(m_manager);
|
||||
n->m_destroyed = false;
|
||||
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
|
||||
n->added(this);
|
||||
@@ -402,7 +438,7 @@ void Node::add_child(std::shared_ptr<Node> n, int index)
|
||||
n->m_parent->remove_child(n.get());
|
||||
m_children.insert(m_children.begin() + index, n);
|
||||
n->m_parent = this;
|
||||
n->m_manager = m_manager;
|
||||
n->set_manager(m_manager);
|
||||
n->m_destroyed = false;
|
||||
YGNodeInsertChild(y_node, n->y_node, index);
|
||||
n->added(this);
|
||||
@@ -673,8 +709,6 @@ Node::Node(Node&& o)
|
||||
m_name = std::move(o.m_name);
|
||||
m_nodeID_s = std::move(o.m_nodeID_s);
|
||||
m_children = std::move(o.m_children);
|
||||
for (auto& c : m_children)
|
||||
c->m_parent = this;
|
||||
m_nodeID = o.m_nodeID;
|
||||
m_display = o.m_display;
|
||||
m_parent = o.m_parent;
|
||||
@@ -687,7 +721,10 @@ Node::Node(Node&& o)
|
||||
o.y_node = nullptr;
|
||||
o.m_parent = nullptr;
|
||||
|
||||
m_manager = o.m_manager;
|
||||
set_manager(o.m_manager);
|
||||
for (auto& c : m_children)
|
||||
c->m_parent = this;
|
||||
|
||||
current_mouse_capture = o.current_mouse_capture;
|
||||
current_key_capture = o.current_key_capture;
|
||||
m_mouse_captured = o.m_mouse_captured;
|
||||
@@ -1380,7 +1417,7 @@ Node* Node::clone_instantiate() const
|
||||
void Node::clone_copy(Node* dest) const
|
||||
{
|
||||
YGNodeCopyStyle(dest->y_node, y_node);
|
||||
dest->m_manager = m_manager;
|
||||
dest->set_manager(m_manager);
|
||||
|
||||
dest->m_name = m_name;
|
||||
dest->m_nodeID_s = m_nodeID_s;
|
||||
@@ -1392,7 +1429,6 @@ void Node::clone_copy(Node* dest) const
|
||||
dest->m_flood_events = m_flood_events;
|
||||
dest->m_force_mouse_capture = m_force_mouse_capture;
|
||||
|
||||
dest->m_manager = m_manager;
|
||||
dest->current_mouse_capture = current_mouse_capture;
|
||||
dest->current_key_capture = current_key_capture;
|
||||
dest->m_mouse_captured = m_mouse_captured;
|
||||
@@ -1416,7 +1452,7 @@ void Node::clone_children(Node* dest) const
|
||||
std::shared_ptr<Node> cn = c->clone();
|
||||
dest->m_children.push_back(cn);
|
||||
cn->m_parent = dest;
|
||||
cn->m_manager = dest->m_manager;
|
||||
cn->set_manager(dest->m_manager);
|
||||
cn->loaded();
|
||||
YGNodeInsertChild(dest->y_node, cn->y_node, YGNodeGetChildCount(dest->y_node));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user