fix: Recognize every input callbacks mixin when hit testing - #3994
Open
luanpotter wants to merge 2 commits into
Open
fix: Recognize every input callbacks mixin when hit testing#3994luanpotter wants to merge 2 commits into
luanpotter wants to merge 2 commits into
Conversation
luanpotter
commented
Aug 12, 2026
| component is DoubleTapCallbacks || | ||
| component is ScaleCallbacks || | ||
| component is SecondaryTapCallbacks) { | ||
| if (component is PointerInputCallbacks) { |
Contributor
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.
luanpotter
force-pushed
the
luan.input-callbacks
branch
from
August 12, 2026 03:00
9df50d6 to
0e402c1
Compare
erickzanardo
approved these changes
Aug 12, 2026
erickzanardo
left a comment
Member
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 {} |
Member
There was a problem hiding this comment.
Shouldn't this and the other interface define methods?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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?