nonogram: fit the board on landscape phones, keep Next level visible (#ux-audit)
- Commit
8c9f4b065e3cf23a7e199cb427c7355a26090c3a- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 01:28 UTC (23 days ago)
- Parents
8b2feb9
Symptom: on a phone in landscape the board overflowed the screen and the Next level / Restart controls ended up below the fold with no way to reach them (the column does not scroll), so a solved puzzle could not be advanced without rotating back. Root cause: - NonogramGameScreen only used the side-panel layout for isExpandedWidth(); a landscape phone (~800x360dp) is medium width, so it got the stacked portrait layout. - NonogramBoard sized cells from maxWidth alone, so in a wide, short window the grid was taller than the window. Fix: - Use the side panel when isExpandedWidth() || isCompactHeight(), the pattern library/ui documents for short windows. - NonogramBoard sizes cells from min(width-fit, height-fit) (falling back to width when height is unbounded) and centres the board. - The stacked phone layout gives the board a weight(1f) slot, so it fits the height left by the hearts and controls instead of pushing them down. - The side panel scrolls as a last resort (very short windows, huge fonts) while staying vertically centred when it fits. User-visible effect: in landscape the board fits beside the hearts and controls, and Next level is always on screen. Verification: new Robolectric NonogramLandscapeScreenTest at w800dp-h360dp: a solved 15x15 shows a displayed, clickable Next level; the bottom-right cell lies within the window; and the mode toggle sits to the right of the board (side panel). Existing expanded and phone screen tests still pass.
Diff
games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/NonogramGameScreen.kt
diff --git a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/NonogramGameScreen.kt b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/NonogramGameScreen.ktindex b34b4d3753..4760dbd5c3 100644--- a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/NonogramGameScreen.kt+++ b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/NonogramGameScreen.kt@@ -10,6 +10,8 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.widthIn+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf@@ -47,6 +49,7 @@ import com.vayunmathur.library.ui.game.DailyStreakText import com.vayunmathur.library.ui.game.GameModeChooser import com.vayunmathur.library.ui.game.GameTopBarActions import com.vayunmathur.library.ui.game.HeartsRow+import com.vayunmathur.library.ui.isCompactHeight import com.vayunmathur.library.ui.isExpandedWidth /** Caps the board on tablets, where a full-width grid would give absurdly large cells. */@@ -95,7 +98,9 @@ fun NonogramGameScreen( val daily = state.mode == GameMode.DAILY // Wide windows put the hearts and controls beside the board instead of // stretching the grid across the window; the board itself never splits.- val expanded = isExpandedWidth()+ // Short windows (a landscape phone) split too: stacking board over controls+ // cannot fit in ~360dp of height, and pushed Next level off-screen.+ val sidePanel = isExpandedWidth() || isCompactHeight() AppScaffold( title = { GameModeChooser(@@ -162,7 +167,7 @@ fun NonogramGameScreen( contentAlignment = Alignment.Center, ) { CircularProgressIndicator() } - expanded -> {+ sidePanel -> { Row( Modifier.weight(1f).fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(Spacing.lg),@@ -182,7 +187,12 @@ fun NonogramGameScreen( ) } Column(- Modifier.width(NonogramSidePanelWidth).fillMaxHeight(),+ Modifier+ .width(NonogramSidePanelWidth)+ .fillMaxHeight()+ // A last resort for very short windows or huge fonts:+ // the controls scroll rather than clip.+ .verticalScroll(rememberScrollState()), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy( Spacing.md,@@ -202,14 +212,21 @@ fun NonogramGameScreen( else -> { HeartsRow(remaining = game.hearts, total = STARTING_HEARTS) - NonogramBoard(- game = game,- actions = actions,- markMode = state.markMode,- modifier = Modifier- .widthIn(max = BoardMaxWidth)- .fillMaxWidth(),- )+ // The board takes whatever height the hearts and controls leave and+ // sizes itself to fit it, so the controls are never pushed off-screen.+ Box(+ Modifier.weight(1f).fillMaxWidth(),+ contentAlignment = Alignment.Center,+ ) {+ NonogramBoard(+ game = game,+ actions = actions,+ markMode = state.markMode,+ modifier = Modifier+ .widthIn(max = BoardMaxWidth)+ .fillMaxWidth(),+ )+ } NonogramControls( game = game,
games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/components/NonogramBoard.kt
diff --git a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/components/NonogramBoard.kt b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/components/NonogramBoard.ktindex 0a98387f81..dcfa000269 100644--- a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/components/NonogramBoard.kt+++ b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/components/NonogramBoard.kt@@ -16,6 +16,7 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.saveable.listSaver import androidx.compose.runtime.saveable.rememberSaveable+import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clipToBounds import androidx.compose.ui.draw.drawWithContent@@ -41,7 +42,7 @@ import com.vayunmathur.library.ui.rememberHaptics * Laid out as a two-by-two arrangement: an empty corner, the column clues across the top, the row * clues down the left, and the grid itself. The clue gutters are sized from the longest clue on that * axis so nothing is ever clipped, and everything scales off the cell size so a 5x5 and a 15x15 both- * fill the available width.+ * fill the available space โ width or height, whichever runs out first โ centred within it. * * Touch goes through one handler on the whole grid ([strokeGestures]): taps, drags and long presses * all become strokes on [actions]. TalkBack's per-cell actions call [NonogramGameActions.tapCell] and@@ -59,9 +60,17 @@ fun NonogramBoard( val rowGutterCells = game.puzzle.rowClues.maxOf { it.size }.coerceAtLeast(1) val colGutterCells = game.puzzle.colClues.maxOf { it.size }.coerceAtLeast(1) - BoxWithConstraints(modifier) {+ BoxWithConstraints(modifier, contentAlignment = Alignment.Center) { // The clue gutters are narrower than a cell: they only ever hold a one or two digit number.- val cell: Dp = maxWidth / (size + rowGutterCells * CLUE_CELL_FRACTION)+ // Fitted to both axes: sizing from width alone overflowed a landscape phone, where the board+ // is far wider than it is tall. Unbounded height (a scrolling parent) falls back to width.+ val fromWidth = maxWidth / (size + rowGutterCells * CLUE_CELL_FRACTION)+ val fromHeight = if (constraints.hasBoundedHeight) {+ maxHeight / (size + colGutterCells * CLUE_CELL_FRACTION)+ } else {+ fromWidth+ }+ val cell: Dp = minOf(fromWidth, fromHeight) val clueCell = cell * CLUE_CELL_FRACTION // Sized from the clue slot, not the grid cell, and paired with a line height equal to the // slot. Without that a 15x15's slots are shorter than the text's natural line box, the clue
games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramLandscapeScreenTest.kt
diff --git a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramLandscapeScreenTest.kt b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramLandscapeScreenTest.ktnew file mode 100644index 0000000000..8e50521d38--- /dev/null+++ b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramLandscapeScreenTest.kt@@ -0,0 +1,58 @@+package com.vayunmathur.games.nonogram.ui++import android.content.Context+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithContentDescription+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.onRoot+import androidx.compose.ui.test.performClick+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.games.nonogram.R+import com.vayunmathur.games.nonogram.data.GameMode+import com.vayunmathur.games.nonogram.data.NonogramGameState+import com.vayunmathur.games.nonogram.data.STARTING_HEARTS+import com.vayunmathur.games.nonogram.domain.NonogramGenerator+import com.vayunmathur.games.nonogram.platform.NonogramUiState+import com.vayunmathur.library.ui.R as UiR+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.annotation.Config+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/** A landscape phone: medium width, compact height โ the case that used to overflow. */+@RunWith(RobolectricTestRunner::class)+@Config(qualifiers = "w800dp-h360dp-land")+class NonogramLandscapeScreenTest {+ @get:Rule val rule = createComposeRule()+ private val ctx get() = ApplicationProvider.getApplicationContext<Context>()++ private fun solved15(): NonogramGameState {+ val p = requireNotNull(NonogramGenerator.generateSeeded(15, 25L))+ val answer = p.solution.indices.filter { p.solution[it] }.toSet()+ return NonogramGameState(p, answer, emptySet(), emptySet(), STARTING_HEARTS, GameMode.CASUAL, 25)+ }++ @Test fun solvedBoardKeepsNextLevelOnScreen() {+ val a = NonogramScreensTest.Recording()+ rule.setContent { NonogramGameScreen(NonogramUiState(game = solved15(), level = 25), a, {}, {}) }+ rule.onNodeWithText(ctx.getString(UiR.string.next_level)).assertIsDisplayed().performClick()+ assertEquals(1, a.next)+ }++ @Test fun boardFitsTheWindowHeight() {+ val g = solved15().copy(filled = emptySet())+ rule.setContent { NonogramGameScreen(NonogramUiState(game = g, level = 25), NonogramScreensTest.Recording(), {}, {}) }+ val root = rule.onRoot().fetchSemanticsNode().boundsInRoot+ val lastCell = rule.onNodeWithContentDescription(ctx.getString(R.string.cd_cell_position, 15, 15))+ .fetchSemanticsNode().boundsInRoot+ assertTrue(lastCell.bottom <= root.bottom + 0.5f, "bottom row at ${lastCell.bottom} overflows ${root.bottom}")+ assertTrue(lastCell.right <= root.right + 0.5f)+ // Side panel: the controls sit beside the board, not under it.+ val toggle = rule.onNodeWithText(ctx.getString(R.string.mode_fill)).fetchSemanticsNode().boundsInRoot+ assertTrue(toggle.left >= lastCell.right, "mode toggle should be in the side panel")+ }+}