Commit 58247cb
authored
fix: Recognize every input callbacks mixin when hit testing (#3994)
Follow up from
#3986 (comment)
`FlameGame.containsEventHandlerAt` backs `GameRenderBox.hitTestSelf`,
which decides (for now) whether the game takes part in the hit test when
the `GameWidget` uses a `HitTestBehavior` other than `opaque`. It
enumerated some callbacks mixins and was missing five others:
`LongPressCallbacks`, `TertiaryTapCallbacks`, `ScrollCallbacks`,
`PointerMoveCallbacks` and `HoverCallbacks`.
Before, components using any of those would silently received no events
under `deferToChild` or `translucent`.
Rather than extending the list and the problem, this adds two marker
interfaces:
- `InputCallbacks`: anchors the whole family, much like `Event` does 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: `FlameGame` stops overriding `containsEventHandlerAt` altogether
- the game reports a hit anywhere within its bounds, and per-component
transparency becomes an explicit opt-in user override written against
`PointerInputCallbacks` using this interface:
```dart
@OverRide
bool containsEventHandlerAt(Vector2 position) =>
componentsAtPoint(position).any((c) => c is PointerInputCallbacks);
```
Regardless, this is a great shape to have the callbacks in, so I am
extracting this first.1 parent 9081a0f commit 58247cb
15 files changed
Lines changed: 155 additions & 17 deletions
File tree
- doc/flame
- packages/flame
- lib
- src
- events/callbacks
- game
- test/game
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
80 | | - | |
81 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
82 | 83 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
| 6 | + | |
| 7 | + | |
5 | 8 | | |
6 | 9 | | |
7 | 10 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
0 commit comments