Skip to content
Snippets Groups Projects
Commit 3aa6a251 authored by MrGVSV's avatar MrGVSV
Browse files

Updated get_nodes_under method to be more generic

parent d64cb0e5
No related branches found
No related tags found
No related merge requests found
......@@ -360,7 +360,7 @@ impl KayakContext {
match input_event {
InputEvent::MouseMoved(point) => {
if let Some((next, next_nodes)) = self.widget_manager.get_nodes_under(*point, None) {
if let Some((next, next_nodes)) = self.widget_manager.get_nodes_under(*point, None, true) {
event_stream.push(Event::new(next, EventType::Hover));
// Mouse In - Applies to all matching nodes
......@@ -373,7 +373,7 @@ impl KayakContext {
}
}
if let Some((.., prev_nodes)) = self.widget_manager.get_nodes_under(self.last_mouse_position, None) {
if let Some((.., prev_nodes)) = self.widget_manager.get_nodes_under(self.last_mouse_position, None, true) {
// Mouse Out - Applies to all matching nodes
for prev in prev_nodes {
if let Some(rect) = self.widget_manager.layout_cache.rect.get(&prev) {
......@@ -391,7 +391,7 @@ impl KayakContext {
// Reset global mouse pressed
self.is_mouse_pressed = true;
if let Some((prev, ..)) = self.widget_manager.get_nodes_under(self.last_mouse_position, None) {
if let Some((prev, ..)) = self.widget_manager.get_nodes_under(self.last_mouse_position, None, true) {
event_stream.push(Event::new(prev, EventType::MouseDown));
// Find a focusable widget in the hierarchy
......@@ -427,7 +427,7 @@ impl KayakContext {
// Reset global mouse pressed
self.is_mouse_pressed = false;
if let Some((prev, ..)) = self.widget_manager.get_nodes_under(self.last_mouse_position, None) {
if let Some((prev, ..)) = self.widget_manager.get_nodes_under(self.last_mouse_position, None, true) {
event_stream.push(Event::new(prev, EventType::MouseUp));
if Self::contains_event(
......
......@@ -15,4 +15,4 @@ impl Default for PointerEvents {
fn default() -> Self {
Self::All
}
}
\ No newline at end of file
}
......@@ -395,8 +395,9 @@ impl WidgetManager {
///
/// * `position`: The 2D point to check under
/// * `parent`: The parent to start at (or `None` for the root element)
/// * `respect_pointer_events`: Whether a widget's `pointer_events` style should be respected
///
pub fn get_nodes_under(&self, position: (f32, f32), parent: Option<Index>) -> Option<(Index, Vec<Index>)> {
pub fn get_nodes_under(&self, position: (f32, f32), parent: Option<Index>, respect_pointer_events: bool) -> Option<(Index, Vec<Index>)> {
// TODO: Find a more efficient way of finding a node at a given point
// The main issue with recursively checking if a node contains the point is that we cannot be sure
......@@ -426,9 +427,11 @@ impl WidgetManager {
while stack.len() > 0 {
let (parent, nest_level) = stack.pop().unwrap();
let mut pointer_events = PointerEvents::default();
if let Some(widget) = self.current_widgets.get(parent).unwrap() {
if let Some(styles) = widget.get_styles() {
pointer_events = styles.pointer_events.resolve();
if respect_pointer_events {
if let Some(widget) = self.current_widgets.get(parent).unwrap() {
if let Some(styles) = widget.get_styles() {
pointer_events = styles.pointer_events.resolve();
}
}
}
......@@ -472,7 +475,7 @@ impl WidgetManager {
/// Get the "best match" node at the given position
#[allow(dead_code)]
pub fn get_node_at(&self, position: (f32, f32), parent: Option<Index>) -> Option<Index> {
Some(self.get_nodes_under(position, parent)?.0)
pub fn get_node_at(&self, position: (f32, f32), parent: Option<Index>, respect_pointer_events: bool) -> Option<Index> {
Some(self.get_nodes_under(position, parent, respect_pointer_events)?.0)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment