wordmaker: start a swipe only on a letter tile (#ux-audit)
- Commit
c49ab2bb88d6ce141361bd4f7db29d1a67e8ad86- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 01:17 UTC (23 days ago)
- Parents
14a80df
Symptom: a drag that started in the middle of the wheel, or in one of the empty corners of the wheel box, immediately selected a letter - whichever one lay in the direction of the touch - even though the finger never touched it. Root cause: onDragStart chose the first letter with getLetterAtArc, which maps the angle of the touch around the wheel centre to the nearest letter regardless of distance. Moves after that already used the per-tile circle test, so only the first letter was affected. Fix: the first letter uses the same tile-circle hit test (WheelGeometry.letterAt) as the rest of the swipe. Because detectDragGestures reports the position where touch slop was crossed (which can already be past the first tile on a fast flick), a small Initial-pass pointer handler records the actual down position without consuming it, and the swipe starts with the tile under the down point and/or the tile under the slop point. getLetterAtArc is removed. User-visible effect: starting a drag off the letters selects nothing until the finger reaches a tile; fast swipes that start on a tile keep that tile as their first letter. Verification: LetterChooserInputTest - a drag from the centre towards C then on to T spells "T" (was "CT"), a drag from the empty top-left corner to A spells "A", and a single jump from C to A still spells "CA".
Diff
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.ktindex ba0f52a3ee..0e0edc87f0 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooser.kt@@ -2,6 +2,8 @@ package com.vayunmathur.games.wordmaker.ui.components import androidx.compose.foundation.Canvas import androidx.compose.foundation.clickable+import androidx.compose.foundation.gestures.awaitEachGesture+import androidx.compose.foundation.gestures.awaitFirstDown import androidx.compose.foundation.gestures.detectDragGestures import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxWithConstraints@@ -37,6 +39,7 @@ import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.StrokeCap import androidx.compose.ui.graphics.graphicsLayer+import androidx.compose.ui.input.pointer.PointerEventPass import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.platform.LocalDensity@@ -52,9 +55,7 @@ import com.vayunmathur.games.wordmaker.ui.ChooserLetter import com.vayunmathur.library.ui.animatedDp import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch-import kotlin.math.atan2 import kotlin.math.cos-import kotlin.math.roundToInt import kotlin.math.sin @Composable@@ -176,25 +177,32 @@ fun LetterChooser( // positions without restarting a swipe in progress. val currentGeometry by rememberUpdatedState(geometry) - fun getLetterAtArc(position: Offset): Int {- val relative = position - currentGeometry.center- val angleStep = 2 * Math.PI / letters.size.toDouble()- var normalizedAngle = atan2(relative.y, relative.x) + Math.PI / 2- while (normalizedAngle < 0) normalizedAngle += 2 * Math.PI- while (normalizedAngle >= 2 * Math.PI) normalizedAngle -= 2 * Math.PI- return (normalizedAngle / angleStep).roundToInt() % letters.size- }+ // Where the finger went down. The drag detector only reports the point where the+ // touch slop was crossed, which can already be past the first letter.+ var dragDown by remember { mutableStateOf<Offset?>(null) } // The tiles' parent handles the swipe, so it sees every move after the tiles // (which only take taps, in tap-to-spell mode). Box( Modifier .fillMaxSize()+ .pointerInput(Unit) {+ awaitEachGesture {+ dragDown = awaitFirstDown(requireUnconsumed = false, pass = PointerEventPass.Initial).position+ }+ } .pointerInput(letters) { detectDragGestures( onDragStart = { startOffset -> currentDragPosition = startOffset- selectedLettersIndices = listOf(getLetterAtArc(startOffset))+ // Only a touch on a tile selects it. A drag that starts in the+ // middle of the wheel or in a corner used to pick a letter by+ // angle alone; now it selects nothing until it reaches a tile.+ val geometry = currentGeometry+ selectedLettersIndices = listOfNotNull(+ dragDown?.let(geometry::letterAt),+ geometry.letterAt(startOffset),+ ).distinct() }, onDrag = { change, _ -> currentDragPosition = change.position
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooserInputTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooserInputTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooserInputTest.ktindex 396740d477..242ab5e403 100644--- a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooserInputTest.kt+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/components/LetterChooserInputTest.kt@@ -111,4 +111,30 @@ class LetterChooserInputTest { rule.waitForIdle() assertEquals(listOf("CAT"), submitted) }++ @Test fun dragStartingInTheCentreOrACornerSelectsNoLetterUntilItReachesOne() {+ val submitted = mutableListOf<String>()+ setChooser { submitted += it }+ val c = centerOf('C'); val a = centerOf('A'); val t = centerOf('T'); val s = centerOf('S')+ val wheelCentre = Offset(c.x, s.y)+ val topLeftCorner = Offset(s.x, c.y)++ // Starting in the centre and heading up used to select C by angle alone.+ rule.onRoot().performTouchInput { down(wheelCentre); moveTo(wheelCentre + Offset(0f, -12f)); moveTo(t); up() }+ rule.waitForIdle()+ // Same from the empty top-left corner of the wheel box.+ rule.onRoot().performTouchInput { down(topLeftCorner); moveTo(topLeftCorner + Offset(12f, 0f)); moveTo(a); up() }+ rule.waitForIdle()+ assertEquals(listOf("T", "A"), submitted)+ }++ @Test fun dragStartingOnATileKeepsThatTileEvenIfTheSlopEndsElsewhere() {+ val submitted = mutableListOf<String>()+ setChooser { submitted += it }+ val c = centerOf('C'); val a = centerOf('A')+ // One big move: the slop is only crossed at A, but the finger went down on C.+ rule.onRoot().performTouchInput { down(c); moveTo(a); up() }+ rule.waitForIdle()+ assertEquals(listOf("CA"), submitted)+ } }