add messagebox to template binding, add absolute positioning layout, add observer instead of stack based node traversal which is not great in case of hierarchical traversal
This commit is contained in:
@@ -62,6 +62,16 @@ void Node::add_child(Node* n)
|
||||
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
|
||||
}
|
||||
|
||||
void Node::remove_child(Node* n)
|
||||
{
|
||||
auto i = std::find_if(m_children.begin(), m_children.end(), [=](std::unique_ptr<Node>& ptr)
|
||||
{
|
||||
return ptr.get() == n;
|
||||
});
|
||||
m_children.erase(i);
|
||||
YGNodeRemoveChild(y_node, n->y_node);
|
||||
}
|
||||
|
||||
void Node::update(float width, float height)
|
||||
{
|
||||
YGNodeStyleSetWidth(y_node, width);
|
||||
@@ -212,6 +222,34 @@ void Node::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr)
|
||||
YGNodeStyleSetAlignItems(y_node, v);
|
||||
break;
|
||||
}
|
||||
case kAttribute::Positioning:
|
||||
{
|
||||
YGPositionType v = YGPositionTypeRelative;
|
||||
if (strcmp("relative", attr->Value()) == 0)
|
||||
v = YGPositionTypeRelative;
|
||||
else if (strcmp("absolute", attr->Value()) == 0)
|
||||
v = YGPositionTypeAbsolute;
|
||||
YGNodeStyleSetPositionType(y_node, v);
|
||||
break;
|
||||
}
|
||||
case kAttribute::Position:
|
||||
{
|
||||
glm::vec4 v;
|
||||
int n = sscanf(attr->Value(), "%f %f %f %f", &v.x, &v.y, &v.z, &v.w);
|
||||
if (n == 2)
|
||||
{
|
||||
YGNodeStyleSetPosition(y_node, YGEdgeLeft, v.x);
|
||||
YGNodeStyleSetPosition(y_node, YGEdgeTop, v.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
YGNodeStyleSetPadding(y_node, YGEdgeLeft, v.x);
|
||||
YGNodeStyleSetPadding(y_node, YGEdgeTop, v.y);
|
||||
YGNodeStyleSetPadding(y_node, YGEdgeRight, v.z);
|
||||
YGNodeStyleSetPadding(y_node, YGEdgeBottom, v.w);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kAttribute::Padding:
|
||||
{
|
||||
glm::vec4 pad;
|
||||
@@ -333,6 +371,7 @@ Node* Node::clone()
|
||||
{
|
||||
Node* n = clone_instantiate();
|
||||
clone_copy(n);
|
||||
clone_children(n);
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -345,11 +384,24 @@ void Node::clone_copy(Node* dest) const
|
||||
{
|
||||
YGNodeCopyStyle(dest->y_node, y_node);
|
||||
dest->m_manager = m_manager;
|
||||
|
||||
dest->m_name = m_name;
|
||||
dest->m_nodeID_s = m_nodeID_s;
|
||||
dest->m_nodeID = m_nodeID;
|
||||
dest->m_display = m_display;
|
||||
dest->m_pos = m_pos;
|
||||
dest->m_size = m_size;
|
||||
dest->m_clip = m_clip;
|
||||
}
|
||||
|
||||
void Node::clone_children(Node* dest) const
|
||||
{
|
||||
for (auto& c : m_children)
|
||||
{
|
||||
Node* cn = c->clone();
|
||||
dest->m_children.emplace_back(cn);
|
||||
cn->parent = dest;
|
||||
cn->m_manager = m_manager;
|
||||
YGNodeInsertChild(dest->y_node, cn->y_node, YGNodeGetChildCount(dest->y_node));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user