wordmaker: land the bonus-word flight on the bonus button (#ux-audit)
- Commit
495dcc21a27897eb7546789cec6219eaa3d21a21- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 01:22 UTC (23 days ago)
- Parents
39ccd85
Symptom: when a bonus word was accepted, the word flew down and off the bottom of the screen instead of into the bonus-words button. Root cause: the flight interpolated between the word box and the bonus button using their localToRoot positions, but drew the result inside the game body's root Box, which itself sits below the top app bar. Unlike the solution-letter flights (WordPlaceAnimations, which subtract rootOffset), the bonus flight never subtracted that offset, so it landed one app-bar height (plus insets) too low. It also aimed the word's top-left corner at the button's top-left corner. Fix: - The bonus button reports its centre (localToRoot of the centre point, measured outside the shake layer) instead of its corner. - New pure bonusFlightOffset() converts both ends into the overlay's space by subtracting rootOffset and ends with the word's centre on the button's centre (using the flying word's measured size), so as the word shrinks around its centre it disappears into the button. - WordGameOverlays takes rootOffset and bonusButtonCenter; the offset is computed in the placement phase (absoluteOffset lambda). - The bonus badge from c929c4b50 is untouched: it stays on the BadgedBox inside the positioned corner Box. User-visible effect: accepted bonus words fly from the word box into the bonus-words button. Verification: WordFlightPlacementTest - unit test of bonusFlightOffset (root-offset subtraction and centring), and a Compose test with the overlay inset 150 dp from the root: a landed bonus word is centred on the bonus button's root position.
Diff
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameOverlays.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameOverlays.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameOverlays.ktindex 10f32711d3..4c4a234ed4 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameOverlays.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameOverlays.kt@@ -10,15 +10,21 @@ import androidx.compose.foundation.layout.absoluteOffset import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue import androidx.compose.ui.AbsoluteAlignment import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.lerp+import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.IntOffset+import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.TextUnit import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp@@ -54,8 +60,12 @@ fun WordGameOverlays( onDismissDefinition: () -> Unit, animatedWord: String?, animationProgress: Animatable<Float, AnimationVector1D>,+ /** Root position of the formed-word box's text: where a bonus word takes off. */ wordBoxOffset: Offset,- bonusButtonOffset: Offset,+ /** Root position of the bonus button's centre: where a bonus word lands. */+ bonusButtonCenter: Offset,+ /** Root position of the overlay's own origin; flights are drawn relative to it. */+ rootOffset: Offset, animatedLetters: List<AnimatedLetter>, scale: Float, ) {@@ -97,8 +107,8 @@ fun WordGameOverlays( if (animatedWord == null && animatedLetters.isEmpty()) return Box(Modifier.fillMaxSize(), contentAlignment = AbsoluteAlignment.TopLeft) { animatedWord?.let { word ->+ var wordSize by remember { mutableStateOf(IntSize.Zero) } val progress = animationProgress.value- val currentOffset = lerp(wordBoxOffset, bonusButtonOffset, progress) val alpha = 1f - progress val animScale = 1f - (progress * 0.5f) @@ -107,7 +117,13 @@ fun WordGameOverlays( fontWeight = FontWeight.Bold, fontSize = 32.sp, modifier = Modifier- .absoluteOffset { IntOffset(currentOffset.x.toInt(), currentOffset.y.toInt()) }+ .onSizeChanged { wordSize = it }+ .absoluteOffset {+ val offset = bonusFlightOffset(+ wordBoxOffset, bonusButtonCenter, rootOffset, wordSize, animationProgress.value+ )+ IntOffset(offset.x.toInt(), offset.y.toInt())+ } .graphicsLayer( scaleX = animScale, scaleY = animScale,
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.ktindex e0741a2743..8d44aaf4ad 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameScreen.kt@@ -104,7 +104,7 @@ fun WordGameScreen( // Animation state: solution and bonus word-place flights queue up (#807) so a fast // second word waits for the first flight to finish instead of cancelling it. var wordBoxOffset by remember(levelKey) { mutableStateOf(Offset.Zero) }- var bonusButtonOffset by remember(levelKey) { mutableStateOf(Offset.Zero) }+ var bonusButtonCenter by remember(levelKey) { mutableStateOf(Offset.Zero) } var crosswordCellPositions by remember(levelKey) { mutableStateOf<Map<Pair<Int, Int>, Offset>>( emptyMap()@@ -270,7 +270,7 @@ fun WordGameScreen( bonusWords = bonusWords, bonusShake = bonusShakeAnim.value, onOpenBonusWords = { showBonusWordsDialog = true },- onBonusButtonPositioned = { bonusButtonOffset = it },+ onBonusButtonPositioned = { bonusButtonCenter = it }, remainingCooldownMs = remainingCooldown, onOpenHint = { showHintDialog = true }, )@@ -290,7 +290,8 @@ fun WordGameScreen( animatedWord = wordPlaceAnimations.activeBonusWord, animationProgress = wordPlaceAnimations.bonusProgress, wordBoxOffset = wordBoxOffset,- bonusButtonOffset = bonusButtonOffset,+ bonusButtonCenter = bonusButtonCenter,+ rootOffset = rootOffset, animatedLetters = wordPlaceAnimations.animatedLetters, scale = scale, )
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameWheel.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameWheel.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameWheel.ktindex f62f695fc3..e4f2206306 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameWheel.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordGameWheel.kt@@ -142,6 +142,7 @@ fun BoxScope.WordGameCornerButtons( bonusWords: Set<String>, bonusShake: Float, onOpenBonusWords: () -> Unit,+ /** Receives the bonus button's centre in root coordinates. */ onBonusButtonPositioned: (Offset) -> Unit, remainingCooldownMs: Long, onOpenHint: () -> Unit,@@ -152,7 +153,11 @@ fun BoxScope.WordGameCornerButtons( // Same 16 dp inset as the hint button opposite, so the two corner buttons line up // (the extra 32 dp bottom padding left the bonus button floating higher). .padding(16.dp)- .onGloballyPositioned { onBonusButtonPositioned(it.localToRoot(Offset.Zero)) }+ // Report the button's centre, the bonus flight's landing point. Measured outside+ // the shake layer, so a shake does not move the target.+ .onGloballyPositioned {+ onBonusButtonPositioned(it.localToRoot(Offset(it.size.width / 2f, it.size.height / 2f)))+ } .graphicsLayer { translationX = bonusShake },
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordPlaceAnimations.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordPlaceAnimations.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordPlaceAnimations.ktindex 729fc300d7..b4c57fb93e 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordPlaceAnimations.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/WordPlaceAnimations.kt@@ -13,7 +13,9 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.geometry.lerp import androidx.compose.ui.unit.Density+import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.dp import com.vayunmathur.games.wordmaker.data.CrosswordData import com.vayunmathur.games.wordmaker.platform.WordGameActions@@ -126,3 +128,24 @@ fun rememberWordPlaceAnimations( private const val LETTER_FLIGHT_MILLIS = 800 private const val BONUS_FLIGHT_MILLIS = 800++/**+ * Top-left of the flying bonus word at [progress], in the overlay's coordinate space.+ *+ * Both ends arrive as root coordinates (localToRoot), so [rootOffset] - where the overlay itself+ * sits in the root - is subtracted, exactly as the solution flights do; without it the word landed+ * that far below the button, off the bottom of the screen. It ends centred on the bonus button+ * ([bonusCenter]) rather than with its top-left corner there, so as it shrinks around its own+ * centre it disappears into the button.+ */+internal fun bonusFlightOffset(+ wordBox: Offset,+ bonusCenter: Offset,+ rootOffset: Offset,+ wordSize: IntSize,+ progress: Float,+): Offset {+ val start = wordBox - rootOffset+ val end = bonusCenter - rootOffset - Offset(wordSize.width / 2f, wordSize.height / 2f)+ return lerp(start, end, progress)+}
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordFlightPlacementTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordFlightPlacementTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordFlightPlacementTest.ktindex d54a6ec199..5527a2c0ee 100644--- a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordFlightPlacementTest.kt+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordFlightPlacementTest.kt@@ -3,12 +3,15 @@ package com.vayunmathur.games.wordmaker.ui import androidx.compose.animation.core.Animatable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.padding import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset+import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp import com.vayunmathur.games.wordmaker.data.CrosswordData@@ -21,6 +24,7 @@ import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config import kotlin.math.abs import kotlin.test.Test+import kotlin.test.assertEquals import kotlin.test.assertTrue /** Where the word-place flights are drawn, in the overlay's (root-anchored) coordinate space. */@@ -39,7 +43,7 @@ class WordFlightPlacementTest { foundWords = emptySet(), revealedHints = emptySet(), actions = WordGameActions.Noop, showBonusWordsDialog = false, onDismissBonusWords = {}, bonusWords = emptySet(), wordWithDefinition = null, onDismissDefinition = {}, animatedWord = null,- animationProgress = Animatable(0f), wordBoxOffset = Offset.Zero, bonusButtonOffset = Offset.Zero,+ animationProgress = Animatable(0f), wordBoxOffset = Offset.Zero, bonusButtonCenter = Offset.Zero, rootOffset = Offset.Zero, animatedLetters = listOf(letter), scale = 1f, ) }@@ -65,4 +69,42 @@ class WordFlightPlacementTest { setOverlays(LayoutDirection.Rtl, AnimatedLetter('Q', Offset(0f, 0f), Offset(40f, 60f), Animatable(1f))) assertLetterTileAt(Offset(40f, 60f)) }++ @Test fun bonusFlightOffsetConvertsRootCoordinatesAndCentresOnTheButton() {+ val wordBox = Offset(120f, 900f)+ val bonusCenter = Offset(44f, 1500f)+ val root = Offset(0f, 210f)+ val size = IntSize(80, 40)+ assertEquals(Offset(120f, 690f), bonusFlightOffset(wordBox, bonusCenter, root, size, 0f))+ // Lands with its centre on the button's centre, in the overlay's own space.+ assertEquals(Offset(44f - 40f, 1500f - 210f - 20f), bonusFlightOffset(wordBox, bonusCenter, root, size, 1f))+ }++ @Test fun bonusWordLandsOnTheBonusButtonInsideAnOffsetOverlay() {+ val topInset = 150.dp+ val bonusCenterInRoot = Offset(60f, 600f)+ rule.setContent {+ DynamicTheme {+ // The overlay sits below a bar, like the game screen's body under its top bar.+ Box(Modifier.fillMaxSize().padding(top = topInset)) {+ val rootOffset = with(LocalDensity.current) { Offset(0f, topInset.toPx()) }+ WordGameOverlays(+ showHintDialog = false, onDismissHint = {}, crosswordData = CrosswordData.fromString("CAT\n C \n T ")!!,+ foundWords = emptySet(), revealedHints = emptySet(), actions = WordGameActions.Noop,+ showBonusWordsDialog = false, onDismissBonusWords = {}, bonusWords = emptySet(),+ wordWithDefinition = null, onDismissDefinition = {}, animatedWord = "ZOO",+ animationProgress = Animatable(1f), wordBoxOffset = Offset(100f, 400f),+ bonusButtonCenter = bonusCenterInRoot, rootOffset = rootOffset,+ animatedLetters = emptyList(), scale = 1f,+ )+ }+ }+ }+ rule.waitForIdle()+ val center = rule.onNodeWithText("ZOO").fetchSemanticsNode().boundsInRoot.center+ assertTrue(+ abs(center.x - bonusCenterInRoot.x) < 2f && abs(center.y - bonusCenterInRoot.y) < 2f,+ "bonus word landed at $center, button centre is $bonusCenterInRoot",+ )+ } }
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerComposeTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerComposeTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerComposeTest.ktindex 5f2899206e..fe85a09594 100644--- a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerComposeTest.kt+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/WordMakerComposeTest.kt@@ -316,7 +316,7 @@ class WordMakerComposeTest { showHintDialog = true, onDismissHint = {}, crosswordData = board(), foundWords = emptySet(), revealedHints = emptySet(), actions = actions, showBonusWordsDialog = false, onDismissBonusWords = {}, bonusWords = emptySet(), wordWithDefinition = null, onDismissDefinition = {}, animatedWord = "CAT", animationProgress = progress,- wordBoxOffset = Offset.Zero, bonusButtonOffset = Offset(100f, 100f),+ wordBoxOffset = Offset.Zero, bonusButtonCenter = Offset(100f, 100f), rootOffset = Offset.Zero, animatedLetters = listOf(AnimatedLetter('C', Offset.Zero, Offset(50f, 50f), letterProgress)), scale = 1f, ) }@@ -334,7 +334,7 @@ class WordMakerComposeTest { showHintDialog = false, onDismissHint = {}, crosswordData = board(), foundWords = emptySet(), revealedHints = emptySet(), actions = WordGameActions.Noop, showBonusWordsDialog = true, onDismissBonusWords = {}, bonusWords = setOf("DOG"), wordWithDefinition = null, onDismissDefinition = {}, animatedWord = null, animationProgress = animationProgress,- wordBoxOffset = Offset.Zero, bonusButtonOffset = Offset.Zero, animatedLetters = emptyList(), scale = 1f,+ wordBoxOffset = Offset.Zero, bonusButtonCenter = Offset.Zero, rootOffset = Offset.Zero, animatedLetters = emptyList(), scale = 1f, ) } }