Skip to content

Commit

Permalink
Allow hit testing to detect children outside of the parent's bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Dec 16, 2024
1 parent fc0b97c commit c75bf78
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/blitz-dom/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,15 +988,22 @@ impl Node {
let x = x - self.final_layout.location.x + self.scroll_offset.x as f32;
let y = y - self.final_layout.location.y + self.scroll_offset.y as f32;

let size = self.final_layout.size;
if x < 0.0
|| x > size.width + self.scroll_offset.x as f32
let content_size = self.final_layout.content_size;
let matches_content = !(x < 0.0
|| x > content_size.width + self.scroll_offset.x as f32
|| y < 0.0
|| y > size.height + self.scroll_offset.y as f32
{
|| y > content_size.height + self.scroll_offset.y as f32);

if !matches_content {
return None;
}

let size = self.final_layout.size;
let matches_self = !(x < 0.0
|| x > size.width + self.scroll_offset.x as f32
|| y < 0.0
|| y > size.height + self.scroll_offset.y as f32);

// Call `.hit()` on each child in turn. If any return `Some` then return that value. Else return `Some(self.id).
self.paint_children
.borrow()
Expand All @@ -1008,7 +1015,8 @@ impl Node {
node_id: self.id,
x,
y,
}))
})
.filter(|_| matches_self))
}

/// Computes the Document-relative coordinates of the Node
Expand Down

0 comments on commit c75bf78

Please sign in to comment.