Modern Apps git

← Modern-Apps.git

library: label best and par moves in the moves box (#ux-audit)

Commit
3f7f92cc10f056e95100b9a0cd301a10820c3518
Author
Vayun Mathur <[email protected]>
When
2026-11-13 01:23 UTC (23 days ago)
Parents
5cb9118
Symptom: the moves box shared by pipes and unblockjam showed the
current count and, under it, a bare "12 / 10" (or "- / 10"). Nothing
said which number was the player's best and which was the level's
optimum, so it read like a fraction or a score out of ten. TalkBack
read it as "12 slash 10" / "dash slash 10".

Root cause: MovesBox built the line by string concatenation with no
labels and no string resource.

Fix:
- The line is now the string resource game_moves_best_par,
  "Best %1$s · Par %2$d" (e.g. "Best 12 · Par 10"); an unset best
  still shows as a dash ("Best – · Par 10"), keeping the documented
  distinction between "no best yet" and "a best of zero".
- It is drawn with Material's Text with autoSize (StepBased 18 sp down
  to 10 sp) and maxLines = 1: the box is a fixed 150 dp wide, and a
  longer best/par or a translation must shrink to fit instead of
  wrapping out of the box or clipping.
- TalkBack gets a spelled-out description instead of the dash and
  middle dot: "Best 12 moves, par 10" / "No best yet, par 10"
  (game_moves_best_par_description / game_moves_no_best_par_description).
- English strings with translator comments and xliff placeholders.

User-visible effect: pipes and unblockjam show "Best 12 · Par 10"
under the move counter; screen-reader users hear what each number is.

Verification: Slice2GameComposeTest's moves-box test now expects
"Best – · Par 10" then "Best 8 · Par 10"; a new test checks both
TalkBack descriptions. :games:pipes / :games:unblockjam compile.

Diff

