Module: Thaum::HitTest
- Defined in:
- lib/thaum/hit_test.rb
Overview
Mouse hit testing for the layout tree and modals.
Class Method Summary collapse
-
.hit(app:, abs_x:, abs_y:) ⇒ Object
Walk every leaf Sigil with an allocated rect, return the LAST one whose rect contains (abs_x, abs_y).
- .point_in_rect?(x:, y:, rect:) ⇒ Boolean
Class Method Details
.hit(app:, abs_x:, abs_y:) ⇒ Object
Walk every leaf Sigil with an allocated rect, return the LAST one whose rect contains (abs_x, abs_y). Last-in-render-order wins on overlap, matching the draw walk in Painter.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/thaum/hit_test.rb', line 11 def hit(app:, abs_x:, abs_y:) hit = nil Tree.walk(app) do |node| next unless node.is_a?(Sigil) rect = node.rect or next next unless point_in_rect?(x: abs_x, y: abs_y, rect: rect) hit = node end hit end |
.point_in_rect?(x:, y:, rect:) ⇒ Boolean
24 25 26 |
# File 'lib/thaum/hit_test.rb', line 24 def point_in_rect?(x:, y:, rect:) x >= rect.x && x < rect.x + rect.width && y >= rect.y && y < rect.y + rect.height end |