added NodeButton as composition and cleaned up old Widget code

This commit is contained in:
2017-02-11 15:51:22 +00:00
parent b1abb42dd5
commit fb25ffb347
4 changed files with 113 additions and 378 deletions

View File

@@ -65,6 +65,14 @@ kEventResult Node::on_event(Event* e)
return kEventResult::Available;
}
void Node::add_child(Node* n)
{
m_children.emplace_back(n);
n->parent = this;
n->m_manager = m_manager;
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
}
void Node::update(float width, float height)
{
YGNodeStyleSetWidth(y_node, width);
@@ -263,7 +271,9 @@ void Node::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr)
void Node::load_internal(const tinyxml2::XMLElement* x_node)
{
m_name = x_node->Name();
init();
auto attr = x_node->FirstAttribute();
while (attr)
{
@@ -282,54 +292,46 @@ void Node::load_internal(const tinyxml2::XMLElement* x_node)
case kWidget::Border:
{
auto n = new NodeBorder();
m_children.emplace_back(n);
n->parent = this;
n->m_manager = m_manager;
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
add_child(n);
n->load_internal(x_child);
break;
}
// case kWidget::Shape:
// break;
case kWidget::Image:
{
auto n = new NodeImage();
add_child(n);
n->load_internal(x_child);
break;
}
case kWidget::Text:
{
auto n = new NodeText();
add_child(n);
n->load_internal(x_child);
break;
}
case kWidget::Button:
{
auto n = new NodeButton();
add_child(n);
n->load_internal(x_child);
break;
}
// case kWidget::Shape:
// break;
case kWidget::Image:
{
auto n = new NodeImage();
m_children.emplace_back(n);
n->parent = this;
n->m_manager = m_manager;
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
n->load_internal(x_child);
break;
}
case kWidget::Text:
{
auto n = new NodeText();
m_children.emplace_back(n);
n->parent = this;
n->m_manager = m_manager;
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
n->load_internal(x_child);
break;
}
case kWidget::Ref:
{
auto ids = x_child->Attribute("id");
auto id = const_hash(ids);
auto& ref = (*m_manager)[id];
auto n = ref.clone();
m_children.emplace_back(n);
n->parent = this;
n->m_manager = m_manager;
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
auto& ref = (*m_manager)[id].m_children[0];
auto n = ref->clone();
add_child(n);
break;
}
default:
{
auto n = new Node();
m_children.emplace_back(n);
n->parent = this;
n->m_manager = m_manager;
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
add_child(n);
n->load_internal(x_child);
break;
}