library/ui/src/main/java/com/vayunmathur/library/ui/game/GameInfoBoxes.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameInfoBoxes.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameInfoBoxes.ktindex 48df5a9deb..60ece2b819 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameInfoBoxes.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/game/GameInfoBoxes.kt@@ -4,10 +4,13 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.text.TextAutoSize import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource+import androidx.compose.ui.semantics.contentDescription+import androidx.compose.ui.semantics.semantics import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.sp import com.vayunmathur.library.ui.IconArrowForward@@ -67,10 +70,12 @@ fun LevelPickerBox( }  /**- * The move counter, with the player's best against the known optimum.+ * The move counter, with the player's best against the known optimum, labelled as such:+ * "Best 12 · Par 10". A bare "12 / 10" read as a fraction or a score out of ten.  *  * [bestScore] is null until the level has been finished once, and shows as a dash rather than a zero —- * "no best yet" and "a best of nothing" are different facts.+ * "no best yet" and "a best of nothing" are different facts. TalkBack hears the line spelled out+ * ("Best 12 moves, par 10" / "No best yet, par 10") rather than the dash and the middle dot.  */ @Composable fun MovesBox(@@ -82,11 +87,23 @@ fun MovesBox(     GameInfoBox(title = stringResource(R.string.game_moves), modifier = modifier) {         Column(horizontalAlignment = Alignment.CenterHorizontally) {             Text(text = "$moves", fontSize = 24.sp, fontWeight = FontWeight.Bold)-            Text(-                text = "${bestScore ?: "-"} / $optimalMoves",-                fontSize = 18.sp,+            val spoken = if (bestScore == null) {+                stringResource(R.string.game_moves_no_best_par_description, optimalMoves)+            } else {+                stringResource(R.string.game_moves_best_par_description, bestScore, optimalMoves)+            }+            // Material's Text directly, for autoSize: the box is a fixed 150 dp and a translated+            // "Best 120 · Par 98" must shrink to fit rather than wrap or clip.+            androidx.compose.material3.Text(+                text = stringResource(R.string.game_moves_best_par, bestScore?.toString() ?: NO_BEST, optimalMoves),+                modifier = Modifier.semantics { contentDescription = spoken },+                autoSize = TextAutoSize.StepBased(minFontSize = 10.sp, maxFontSize = 18.sp),                 fontWeight = FontWeight.Bold,+                maxLines = 1,             )         }     } }++/** Shown for a best score that does not exist yet. */+private const val NO_BEST = "–"
library/ui/src/main/res/values/strings.xml
diff --git a/library/ui/src/main/res/values/strings.xml b/library/ui/src/main/res/values/strings.xmlindex e1cbecc191..04139e65df 100644--- a/library/ui/src/main/res/values/strings.xml+++ b/library/ui/src/main/res/values/strings.xml@@ -224,6 +224,12 @@     <string name="game_level">Level</string>     <!-- Shared library: UI - MovesBox: title over the move counter. Noun, plural -->     <string name="game_moves">Moves</string>+    <!-- Shared library: UI - MovesBox: the player's fewest moves on this level against the level's par (optimal move count), e.g. Best 12 · Par 10. %1$s = best move count, or a dash when the level has not been finished yet; %2$d = par. Keep short: shown in a small fixed-width box -->+    <string name="game_moves_best_par">Best <xliff:g id="best" example="12">%1$s</xliff:g> · Par <xliff:g id="par" example="10">%2$d</xliff:g></string>+    <!-- Shared library: UI - MovesBox: what TalkBack reads for the best/par line. %1$d = best move count, %2$d = par (optimal move count) -->+    <string name="game_moves_best_par_description">Best <xliff:g id="best" example="12">%1$d</xliff:g> moves, par <xliff:g id="par" example="10">%2$d</xliff:g></string>+    <!-- Shared library: UI - MovesBox: what TalkBack reads for the best/par line before the level has ever been finished. %1$d = par (optimal move count) -->+    <string name="game_moves_no_best_par_description">No best yet, par <xliff:g id="par" example="10">%1$d</xliff:g></string>     <!-- Shared library: UI - LevelPickerBox: shown under the level number once that level has been finished. Verb past participle -->     <string name="game_completed">Completed</string>     <!-- Shared library: UI - DailyChallengeCard: title of the card opening today's challenge. Noun phrase -->
library/ui/src/test/java/com/vayunmathur/library/ui/game/Slice2GameComposeTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/game/Slice2GameComposeTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/game/Slice2GameComposeTest.ktindex 60a650c862..7cb23f2c12 100644--- a/library/ui/src/test/java/com/vayunmathur/library/ui/game/Slice2GameComposeTest.kt+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/game/Slice2GameComposeTest.kt@@ -100,11 +100,22 @@ class Slice2GameComposeTest {         var moves by mutableStateOf(12)         rule.setContent { MovesBox(moves = moves, bestScore = bestScore, optimalMoves = 10) }         rule.onNodeWithText("12").assertIsDisplayed()-        rule.onNodeWithText("- / 10").assertIsDisplayed()+        rule.onNodeWithText("Best – · Par 10").assertIsDisplayed()         moves = 9         bestScore = 8         rule.waitForIdle()-        rule.onNodeWithText("8 / 10").assertIsDisplayed()+        rule.onNodeWithText("Best 8 · Par 10").assertIsDisplayed()+    }++    @Test+    fun `moves box labels best and par for TalkBack too`() {+        var bestScore: Int? by mutableStateOf<Int?>(null)+        rule.setContent { MovesBox(moves = 3, bestScore = bestScore, optimalMoves = 10) }+        rule.onNode(hasContentDescription("No best yet, par 10")).assertExists()+        bestScore = 12+        rule.waitForIdle()+        rule.onNodeWithText("Best 12 · Par 10").assertIsDisplayed()+        rule.onNode(hasContentDescription("Best 12 moves, par 10")).assertExists()     }      // --- GameModeChooser ---------------------------------------------------------