AABB / Hit Testing System #138

Closed
opened 2025-11-27 18:34:41 +00:00 by john · 1 comment
Owner

Universal axis-aligned bounding box computation for all UIDrawables, enabling mouse event handling and composite bounds calculation.

Context

Mouse events (click, enter, exit) require knowing whether a point is inside an element. Currently hit testing is ad-hoc. This issue creates a consistent AABB system across all drawable types.

Definition of Done

  • All UIDrawable subclasses implement getBounds() returning sf::FloatRect
  • UIFrame, UISprite, UIGrid: straightforward AABB from position + size
  • UICaption: compute bounds after render, cache until text/font changes
  • UIEntity: bounds relative to containing grid's transform
  • Composite AABB: parent's bounds union with all children's bounds
  • overflow property on UIFrame: when true, clip children to parent bounds during render
  • Python-accessible bounds property returning (x, y, w, h) tuple
  • Hit testing utility: point_in_bounds(drawable, x, y) considering global position

Technical Notes

Caption Challenge

SFML doesn't provide text bounds until after rendering. Solution:

  • Call sf::Text::getLocalBounds() after setting string/font
  • Cache result, invalidate when text or font changes
  • Dirty flag integration: text change marks AABB dirty

Composite Bounds

For parent-child hierarchies (post #122):

composite_bounds = parent.bounds
for child in parent.children:
    composite_bounds = union(composite_bounds, child.global_bounds)

Overflow Clipping

When frame.overflow = False (default), children render beyond parent bounds.
When frame.overflow = True, use scissor test or render-to-texture to clip.

Dependencies

  • Blocked by: #122 (Parent-Child UI System) - need hierarchy for composite bounds
  • Blocked by: #102 (Global Position) - need global coords for hit testing nested elements
  • Enables: #111 (Click Events)
  • Enables: Mouse Enter/Exit Events (NEW)
  • Enables: Grid Cell Events (NEW)
Universal axis-aligned bounding box computation for all UIDrawables, enabling mouse event handling and composite bounds calculation. ## Context Mouse events (click, enter, exit) require knowing whether a point is inside an element. Currently hit testing is ad-hoc. This issue creates a consistent AABB system across all drawable types. ## Definition of Done - [ ] All UIDrawable subclasses implement `getBounds()` returning `sf::FloatRect` - [ ] UIFrame, UISprite, UIGrid: straightforward AABB from position + size - [ ] UICaption: compute bounds after render, cache until text/font changes - [ ] UIEntity: bounds relative to containing grid's transform - [ ] Composite AABB: parent's bounds union with all children's bounds - [ ] `overflow` property on UIFrame: when true, clip children to parent bounds during render - [ ] Python-accessible `bounds` property returning (x, y, w, h) tuple - [ ] Hit testing utility: `point_in_bounds(drawable, x, y)` considering global position ## Technical Notes ### Caption Challenge SFML doesn't provide text bounds until after rendering. Solution: - Call `sf::Text::getLocalBounds()` after setting string/font - Cache result, invalidate when text or font changes - Dirty flag integration: text change marks AABB dirty ### Composite Bounds For parent-child hierarchies (post #122): ``` composite_bounds = parent.bounds for child in parent.children: composite_bounds = union(composite_bounds, child.global_bounds) ``` ### Overflow Clipping When `frame.overflow = False` (default), children render beyond parent bounds. When `frame.overflow = True`, use scissor test or render-to-texture to clip. ## Dependencies - **Blocked by**: #122 (Parent-Child UI System) - need hierarchy for composite bounds - **Blocked by**: #102 (Global Position) - need global coords for hit testing nested elements ## Related Issues - Enables: #111 (Click Events) - Enables: Mouse Enter/Exit Events (NEW) - Enables: Grid Cell Events (NEW)
john added this to the Cursor, Grid, and Callback project 2025-11-27 19:28:52 +00:00
Author
Owner

closed-by: 6d5a5e9e16

closed-by: 6d5a5e9e16e415e37fe1d40bd9e43d6301fb41c6
john closed this issue 2025-11-28 19:48:41 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: john/McRogueFace#138
No description provided.