games: fix landscape layouts for wordmaker and chess puzzles
- Commit
2dc4dc226aaf0c593a95959ee8c195305e1242e9- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-19 18:26 UTC (16 days ago)
- Parents
6542bc8
Wordmaker reserved the full wheel height (320-410dp by spacing) as bottom padding under the board, so on a ~360dp-tall landscape window the crossword measured ~0dp. It now branches on isCompactHeight() (the repo's soduku/minesweeper pattern) into a board-beside-wheel Row; taller windows keep the stacked layout. Its bonus-words dialog also swaps a LazyColumn in a dialog slot for a scrolling Column (the launcher TvEditMenu pattern). Chess PuzzleBoardScreen centred a non-scrolling column over a 560dp-capped square board - difficulty header and Next clipped off-screen in landscape. It mirrors the main game's three-way layout: landscape/compact-height puts the board (width-share capped so controls keep width - a narrow-short window starved them to 0dp and hung composition, caught by tests) beside a scrolling control column. Verified: :games:wordmaker and :games:chess compile; full :games:chess:testDevUnitTest passes. Landscape previews for both screens are recommended follow-ups.
Diff
games/chess/src/main/java/com/vayunmathur/games/chess/ChessPuzzleScreens.kt
diff --git a/games/chess/src/main/java/com/vayunmathur/games/chess/ChessPuzzleScreens.kt b/games/chess/src/main/java/com/vayunmathur/games/chess/ChessPuzzleScreens.ktindex e93d4e36ad..3fc49e52db 100644--- a/games/chess/src/main/java/com/vayunmathur/games/chess/ChessPuzzleScreens.kt+++ b/games/chess/src/main/java/com/vayunmathur/games/chess/ChessPuzzleScreens.kt@@ -2,6 +2,7 @@ package com.vayunmathur.games.chess import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer@@ -9,7 +10,10 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size 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.LaunchedEffect import androidx.compose.runtime.collectAsState@@ -37,9 +41,14 @@ import com.vayunmathur.library.ui.SegmentedButton import com.vayunmathur.library.ui.SegmentedButtonDefaults import com.vayunmathur.library.ui.SingleChoiceSegmentedButtonRow import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.isCompactHeight+import com.vayunmathur.library.ui.isExpandedWidth private const val PUZZLE_DIFFICULTY_COUNT = 3 +/** The board's share of the width in the side-by-side layout (as in sudoku). */+private const val BOARDSIDE_WIDTH_SHARE = 0.62f+ /** Binds [PuzzleViewModel] to the stateless [PuzzleBoardScreen] and deals the first puzzle. */ @Composable fun PuzzleScreen(viewModel: PuzzleViewModel) {@@ -88,52 +97,109 @@ fun PuzzleBoardScreen(state: PuzzleUiState, actions: PuzzleActions) { // No app bar: the tab has no title worth showing and no actions, so the content gets the space. // RAW SCAFFOLD EXCEPTION: bar-less game board; the shared scaffolds all impose a top app bar. Scaffold { innerPadding ->- Column(+ BoxWithConstraints( Modifier .fillMaxSize() .padding(innerPadding)- .padding(horizontal = 16.dp),- Arrangement.Center,- Alignment.CenterHorizontally+ .padding(horizontal = 16.dp) ) {- PuzzleHeader(state = state, actions = actions)- // Capped like the game board so a desktop window doesn't blow the grid up.- Box(Modifier.widthIn(max = ChessBoardMaxWidth).fillMaxWidth()) {- BoardGrid(- board = state.board,- selectedPiece = state.selectedPiece,- isFlipped = state.isBoardFlipped,- turn = state.playerColor,- onSquareClick = actions::onSquareClick,- onSquareDrop = actions::onSquareDrop,- showLastMove = true- )- }- Spacer(Modifier.height(16.dp))-- PuzzleStatusText(status = state.status)- Spacer(Modifier.height(16.dp))-- // Reserve the action-row height whether or not the Failed buttons are- // shown, so the board and everything above it never shift.- Box(Modifier.height(40.dp), contentAlignment = Alignment.Center) {- if (state.status == PuzzleStatus.Failed) {- Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {- Button(onClick = { actions.retry() }) {- Text(stringResource(UiR.string.retry))- }- OutlinedButton(onClick = { actions.showSolution() }) {- Text(stringResource(R.string.puzzle_show_solution))- }+ // The same split as the main game (ChessGameScreen): expanded+ // windows and short/landscape ones put the board beside a+ // scrolling control column. The old centred non-scrolling Column+ // let the capped square board push Next off a landscape phone+ // entirely. Portrait windows keep the stacked layout.+ val sideBySide = isExpandedWidth() || isCompactHeight() || maxWidth > maxHeight+ if (sideBySide) {+ // Read in this scope: RowScope would shadow the+ // BoxWithConstraintsScope's maxWidth/maxHeight below.+ // On a landscape phone the height binds first; capped like+ // the game board so a desktop window doesn't blow the grid+ // up, and at a share of the width (sudoku's side-by-side cap)+ // so a narrow-but-short window still leaves the controls a+ // column — full width there squeezed them to zero.+ val boardSide = minOf(maxWidth * BOARDSIDE_WIDTH_SHARE, maxHeight, ChessBoardMaxWidth)+ Row(+ Modifier.fillMaxSize(),+ horizontalArrangement = Arrangement.spacedBy(16.dp),+ verticalAlignment = Alignment.CenterVertically+ ) {+ PuzzleBoardBox(state = state, actions = actions, modifier = Modifier.size(boardSide))+ // No fillMaxHeight and no centred arrangement: the column+ // wraps its content and the Row's CenterVertically centres+ // the whole block (sudoku's side column does the same). A+ // centred arrangement inside a scroll container never+ // settles — it re-centres on every scroll layout.+ Column(+ Modifier+ .weight(1f)+ .verticalScroll(rememberScrollState()),+ horizontalAlignment = Alignment.CenterHorizontally+ ) {+ PuzzleHeader(state = state, actions = actions)+ Spacer(Modifier.height(16.dp))+ PuzzleControls(state = state, actions = actions) } }+ } else {+ Column(+ Modifier.fillMaxSize(),+ Arrangement.Center,+ Alignment.CenterHorizontally+ ) {+ PuzzleHeader(state = state, actions = actions)+ PuzzleBoardBox(+ state = state,+ actions = actions,+ modifier = Modifier.widthIn(max = ChessBoardMaxWidth).fillMaxWidth()+ )+ Spacer(Modifier.height(16.dp))+ PuzzleControls(state = state, actions = actions)+ } }- Spacer(Modifier.height(8.dp))- Button(onClick = { actions.loadRandom(state.difficulty) }) {- Text(stringResource(R.string.puzzle_next))+ }+ }+}++/** The board in the box its caller sized: [BoardGrid] itself is size-agnostic. */+@Composable+private fun PuzzleBoardBox(state: PuzzleUiState, actions: PuzzleActions, modifier: Modifier = Modifier) {+ Box(modifier) {+ BoardGrid(+ board = state.board,+ selectedPiece = state.selectedPiece,+ isFlipped = state.isBoardFlipped,+ turn = state.playerColor,+ onSquareClick = actions::onSquareClick,+ onSquareDrop = actions::onSquareDrop,+ showLastMove = true+ )+ }+}++/** Status, the Failed actions and Next: the controls that must stay reachable. */+@Composable+private fun PuzzleControls(state: PuzzleUiState, actions: PuzzleActions) {+ PuzzleStatusText(status = state.status)+ Spacer(Modifier.height(16.dp))++ // Reserve the action-row height whether or not the Failed buttons are+ // shown, so the board and everything above it never shift.+ Box(Modifier.height(40.dp), contentAlignment = Alignment.Center) {+ if (state.status == PuzzleStatus.Failed) {+ Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {+ Button(onClick = { actions.retry() }) {+ Text(stringResource(UiR.string.retry))+ }+ OutlinedButton(onClick = { actions.showSolution() }) {+ Text(stringResource(R.string.puzzle_show_solution))+ } } } }+ Spacer(Modifier.height(8.dp))+ Button(onClick = { actions.loadRandom(state.difficulty) }) {+ Text(stringResource(R.string.puzzle_next))+ } } @Composable
games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipTray.kt
diff --git a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipTray.kt b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipTray.ktindex 3546726581..3e7206d657 100644--- a/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipTray.kt+++ b/games/logicgate/src/main/java/com/vayunmathur/games/logicgate/ui/ChipTray.kt@@ -32,6 +32,7 @@ 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.text.style.TextOverflow import androidx.compose.ui.unit.dp import com.vayunmathur.games.logicgate.R import com.vayunmathur.games.logicgate.domain.levels.Chapter@@ -171,7 +172,7 @@ private fun ChipCard( verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, ) {- Text(chipLabel(chip.id), fontWeight = FontWeight.Bold, style = MaterialTheme.typography.labelLarge, maxLines = 1, softWrap = false)+ Text(chipLabel(chip.id), fontWeight = FontWeight.Bold, style = MaterialTheme.typography.labelLarge, maxLines = 1, softWrap = false, overflow = TextOverflow.Ellipsis) Row(horizontalArrangement = Arrangement.spacedBy(Spacing.xs)) { Text( chip.nandCost.toString(),@@ -179,6 +180,7 @@ private fun ChipCard( color = MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1, softWrap = false,+ overflow = TextOverflow.Ellipsis, ) if (widest > 1) { Text(@@ -187,6 +189,7 @@ private fun ChipCard( maxLines = 1, softWrap = false, color = if (widest == 4) MaterialTheme.colorScheme.tertiary else MaterialTheme.colorScheme.primary,+ overflow = TextOverflow.Ellipsis, ) } }
games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/components/BoardClues.kt
diff --git a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/components/BoardClues.kt b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/components/BoardClues.ktindex eae96b7618..c7edea9b4a 100644--- a/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/components/BoardClues.kt+++ b/games/nonogram/src/main/java/com/vayunmathur/games/nonogram/ui/components/BoardClues.kt@@ -15,6 +15,7 @@ import androidx.compose.ui.layout.Layout import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign+import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.Constraints import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.LayoutDirection@@ -142,6 +143,7 @@ private fun ClueText( textAlign = TextAlign.Center, color = if (clue == 0) MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.5f) else MaterialTheme.colorScheme.onSurface,+ overflow = TextOverflow.Ellipsis, ) } }
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 35efb19b20..971df38472 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@@ -10,14 +10,12 @@ import androidx.compose.foundation.clickable import androidx.compose.foundation.gestures.rememberTransformableState import androidx.compose.foundation.gestures.transformable import androidx.compose.foundation.layout.Box-import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.size-import androidx.compose.foundation.shape.CircleShape-import androidx.compose.foundation.verticalScroll+import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable@@ -56,6 +54,7 @@ import com.vayunmathur.library.ui.IconSettings import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.game.GameTopBarActions+import com.vayunmathur.library.ui.isCompactHeight import com.vayunmathur.library.util.AchievementsManager import com.vayunmathur.games.wordmaker.ui.components.CrosswordBoard import com.vayunmathur.games.wordmaker.ui.components.WordMakerModeChooser@@ -64,6 +63,9 @@ import kotlinx.coroutines.delay /** Room above the wheel for the formed-word box and its padding. */ private val WHEEL_HEADROOM = 70.dp +/** Width of the two side columns LetterChooser keeps beside the wheel (56.dp each). */+private val WHEEL_SIDE_COLUMNS = 112.dp+ /** Longest single wait of the competitive timer before it re-reads the wall clock. */ private const val MAX_TIMER_WAIT_MS = 1_000L @@ -169,7 +171,14 @@ fun WordGameScreen( // instead of stretching the crossword across the window; the board // itself never splits. Bars stay full-bleed — only the body is capped. DesktopMaxWidthContainer(modifier = Modifier.padding(innerPadding)) {- Box(+ // Short windows (landscape phones, under 480.dp tall) cannot stack the+ // board over the wheel: wheelHeight alone is 320-410.dp, so reserving it+ // as bottom padding left the board ~0.dp and it collapsed. There the+ // board and wheel sit side by side instead — the same split sudoku and+ // minesweeper make on isCompactHeight() — each with the full height,+ // and the wheel's measured-fit geometry shrinks it to its column.+ // Taller windows keep the stacked layout below, unchanged.+ BoxWithConstraints( modifier = Modifier .padding(bottom = 32.dp) .fillMaxSize()@@ -177,15 +186,15 @@ fun WordGameScreen( rootOffset = it.localToRoot(Offset.Zero) } ) {- // Puzzle board occupies the space above the letter wheel so it stays- // vertically centred there. The wheel below reserves its own height. val wheelHeight = wheelSpacing.boxSize + WHEEL_HEADROOM- Box(- modifier = Modifier- .fillMaxSize()- .padding(bottom = wheelHeight),- contentAlignment = Alignment.Center- ) {+ // The wheel column's natural width: the wheel box plus the side+ // columns LetterChooser keeps for its buttons. Capped at half the+ // window so the board keeps a usable share beside it.+ val wheelColumnWidth = minOf(wheelSpacing.boxSize + WHEEL_SIDE_COLUMNS, maxWidth / 2)+ val boardContent: @Composable () -> Unit = {+ // Fills whatever box it is given and re-fits its zoom to that+ // box on every layout (see CrosswordBoard), so rotation and+ // the side-by-side split need no size maths here. CrosswordBoard( foundWords = foundWords, revealedHints = revealedHints,@@ -202,10 +211,7 @@ fun WordGameScreen( } ) }- Column(- modifier = Modifier.fillMaxSize(),- horizontalAlignment = Alignment.CenterHorizontally- ) {+ val wheelContent: @Composable () -> Unit = { WordGameWheel( isCompetitive = isCompetitive, isDaily = isDaily,@@ -239,6 +245,40 @@ fun WordGameScreen( ) } + if (isCompactHeight()) {+ Row(modifier = Modifier.fillMaxSize()) {+ Box(+ modifier = Modifier.weight(1f).fillMaxHeight(),+ contentAlignment = Alignment.Center+ ) {+ boardContent()+ }+ // The wheel column is only as tall as the window, so its+ // fixed wheelHeight box is coerced down and LetterChooser+ // fits the wheel to what it actually gets.+ Box(+ modifier = Modifier.width(wheelColumnWidth).fillMaxHeight()+ ) {+ wheelContent()+ }+ }+ } else {+ // Puzzle board occupies the space above the letter wheel so it+ // stays vertically centred there. The wheel below reserves its+ // own height.+ Box(+ modifier = Modifier+ .fillMaxSize()+ .padding(bottom = wheelHeight),+ contentAlignment = Alignment.Center+ ) {+ boardContent()+ }+ Box(modifier = Modifier.fillMaxSize()) {+ wheelContent()+ }+ }+ WordGameCornerButtons( isWon = isWon, isCompetitive = isCompetitive,
games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/dialogs/WordDialogs.kt
diff --git a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/dialogs/WordDialogs.kt b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/dialogs/WordDialogs.ktindex f93c8f32a3..73f08e0472 100644--- a/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/dialogs/WordDialogs.kt+++ b/games/wordmaker/src/main/java/com/vayunmathur/games/wordmaker/ui/dialogs/WordDialogs.kt@@ -4,8 +4,6 @@ import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.lazy.LazyColumn-import androidx.compose.foundation.lazy.items import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Text@@ -67,10 +65,14 @@ fun BonusWordsDialog( // The count of this puzzle's bonus words found so far (#915). title = { Text(text = pluralStringResource(R.plurals.bonus_words_title, bonusWords.size, bonusWords.size)) }, text = {- LazyColumn(modifier = Modifier.fillMaxWidth()) {+ // Plain scrolling Column, not a LazyColumn: the dialog's text slot+ // is measured with bounded height, and a lazy container nested in+ // it is a nested-scroll hazard (the launcher's TvEditMenu add-app+ // picker follows the same rule) — bonus-word lists are short.+ Column(modifier = Modifier.fillMaxWidth().verticalScroll(rememberScrollState())) { // Full-height list rows (the old ~28 dp text lines were hard to hit) with a // visible info affordance, so it is clear a tap shows the word's definition.- items(bonusWords.toList().sorted()) { word ->+ bonusWords.sorted().forEach { word -> ListItem( modifier = Modifier .fillMaxWidth()