fix: Recognize every input callbacks mixin when hit testing - #3994
Conversation
| component is DoubleTapCallbacks || | ||
| component is ScaleCallbacks || | ||
| component is SecondaryTapCallbacks) { | ||
| if (component is PointerInputCallbacks) { |
There was a problem hiding this comment.
Pull request overview
This PR fixes FlameGame.containsEventHandlerAt / GameWidget hit-testing under HitTestBehavior.deferToChild and translucent by introducing marker interfaces for input-callback mixins and using them for pointer-position-aware hit testing.
Changes:
- Add
InputCallbacksandPointerInputCallbacksmarker interfaces and export them as public API. - Update pointer/positional callback mixins to implement
PointerInputCallbacks, and simplifyFlameGame.containsEventHandlerAtto check for that marker. - Add regression tests and update
GameWidgetdocumentation to reflect the new behavior.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/flame/test/game/contains_event_handler_at_test.dart | Adds regression coverage for containsEventHandlerAt and GameWidget hit-testing (including LongPressCallbacks under deferToChild). |
| packages/flame/lib/src/game/flame_game.dart | Replaces a hard-coded list of callback mixins with a PointerInputCallbacks marker check for hit testing. |
| packages/flame/lib/src/events/callbacks/input_callbacks.dart | Introduces the root marker interface for all input callback mixins. |
| packages/flame/lib/src/events/callbacks/pointer_input_callbacks.dart | Introduces the positional/pointer subset marker used for hit testing. |
| packages/flame/lib/src/events/callbacks/tap_callbacks.dart | Implements PointerInputCallbacks on TapCallbacks. |
| packages/flame/lib/src/events/callbacks/secondary_tap_callbacks.dart | Implements PointerInputCallbacks on SecondaryTapCallbacks. |
| packages/flame/lib/src/events/callbacks/tertiary_tap_callbacks.dart | Implements PointerInputCallbacks on TertiaryTapCallbacks. |
| packages/flame/lib/src/events/callbacks/drag_callbacks.dart | Implements PointerInputCallbacks on DragCallbacks. |
| packages/flame/lib/src/events/callbacks/double_tap_callbacks.dart | Implements PointerInputCallbacks on DoubleTapCallbacks. |
| packages/flame/lib/src/events/callbacks/scale_callbacks.dart | Implements PointerInputCallbacks on ScaleCallbacks. |
| packages/flame/lib/src/events/callbacks/scroll_callbacks.dart | Implements PointerInputCallbacks on ScrollCallbacks. |
| packages/flame/lib/src/events/callbacks/pointer_move_callbacks.dart | Implements PointerInputCallbacks on PointerMoveCallbacks (covering HoverCallbacks transitively). |
| packages/flame/lib/src/events/callbacks/long_press_callbacks.dart | Implements PointerInputCallbacks on LongPressCallbacks. |
| packages/flame/lib/events.dart | Exports the new marker interfaces as part of the public events.dart surface. |
| doc/flame/game_widget.md | Documents that pointer hit-testing treats PointerInputCallbacks components as interactive. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
9df50d6 to
0e402c1
Compare
erickzanardo
left a comment
There was a problem hiding this comment.
Left a question, but LGTM either way
| /// Marker interface implemented by every input callbacks mixin. | ||
| /// | ||
| /// See `PointerInputCallbacks` for the positional subset. | ||
| abstract interface class InputCallbacks {} |
There was a problem hiding this comment.
Shouldn't this and the other interface define methods?
There was a problem hiding this comment.
they don't actually share any methods or fields atm - this is just a marker interface for type-checking purposes
Description
Follow up from #3986 (comment)
FlameGame.containsEventHandlerAtbacksGameRenderBox.hitTestSelf, which decides (for now) whether the game takes part in the hit test when theGameWidgetuses aHitTestBehaviorother thanopaque. It enumerated some callbacks mixins and was missing five others:LongPressCallbacks,TertiaryTapCallbacks,ScrollCallbacks,PointerMoveCallbacksandHoverCallbacks.Before, components using any of those would silently received no events under
deferToChildortranslucent.Rather than extending the list and the problem, this adds two marker interfaces:
InputCallbacks: anchors the whole family, much likeEventdoes for the event classes.PointerInputCallbacks implements InputCallbacks: the positional/pointer subset, i.e. the mixins whose events carry a position and can therefore take part in hit testing.This serves this and other future purposes, and is public API for users to access and write generic code on top.
I will still explore (after this) following the direction I proposed in #3982:
FlameGamestops overridingcontainsEventHandlerAtaltogether - the game reports a hit anywhere within its bounds, and per-component transparency becomes an explicit opt-in user override written againstPointerInputCallbacksusing this interface:Regardless, this is a great shape to have the callbacks in, so I am extracting this first.
Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?