complete left click event handle
This commit is contained in:
@@ -6,6 +6,39 @@ Plane WidgetBorder::m_plane;
|
||||
Plane WidgetImage::m_plane;
|
||||
Sampler WidgetImage::m_sampler;
|
||||
|
||||
Node* Node::find(const char* ids)
|
||||
{
|
||||
uint16_t id = const_hash(ids);
|
||||
if (id == m_nodeID)
|
||||
return this;
|
||||
for (auto& c : *this)
|
||||
if (c.m_nodeID == id)
|
||||
return &c;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
kEventResult Node::on_event(Event* e)
|
||||
{
|
||||
for (auto& c : m_children)
|
||||
if (c.on_event(e) == kEventResult::Handled)
|
||||
return kEventResult::Handled;
|
||||
if (m_widget)
|
||||
{
|
||||
switch (e->m_cat)
|
||||
{
|
||||
case kEventCategory::MouseEvent:
|
||||
if (point_in_rect(((MouseEvent*)e)->m_pos, m_clip) && m_widget->on_event(e) == kEventResult::Handled)
|
||||
return kEventResult::Handled;
|
||||
break;
|
||||
default:
|
||||
if (m_widget->on_event(e) == kEventResult::Handled)
|
||||
return kEventResult::Handled;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return kEventResult::UnHandled;
|
||||
}
|
||||
|
||||
void Node::update(float width, float height)
|
||||
{
|
||||
YGNodeStyleSetWidth(y_node, width);
|
||||
@@ -29,10 +62,10 @@ void Node::update_internal(const glm::vec2& origin, const glm::mat4& proj)
|
||||
// correct the padding clip
|
||||
// should not clip the padded area
|
||||
// useful to draw decorations
|
||||
float pt = YGNodeLayoutGetPadding(parent->y_node, YGEdgeTop);
|
||||
float pr = YGNodeLayoutGetPadding(parent->y_node, YGEdgeRight);
|
||||
float pb = YGNodeLayoutGetPadding(parent->y_node, YGEdgeBottom);
|
||||
float pl = YGNodeLayoutGetPadding(parent->y_node, YGEdgeLeft);
|
||||
float pt = 0;//YGNodeLayoutGetPadding(parent->y_node, YGEdgeTop);
|
||||
float pr = 0;//YGNodeLayoutGetPadding(parent->y_node, YGEdgeRight);
|
||||
float pb = 0;//YGNodeLayoutGetPadding(parent->y_node, YGEdgeBottom);
|
||||
float pl = 0;//YGNodeLayoutGetPadding(parent->y_node, YGEdgeLeft);
|
||||
glm::vec2 off_p(pl, pt);
|
||||
glm::vec2 off_s(pr, pb);
|
||||
m_clip = glm::vec4(m_pos - off_p, m_size + off_p + off_s);
|
||||
@@ -63,6 +96,10 @@ void Node::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* attr)
|
||||
{
|
||||
switch (ka)
|
||||
{
|
||||
case kAttribute::id:
|
||||
m_nodeID_s = attr->Value();
|
||||
m_nodeID = const_hash(attr->Value());
|
||||
break;
|
||||
case kAttribute::Width:
|
||||
if (strcmp(attr->Value(), "auto") == 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user