Skip to content

feat!: Make transparent hit-test opt-in via DeferHitTestToComponents - #4062

Merged
luanpotter merged 2 commits into
mainfrom
luan.hit-test
Sep 27, 2026
Merged

luanpotter merged 2 commits into
mainfrom
luan.hit-test

Conversation

@luanpotter

Copy link
Copy Markdown
Member

Description

Make transparent hit-test opt-in via DeferHitTestToComponents.

FlameGame used to answer containsEventHandlerAt by walking the component tree and reporting a hit only where a component implemented PointerInputCallbacks, which was an expensive recursive check for a feature I'd imagine nearly no one uses.

This changes the default - it now reports a hit everywhere, like the base Game class, and the tree walk is opt-in via a mixin. This only affects games built with HitTestBehavior.deferToChild, since opaque and translucent never consult the game. If you use deferToChild to let events reach widgets behind the GameWidget, add the mixin, or override containsEventHandlerAt with a cheaper rule of your own.

I think this is a saner alternative to @spydon 's #3982 , as we discussed before. The ultimate control is in the user hands to implement this in a more effective way w/o the mixin. This also uses the new marker interface to avoid having to list all types of click handlers.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Migration instructions

Only applicable if you do want this specific behaviour; add the mixin to your FlameGame:

// Before: implicit, and paid for on every hit test under deferToChild
class MyGame extends FlameGame {}

// After
class MyGame extends FlameGame with DeferHitTestToComponents {}

@luanpotter
luanpotter marked this pull request as ready for review September 27, 2026 16:40
@luanpotter
luanpotter requested a review from spydon September 27, 2026 16:40

@spydon spydon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, this is better indeed!

@luanpotter
luanpotter merged commit 94f692f into main Sep 27, 2026
8 checks passed
@luanpotter
luanpotter deleted the luan.hit-test branch September 27, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants