games: nonogram and kart landscape fixes
- Commit
5cea1bd477106b382870d28f02eb102a995b4e32- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-21 08:56 UTC (15 days ago)
- Parents
bb9dfc7
Nonogram's side-by-side landscape branch gated on compact height alone - the exact wordmaker bug class (19 CI failures): short portrait windows (split-screen, test sizes) got the side panel halved. Gate is now expanded-width or compact- height AND landscape; a regression test pins short-portrait stacked layout. Kart's race screen scrolled during Racing and Countdown - those phases are now fixed constraint-sized layouts (standings compressed to one line to fit), lobby and results keep scrolling. Verified: nonogram 112, kart 74 tests pass incl. new layout tests.
Diff
games/kart/src/main/java/com/vayunmathur/games/kart/ui/KartGameScreen.kt
diff --git a/games/kart/src/main/java/com/vayunmathur/games/kart/ui/KartGameScreen.kt b/games/kart/src/main/java/com/vayunmathur/games/kart/ui/KartGameScreen.ktindex 4f13010445..9a6e3995de 100644--- a/games/kart/src/main/java/com/vayunmathur/games/kart/ui/KartGameScreen.kt+++ b/games/kart/src/main/java/com/vayunmathur/games/kart/ui/KartGameScreen.kt@@ -3,9 +3,10 @@ package com.vayunmathur.games.kart.ui import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.ColumnScope+import androidx.compose.foundation.layout.Row 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.rememberScrollState import androidx.compose.foundation.verticalScroll@@ -15,7 +16,6 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign-import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidView import com.vayunmathur.games.kart.R import com.vayunmathur.games.kart.platform.KartGameActions@@ -45,11 +45,17 @@ fun KartGameScreen( ?: stringResource(R.string.app_name), alignment = AppBarAlignment.Center, ) { padding ->+ // Only the garage and the results scroll. Countdown and the race itself+ // are the live race surface: a scrollable column there is a hazard while+ // racing (a stray swipe drags the viewport and HUD away mid-race), so+ // those phases get a fixed layout sized to the window instead.+ val scrollState = rememberScrollState()+ val scrollable = phase is RacePhase.Lobby || phase is RacePhase.Results Column( Modifier .fillMaxSize() .padding(padding)- .verticalScroll(rememberScrollState())+ .then(if (scrollable) Modifier.verticalScroll(scrollState) else Modifier) .padding(horizontal = Spacing.md), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(Spacing.md),@@ -135,11 +141,14 @@ private fun CountdownBody(phase: RacePhase.Countdown) { } @Composable-private fun RacingBody(phase: RacePhase.Racing) {+private fun ColumnScope.RacingBody(phase: RacePhase.Racing) { // The native 3D viewport sits behind the standings HUD. With no // libkart_engine it is never composed and the HUD is the whole screen; // in a @Preview (Layoutlib) a SurfaceView is a blank rect, so listing // images keep rendering the HUD exactly as before.+ // The viewport takes whatever height the HUD leaves (weight, not a fixed+ // height): the race layout never scrolls, so on a short landscape window+ // the 3D view shrinks instead of pushing the standings off-screen. if (com.vayunmathur.games.kart.util.KartNative.isAvailable) { AndroidView( factory = { ctx ->@@ -147,7 +156,7 @@ private fun RacingBody(phase: RacePhase.Racing) { // through a transparent hole in the window. KartSurfaceView(ctx) },- modifier = Modifier.fillMaxWidth().height(240.dp),+ modifier = Modifier.fillMaxWidth().weight(1f), ) } Text(@@ -171,15 +180,23 @@ private fun RacingBody(phase: RacePhase.Racing) { color = MaterialTheme.colorScheme.onSurfaceVariant, ) }+ // One line per kart (name beside its progress bar, not above it): the race+ // layout never scrolls, so the whole HUD has to fit the window height —+ // on a ~360dp landscape phone the stacked two-line rows pushed the last+ // places off-screen. phase.order.forEachIndexed { place, id ->- Column(Modifier.fillMaxWidth()) {+ Row(+ Modifier.fillMaxWidth(),+ horizontalArrangement = Arrangement.spacedBy(Spacing.md),+ verticalAlignment = Alignment.CenterVertically,+ ) { Text( stringResource(R.string.race_place, place + 1, displayName(id)), style = MaterialTheme.typography.bodyMedium, ) LinearProgressIndicator( progress = { phase.lapProgress[id] ?: 0f },- modifier = Modifier.fillMaxWidth(),+ modifier = Modifier.weight(1f), ) } }
games/kart/src/test/java/com/vayunmathur/games/kart/ui/KartRaceSurfaceTest.kt
diff --git a/games/kart/src/test/java/com/vayunmathur/games/kart/ui/KartRaceSurfaceTest.kt b/games/kart/src/test/java/com/vayunmathur/games/kart/ui/KartRaceSurfaceTest.ktnew file mode 100644index 0000000000..e714512c0e--- /dev/null+++ b/games/kart/src/test/java/com/vayunmathur/games/kart/ui/KartRaceSurfaceTest.kt@@ -0,0 +1,67 @@+package com.vayunmathur.games.kart.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.hasScrollAction+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.games.kart.R+import com.vayunmathur.games.kart.data.CUPS+import com.vayunmathur.games.kart.platform.KartGameActions+import com.vayunmathur.games.kart.platform.KartUiState+import com.vayunmathur.games.kart.platform.RacePhase+import com.vayunmathur.sdk.controller.LobbyState+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.annotation.Config+import kotlin.test.Test++/**+ * A landscape phone: short enough that the old all-phases scrolling column+ * put part of the race HUD below the fold. The race surface must now be a+ * fixed layout — no scrollable node to drag mid-race — while the garage+ * keeps its scroll.+ */+@RunWith(RobolectricTestRunner::class)+@Config(qualifiers = "w800dp-h360dp-land")+class KartRaceSurfaceTest {++ @get:Rule val rule = createComposeRule()+ private val ctx get() = ApplicationProvider.getApplicationContext<android.content.Context>()+ private fun str(id: Int, vararg args: Any) = ctx.getString(id, *args)++ @Test fun racingHasNoScrollAndShowsStandings() {+ val phase = RacePhase.Racing(+ order = listOf("p1", "ai-0", "ai-1", "ai-2"),+ lapProgress = mapOf("p1" to 0.5f, "ai-0" to 0.25f),+ playerLap = 1,+ totalLaps = 3,+ lastLapMs = 83_456L,+ bestLapMs = 61_005L,+ )+ rule.setContent { KartGameScreen(KartUiState(cup = CUPS[0]), phase, KartGameActions.Noop) }+ rule.onNode(hasScrollAction()).assertDoesNotExist()+ rule.onNodeWithText(str(R.string.race_lap, 2, 3)).assertIsDisplayed()+ rule.onNodeWithText(str(R.string.race_place, 4, "Rival 2")).assertIsDisplayed()+ }++ @Test fun countdownHasNoScroll() {+ rule.setContent {+ KartGameScreen(KartUiState(cup = CUPS[0]), RacePhase.Countdown(2), KartGameActions.Noop)+ }+ rule.onNode(hasScrollAction()).assertDoesNotExist()+ rule.onNodeWithText("2").assertIsDisplayed()+ }++ @Test fun lobbyStillScrolls() {+ rule.setContent {+ KartGameScreen(+ KartUiState(cup = CUPS[0]),+ RacePhase.Lobby(LobbyState(gameId = "kart")),+ KartGameActions.Noop,+ )+ }+ rule.onNode(hasScrollAction()).assertExists()+ }+}
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 305f946a28..ae2e72c05b 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@@ -2,6 +2,7 @@ package com.vayunmathur.games.nonogram.ui 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.fillMaxHeight@@ -95,11 +96,6 @@ fun NonogramGameScreen( onOpenGameCenter: () -> Unit, ) { 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.- // 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(@@ -131,48 +127,104 @@ fun NonogramGameScreen( ) }, ) { padding ->- Column(+ BoxWithConstraints( Modifier .fillMaxSize()- .padding(padding)- .padding(horizontal = Spacing.md),- horizontalAlignment = Alignment.CenterHorizontally,- verticalArrangement = Arrangement.spacedBy(Spacing.md),+ .padding(padding), ) {- if (daily) {- DailyStreakText(state.dailyStreak)- }+ // Wide windows put the hearts and controls beside the board instead of+ // stretching the grid across the window; the board itself never splits.+ // Short landscape windows split too: stacking board over controls cannot+ // fit in ~360dp of height, and pushed Next level off-screen. Compact+ // height alone must not trigger the split — a short portrait window+ // (portrait split-screen, the 320x470dp test window) would halve an+ // already narrow width and squeeze the board into a sliver, so the+ // compact-height branch also requires landscape aspect (the wordmaker+ // gate: isCompactHeight() && maxWidth > maxHeight). Portrait phones+ // keep the stacked layout below, unchanged.+ val sidePanel = isExpandedWidth() || (isCompactHeight() && maxWidth > maxHeight)+ Column(+ Modifier+ .fillMaxSize()+ .padding(horizontal = Spacing.md),+ horizontalAlignment = Alignment.CenterHorizontally,+ verticalArrangement = Arrangement.spacedBy(Spacing.md),+ ) {+ if (daily) {+ DailyStreakText(state.dailyStreak)+ } - val game = state.game- when {- state.generationFailed -> Column(- Modifier.fillMaxWidth(),- horizontalAlignment = Alignment.CenterHorizontally,- verticalArrangement = Arrangement.spacedBy(Spacing.md),- ) {- Text(- stringResource(R.string.generation_failed),- color = MaterialTheme.colorScheme.error,- textAlign = TextAlign.Center,- )- Button(onClick = { actions.retryGeneration() }) {- Text(stringResource(R.string.try_again))+ val game = state.game+ when {+ state.generationFailed -> Column(+ Modifier.fillMaxWidth(),+ horizontalAlignment = Alignment.CenterHorizontally,+ verticalArrangement = Arrangement.spacedBy(Spacing.md),+ ) {+ Text(+ stringResource(R.string.generation_failed),+ color = MaterialTheme.colorScheme.error,+ textAlign = TextAlign.Center,+ )+ Button(onClick = { actions.retryGeneration() }) {+ Text(stringResource(R.string.try_again))+ } }- } - game == null -> Box(- Modifier.fillMaxWidth().padding(Spacing.xxl),- contentAlignment = Alignment.Center,- ) { CircularProgressIndicator() }+ game == null -> Box(+ Modifier.fillMaxWidth().padding(Spacing.xxl),+ contentAlignment = Alignment.Center,+ ) { CircularProgressIndicator() } - sidePanel -> {- Row(- Modifier.weight(1f).fillMaxWidth(),- horizontalArrangement = Arrangement.spacedBy(Spacing.lg),- verticalAlignment = Alignment.CenterVertically,- ) {+ sidePanel -> {+ Row(+ Modifier.weight(1f).fillMaxWidth(),+ horizontalArrangement = Arrangement.spacedBy(Spacing.lg),+ verticalAlignment = Alignment.CenterVertically,+ ) {+ Box(+ Modifier.weight(1f).fillMaxHeight(),+ contentAlignment = Alignment.Center,+ ) {+ NonogramBoard(+ game = game,+ actions = actions,+ markMode = state.markMode,+ modifier = Modifier+ .widthIn(max = BoardMaxWidth)+ .fillMaxWidth(),+ )+ }+ Column(+ 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,+ Alignment.CenterVertically,+ ),+ ) {+ HeartsRow(remaining = game.hearts, total = STARTING_HEARTS)+ NonogramControls(+ game = game,+ state = state,+ actions = actions,+ )+ }+ }+ }++ else -> {+ HeartsRow(remaining = game.hearts, total = STARTING_HEARTS)++ // 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).fillMaxHeight(),+ Modifier.weight(1f).fillMaxWidth(), contentAlignment = Alignment.Center, ) { NonogramBoard(@@ -184,53 +236,13 @@ fun NonogramGameScreen( .fillMaxWidth(), ) }- Column(- 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,- Alignment.CenterVertically,- ),- ) {- HeartsRow(remaining = game.hearts, total = STARTING_HEARTS)- NonogramControls(- game = game,- state = state,- actions = actions,- )- }- }- } - else -> {- HeartsRow(remaining = game.hearts, total = STARTING_HEARTS)-- // 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(+ NonogramControls( game = game,+ state = state, actions = actions,- markMode = state.markMode,- modifier = Modifier- .widthIn(max = BoardMaxWidth)- .fillMaxWidth(), ) }-- NonogramControls(- game = game,- state = state,- actions = actions,- ) } } }
games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramShortPortraitScreenTest.kt
diff --git a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramShortPortraitScreenTest.kt b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramShortPortraitScreenTest.ktnew file mode 100644index 0000000000..b6c8540541--- /dev/null+++ b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramShortPortraitScreenTest.kt@@ -0,0 +1,52 @@+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.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 org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import org.robolectric.annotation.Config+import kotlin.test.Test+import kotlin.test.assertTrue++/**+ * A short portrait window (portrait split-screen size): compact height, but+ * taller than wide. The side-by-side split must not engage here — it would+ * halve an already narrow width and squeeze the board into a sliver — so the+ * stacked portrait layout stays, exactly as in a full-height portrait window.+ */+@RunWith(RobolectricTestRunner::class)+@Config(qualifiers = "w320dp-h470dp-port")+class NonogramShortPortraitScreenTest {+ @get:Rule val rule = createComposeRule()+ private val ctx get() = ApplicationProvider.getApplicationContext<Context>()++ @Test fun shortPortraitKeepsStackedLayout() {+ val p = requireNotNull(NonogramGenerator.generateSeeded(15, 25L))+ val g = NonogramGameState(p, emptySet(), emptySet(), emptySet(), STARTING_HEARTS, GameMode.CASUAL, 25)+ rule.setContent {+ NonogramGameScreen(NonogramUiState(game = g, level = 25), NonogramScreensTest.Recording(), {}, {})+ }+ val lastCell = rule.onNodeWithContentDescription(ctx.getString(R.string.cd_cell_position, 15, 15))+ .fetchSemanticsNode().boundsInRoot+ val toggle = rule.onNodeWithText(ctx.getString(R.string.mode_fill))+ .fetchSemanticsNode().boundsInRoot+ // Stacked: the controls sit under the board, not beside it.+ assertTrue(+ toggle.top >= lastCell.bottom - 0.5f,+ "mode toggle should be under the board in short portrait: toggle=$toggle lastCell=$lastCell",+ )+ // The weighted board slot leaves the controls on screen without scrolling.+ rule.onNodeWithText(ctx.getString(R.string.mode_fill)).assertIsDisplayed()+ }+}