improve mouse events propagation
This commit is contained in:
@@ -111,18 +111,19 @@ kEventResult Node::on_event(Event* e)
|
||||
if (e->m_cat == kEventCategory::MouseEvent)
|
||||
{
|
||||
MouseEvent* me = static_cast<MouseEvent*>(e);
|
||||
skip_children |= m_mouse_inside && !point_in_rect(me->m_pos, m_clip);
|
||||
skip_children |= !m_mouse_inside && !point_in_rect(me->m_pos, m_clip);
|
||||
}
|
||||
|
||||
skip_children |= (e->m_cat == kEventCategory::MouseEvent || e->m_cat == kEventCategory::GestureEvent) &&
|
||||
(m_mouse_captured) && (root()->current_mouse_capture == this) && m_capture_children; // <-- THIS IS WRONG "!m_capture_children" is correct, but it breaks everything if changed
|
||||
|
||||
|
||||
if (!m_display || glm::any(glm::lessThanEqual(zw(m_clip), { 0, 0 })))
|
||||
return kEventResult::Available;
|
||||
|
||||
if (!skip_children)
|
||||
{
|
||||
auto children_copy = m_children; // make a copy for safety
|
||||
// make a copy because any handler can change the children vector
|
||||
auto children_copy = m_children;
|
||||
for (auto it = children_copy.rbegin(); it != children_copy.rend(); ++it)
|
||||
{
|
||||
if ((*it)->on_event(e) == kEventResult::Consumed)
|
||||
|
||||
@@ -210,6 +210,11 @@ NodeLayer* NodePanelLayer::add_layer(const char* name, bool add_history /*= true
|
||||
l->on_selected = std::bind(&NodePanelLayer::handle_layer_selected, this, std::placeholders::_1);
|
||||
l->on_visibility_changed = std::bind(&NodePanelLayer::handle_layer_visibility, this, std::placeholders::_1, std::placeholders::_2);
|
||||
l->on_highlight = std::bind(&NodePanelLayer::handle_layer_highlight, this, std::placeholders::_1, std::placeholders::_2);
|
||||
|
||||
// reset selected state
|
||||
for (const auto& c : m_layers_container->m_children)
|
||||
((NodeLayer*)c.get())->m_selected = false;
|
||||
|
||||
if (m_current_layer)
|
||||
m_current_layer->m_selected = false;
|
||||
m_current_layer = l.get();
|
||||
@@ -268,6 +273,11 @@ void NodePanelLayer::remove_layer(NodeLayer* layer, bool add_history /*= true*/)
|
||||
m_layers_container->remove_child(layer);
|
||||
m_layers.erase(it);
|
||||
i = std::min<int>(i, (int)m_layers.size() - 1);
|
||||
|
||||
// reset selected state
|
||||
for (const auto& c : m_layers_container->m_children)
|
||||
((NodeLayer*)c.get())->m_selected = false;
|
||||
|
||||
m_current_layer = (NodeLayer*)m_layers_container->get_child_at(i);
|
||||
m_current_layer->m_selected = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user