change node children from unique to shared ptr, rename Canvas2D to StrokePreview, add panel toolbar with icon buttons to toggle

This commit is contained in:
2017-03-25 17:28:57 +00:00
parent 4da0c3696a
commit a1e3fd4ecf
15 changed files with 216 additions and 65 deletions

View File

@@ -9,7 +9,7 @@ Plane NodeBorder::m_plane;
Plane NodeImage::m_plane;
Sampler NodeImage::m_sampler;
std::map<std::string, glm::vec4> NodeIcon::m_icons;
ui::Shader NodeCanvas2D::m_shader;
ui::Shader NodeStrokePreview::m_shader;
kEventResult Node::on_event(Event* e)
{
@@ -112,9 +112,23 @@ void Node::add_child(Node* n, int index)
YGNodeInsertChild(y_node, n->y_node, index);
}
void Node::add_child(std::shared_ptr<Node> n)
{
m_children.push_back(n);
n->parent = this;
n->m_manager = m_manager;
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
}
void Node::add_child(std::shared_ptr<Node> n, int index)
{
m_children.push_back(n);
n->parent = this;
n->m_manager = m_manager;
YGNodeInsertChild(y_node, n->y_node, index);
}
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; });
auto i = std::find_if(m_children.begin(), m_children.end(), [=](auto& ptr) { return ptr.get() == n; });
if (i != m_children.end())
{
YGNodeRemoveChild(y_node, n->y_node);
@@ -122,6 +136,12 @@ void Node::remove_child(Node* n)
}
}
void Node::remove_all_children()
{
for (auto& n : m_children)
YGNodeRemoveChild(y_node, n->y_node);
m_children.clear();
}
void Node::move_child(Node* n, int index)
{
YGNodeRemoveChild(y_node, n->y_node);
@@ -443,7 +463,7 @@ void Node::load_internal(const tinyxml2::XMLElement* x_node)
CASE(kWidget::PanelColor, NodePanelColor);
CASE(kWidget::PanelStroke, NodePanelStroke);
CASE(kWidget::ColorQuad, NodeColorQuad);
CASE(kWidget::Canvas2D, NodeCanvas2D);
CASE(kWidget::Canvas2D, NodeStrokePreview);
#undef CASE
case kWidget::Ref:
{