Add Multitouch rollover support for the gamepad buttons - #29
Open
SerSaumy wants to merge 2 commits into
Open
Conversation
- Add MultiTouchController (ui/composables/TouchZoneController.kt) that hit-tests every active pointer against registered button bounds instead of relying on one clickable per button. - MAX_TRACKED_TOUCH_POINTS = 4: explicit, tunable cap on simultaneously tracked fingers on the button layer. - Rollover: dragging an already-down finger from one button directly into a neighbouring one releases the first and presses the second, without lifting off the screen. - Wire the controller into DrawGamepad (ui/composables/Gamepad.kt) via CompositionLocalProvider. - Migrate FaceButtons.kt, Dpad.kt, CentralButtons.kt from Button/OutlinedButton/OutlinedIconButton + clickable to Surface + Modifier.touchZone, with an animated press-color for visual feedback (replacing the lost ripple). - Trigger.kt and AnalogStick.kt intentionally left untouched (drag-based analog controls, not discrete buttons).
|
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.


What this does
Replaces the per-button
clickablegesture detectors on the D-pad, face buttons,shoulder buttons, and menu buttons with a shared
MultiTouchControllerthathit-tests every active pointer against every button's bounds. This adds two
related behaviors:
MAX_TRACKED_TOUCH_POINTSinthe new
TouchZoneController.kt) — previously each button's gesture detectoronly knew about its own pointer, with no shared limit or coordination across
the cluster.
finger, drag it onto a different button — the first releases and the second
presses automatically. No need to lift and re-tap to switch buttons mid-gesture.
Analog sticks (
AnalogStick.kt) and triggers (Trigger.kt) are unchangedon purpose — they're continuous drag controls, not discrete buttons, so
rollover doesn't apply to them the same way.
Why
Each button previously owned its own
MutableInteractionSource+clickable,so no button's gesture detector could know a finger had slid over from a
neighboring button, and there was no single place to reason about "how many
fingers is this cluster tracking." Rollover requires looking at all buttons'
bounds and all active pointers together, so the touch handling moved to one
shared controller instead.
Changes
ui/composables/TouchZoneController.kt—MultiTouchController(zone registration, pointer-to-zone tracking, hit-testing, press/release
callbacks),
Modifier.multiTouchDispatcher(manual low-level pointertracking via
awaitPointerEventScope),Modifier.touchZone(per-buttonregistration), plus
LocalMultiTouchController/LocalTouchContainerCoordinates.ui/composables/Gamepad.kt— wires the shared controller andcontainer coordinates into
DrawGamepadviaCompositionLocalProvider,releases all buttons on teardown so nothing gets stuck "pressed."
ui/composables/FaceButtons.kt,Dpad.kt,CentralButtons.kt— swapped
Button/OutlinedButton/OutlinedIconButton+clickableforSurface+Modifier.touchZone, with an animated background tint on press(replacing the ripple lost by moving off
clickable).Testing
Built and tested on-device (not just emulator, since emulators generally only
simulate 1-2 touch points). Verified:
the transition
than stealing a tracking slot
mid-touch
Notes
MAX_TRACKED_TOUCH_POINTSis a single constant if this limit should beraised/lowered later.
(
face_A,dpad_UP,shoulder_LEFT, etc.) if you'd prefer a differentconvention.