games-wordmaker: draw word-circle lines behind letters
- Commit
f8bd6cdb6edf79b573c37ddc994db22e10f2ccb1- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-02 03:25 UTC (4 days ago)
- Parents
364c174
The letter wheel drew its tracing trail in a Canvas placed after the letter tiles in the wheel Box, so connection lines rendered on top of each letter's background chip and glyph and looked like they crossed over the letters. Reorder the wheel's draw layers to circle background, then connection lines, then letter tiles. The stack is now driven by WHEEL_LAYERS_IN_DRAW_ORDER in WheelGeometry.kt, which LetterChooser iterates back-to-front, so the rendered z-order is the listed order: lines are in front of the word circle's own background but behind each letter's chip and letter. Lines remain visible in the gaps between tiles and the live segment to the finger remains visible until it reaches a tile. No colours, geometry, hit-testing or gesture behaviour change. Add WheelLayerOrderTest pinning that CONNECTION_LINES sits after CIRCLE_BACKGROUND and before LETTER_TILES and that the draw order covers every layer exactly once. Document the layer order in the module AGENTS.md gotchas. Verification: targeted WheelLayerOrderTest, CanvasDrawTest, LetterChooserInputTest and WheelGeometryTest pass; :games:wordmaker:testDevUnitTest (full) and :games:wordmaker:lintVitalRelease pass. :games:wordmaker:lint is not green at this base: it fails only on two pre-existing FixtureDeterminism errors in untouched files (CornerButtonsTest.kt:45 and LocalTickersTest.kt:39, System.currentTimeMillis fixtures); no lint finding touches the changed files.
Diff
games/wordmaker/AGENTS.md
diff --git a/games/wordmaker/AGENTS.md b/games/wordmaker/AGENTS.mdindex 814e9a397b..2e93bc1675 100644--- a/games/wordmaker/AGENTS.md+++ b/games/wordmaker/AGENTS.md@@ -14,7 +14,7 @@ _Install: ./install games/wordmaker (dev by default)._ **Purpose:** Word puzzle — letter-wheel + crossword modes over a bundled dictionary with definitions; competitive lobby + level generation. 100% offline. **Game shape:** `ui/` wheel/crossword/lobby screens → `platform/WordMakerViewModel` → `domain/` dictionary + generators → `data/` level store + competitive mode; achievements → `:sdk:games` → hub. **Entry points:** `Route` → `MainActivity.kt` → `Navigation.kt` → `ui/WordGameScreen.kt` → `platform/WordMakerViewModel.kt` → `domain/Dictionary.kt`.-**Gotchas:** Dictionary is bundled and locale-sensitive — word-list changes need per-locale validation.+**Gotchas:** Dictionary is bundled and locale-sensitive — word-list changes need per-locale validation. The letter wheel draws back-to-front in `WHEEL_LAYERS_IN_DRAW_ORDER` (`ui/components/WheelGeometry.kt`, iterated by `LetterChooser`): circle background → connection lines → letter tiles, so traced lines sit behind each letter's chip and glyph but in front of the circle background. ## Key files ### Root — entry + navigation
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 c75f25c66c..23cd8dace4 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@@ -235,72 +235,82 @@ fun LetterChooser( }, contentAlignment = Alignment.Center ) {- Surface(- Modifier.fillMaxSize(0.9f),- CircleShape,- MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.5f)- ) {}-- letters.forEachIndexed { index, chooserLetter ->- key(chooserLetter.id) {- val angle = WheelGeometry.angleOf(index, letters.size)- val x = animatedDp((cos(angle) * radiusDp.value).dp)- val y = animatedDp((sin(angle) * radiusDp.value).dp)+ // Drawn back-to-front in WHEEL_LAYERS_IN_DRAW_ORDER: circle background,+ // then the connection lines, then the letter tiles (their background+ // chips and glyphs). Lines stay visible in the gaps between tiles and+ // on the circle background, but never cross over a letter.+ for (layer in WHEEL_LAYERS_IN_DRAW_ORDER) {+ when (layer) {+ WheelLayer.CIRCLE_BACKGROUND -> Surface(+ Modifier.fillMaxSize(0.9f),+ CircleShape,+ MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.5f)+ ) {} - // absoluteOffset, not offset: offset {} mirrors x in RTL while the- // trail and hit-testing work in unmirrored pointer coordinates, so an- // RTL swipe selected the letter opposite the one under the finger.- val letterDescription = stringResource(R.string.letter_tile, chooserLetter.char.toString())- val letterSelected = stringResource(R.string.letter_selected)- val isTileSelected = index in selectedLettersIndices- SurfaceText(Modifier- .align(Alignment.Center)- .absoluteOffset { IntOffset(x.roundToPx(), y.roundToPx()) }- .onGloballyPositioned { coordinates ->- onLetterPositioned(chooserLetter.id, coordinates.localToRoot(Offset.Zero))- }- .then(if (tapToSpell) Modifier.clickable {- if (selectedLettersIndices.lastOrNull() == index) {- selectedLettersIndices = selectedLettersIndices.dropLast(1)- } else if (index !in selectedLettersIndices) {- selectedLettersIndices = selectedLettersIndices + index+ WheelLayer.CONNECTION_LINES -> {+ val primaryColor = MaterialTheme.colorScheme.primary+ Canvas(modifier = Modifier.fillMaxSize()) {+ val centers = geometry.centers+ selectedLettersIndices.zipWithNext { a, b ->+ drawLine(primaryColor, centers[a], centers[b], 10f, cap = StrokeCap.Round) }- } else Modifier)- // Every tile names its letter for TalkBack. In- // tap-to-spell (forced on under a screen reader) this- // merges with the clickable, so double-tap spells the- // letter; in swipe mode it is a read-only label.- .semantics {- contentDescription = letterDescription- if (isTileSelected) {- selected = true- stateDescription = letterSelected+ val lastLetter = selectedLettersIndices.lastOrNull()+ val dragPosition = currentDragPosition+ if (lastLetter != null && dragPosition != null) {+ drawLine(primaryColor, centers[lastLetter], dragPosition, 10f, cap = StrokeCap.Round) }- },- CircleShape,- if (index in selectedLettersIndices) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.secondary,- chooserLetter.char.toString(),- Modifier.padding(1.dp),- FontWeight.Bold,- glyphSize,- tileSize,- lineHeight = TILE_GLYPH_LINE_HEIGHT,- )- }- }+ }+ } - // The trail goes on top of the tiles: drawn first, it vanished under them and- // under the wheel backdrop, so the live segment to the finger was hidden.- val primaryColor = MaterialTheme.colorScheme.primary- Canvas(modifier = Modifier.fillMaxSize()) {- val centers = geometry.centers- selectedLettersIndices.zipWithNext { a, b ->- drawLine(primaryColor, centers[a], centers[b], 10f, cap = StrokeCap.Round)- }- val lastLetter = selectedLettersIndices.lastOrNull()- val dragPosition = currentDragPosition- if (lastLetter != null && dragPosition != null) {- drawLine(primaryColor, centers[lastLetter], dragPosition, 10f, cap = StrokeCap.Round)+ WheelLayer.LETTER_TILES -> {+ letters.forEachIndexed { index, chooserLetter ->+ key(chooserLetter.id) {+ val angle = WheelGeometry.angleOf(index, letters.size)+ val x = animatedDp((cos(angle) * radiusDp.value).dp)+ val y = animatedDp((sin(angle) * radiusDp.value).dp)++ // absoluteOffset, not offset: offset {} mirrors x in RTL while the+ // trail and hit-testing work in unmirrored pointer coordinates, so an+ // RTL swipe selected the letter opposite the one under the finger.+ val letterDescription = stringResource(R.string.letter_tile, chooserLetter.char.toString())+ val letterSelected = stringResource(R.string.letter_selected)+ val isTileSelected = index in selectedLettersIndices+ SurfaceText(Modifier+ .align(Alignment.Center)+ .absoluteOffset { IntOffset(x.roundToPx(), y.roundToPx()) }+ .onGloballyPositioned { coordinates ->+ onLetterPositioned(chooserLetter.id, coordinates.localToRoot(Offset.Zero))+ }+ .then(if (tapToSpell) Modifier.clickable {+ if (selectedLettersIndices.lastOrNull() == index) {+ selectedLettersIndices = selectedLettersIndices.dropLast(1)+ } else if (index !in selectedLettersIndices) {+ selectedLettersIndices = selectedLettersIndices + index+ }+ } else Modifier)+ // Every tile names its letter for TalkBack. In+ // tap-to-spell (forced on under a screen reader) this+ // merges with the clickable, so double-tap spells the+ // letter; in swipe mode it is a read-only label.+ .semantics {+ contentDescription = letterDescription+ if (isTileSelected) {+ selected = true+ stateDescription = letterSelected+ }+ },+ CircleShape,+ if (index in selectedLettersIndices) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.secondary,+ chooserLetter.char.toString(),+ Modifier.padding(1.dp),+ FontWeight.Bold,+ glyphSize,+ tileSize,+ lineHeight = TILE_GLYPH_LINE_HEIGHT,+ )+ }+ }+ } } } }
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WheelGeometry.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WheelGeometry.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WheelGeometry.ktindex a0a47c68b4..f1cde10597 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WheelGeometry.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/components/WheelGeometry.kt@@ -6,6 +6,23 @@ import kotlin.math.cos import kotlin.math.min import kotlin.math.sin +/** Layers of the letter wheel, named for the back-to-front stack they form. */+internal enum class WheelLayer {+ CIRCLE_BACKGROUND,+ CONNECTION_LINES,+ LETTER_TILES,+}++/**+ * The order [WheelLayer]s are drawn in: the word circle's own background first, then the+ * connection lines traced while spelling, then the letter tiles. Lines are therefore in+ * front of the circle background but behind each letter's background chip and glyph, so+ * they never cross over a letter. [com.vayunmathur.games.wordmaker.ui.components.LetterChooser]+ * draws its layers by iterating this list, so this order is the rendered order.+ */+internal val WHEEL_LAYERS_IN_DRAW_ORDER: List<WheelLayer> =+ listOf(WheelLayer.CIRCLE_BACKGROUND, WheelLayer.CONNECTION_LINES, WheelLayer.LETTER_TILES)+ /** * Where the letters of the wheel sit, in the wheel box's own pixel space. *
games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/components/WheelLayerOrderTest.kt
diff --git a/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/components/WheelLayerOrderTest.kt b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/components/WheelLayerOrderTest.ktnew file mode 100644index 0000000000..223d154e0c--- /dev/null+++ b/games/wordmaker/src/test/java/com/vayunmathur/games/wordmaker/ui/components/WheelLayerOrderTest.kt@@ -0,0 +1,33 @@+package com.vayunmathur.games.wordmaker.ui.components++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * Pins the word circle's back-to-front draw order. [LetterChooser] renders by iterating+ * [WHEEL_LAYERS_IN_DRAW_ORDER], so this order is the rendered z-order: connection lines+ * must sit in front of the circle background but behind the letter tiles (each tile's+ * background chip and glyph), never crossing over a letter.+ */+class WheelLayerOrderTest {++ @Test fun linesAreBehindLetterTilesButInFrontOfTheCircleBackground() {+ val order = WHEEL_LAYERS_IN_DRAW_ORDER+ assertTrue(order.indexOf(WheelLayer.CIRCLE_BACKGROUND) < order.indexOf(WheelLayer.CONNECTION_LINES))+ assertTrue(order.indexOf(WheelLayer.CONNECTION_LINES) < order.indexOf(WheelLayer.LETTER_TILES))+ }++ @Test fun drawOrderCoversEveryLayerExactlyOnce() {+ assertEquals(WheelLayer.entries.toSet(), WHEEL_LAYERS_IN_DRAW_ORDER.toSet())+ assertEquals(WheelLayer.entries.size, WHEEL_LAYERS_IN_DRAW_ORDER.size)+ assertEquals(+ listOf(+ WheelLayer.CIRCLE_BACKGROUND,+ WheelLayer.CONNECTION_LINES,+ WheelLayer.LETTER_TILES,+ ),+ WHEEL_LAYERS_IN_DRAW_ORDER,+ )+ }+}