diff --git a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt index 65b6b1cf1c..002aebf02b 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/SessionOverlay.kt @@ -16,6 +16,8 @@ import androidx.compose.ui.input.key.key import androidx.compose.ui.input.key.onPreviewKeyEvent import androidx.compose.ui.input.key.type import androidx.compose.ui.layout.LayoutCoordinates +import androidx.compose.ui.unit.Constraints +import androidx.compose.ui.layout.Layout import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalLayoutDirection @@ -75,6 +77,7 @@ import androidx.compose.foundation.interaction.PressInteraction import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxHeight @@ -669,6 +672,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont val track: (String) -> Modifier = { key -> focus.track(page, key) } val sections = remember(page) { DrawerSections(drawerContext, track) } CompositionLocalProvider(LocalChipMinWidth provides 96.dp, LocalCompactSettings provides true, LocalDrawerSections provides sections) { + DrawerColumns(two = sheetWidth >= DRAWER_TWO_COLUMN_WIDTH && page.inColumns) { when (page) { SessionDrawerPage.CONTROLLER -> DrawerControllerPage(host, a, a.controllerConnected || controllerActive, track) SessionDrawerPage.HUD -> DrawerPerformancePage(host, a, track) @@ -685,6 +689,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont SessionDrawerPage.ACHIEVEMENTS -> a.achievementsGame?.let { DrawerAchievementsPage(it, a.achievementsTitle, track) } SessionDrawerPage.AGENT -> Unit } + } } } } } @@ -1578,6 +1583,44 @@ internal fun secondScreenModes(none: Boolean, deckPad: Boolean, dashboard: Boole private val DRAWER_MIN_WIDTH = 300.dp private val DRAWER_HANDLE_STRIP = 24.dp +private val DRAWER_COLUMN_GAP = 10.dp +// Two columns once each would be as wide as the narrowest single-column sheet. +private val DRAWER_TWO_COLUMN_WIDTH = DRAWER_MIN_WIDTH * 2 + DRAWER_COLUMN_GAP + +private val SessionDrawerPage.inColumns: Boolean + get() = this != SessionDrawerPage.MORE && this != SessionDrawerPage.ACHIEVEMENTS + +/** + * On a wide sheet, lays a page's groups out in two columns, the first half on the left. The split is by count, not + * height, so a group keeps its column while others fold and unfold. + */ +@Composable +internal fun DrawerColumns(two: Boolean, content: @Composable () -> Unit) { + // Keep a single composition so resizing only remeasures existing children. + Layout(content, Modifier.fillMaxWidth()) { measurables, constraints -> + val width = constraints.maxWidth + if (!two || measurables.size < 2) { + val placeables = measurables.map { it.measure(constraints.copy(minWidth = 0, minHeight = 0)) } + return@Layout layout(width, placeables.sumOf { it.height }) { + var y = 0 + placeables.forEach { it.placeRelative(0, y); y += it.height } + } + } + val gap = DRAWER_COLUMN_GAP.roundToPx() + val column = ((width - gap) / 2).coerceAtLeast(0) + val child = Constraints(maxWidth = column) + val placeables = measurables.map { it.measure(child) } + val half = (placeables.size + 1) / 2 + val left = placeables.take(half) + val right = placeables.drop(half) + layout(width, maxOf(left.sumOf { it.height }, right.sumOf { it.height })) { + var y = 0 + left.forEach { it.placeRelative(0, y); y += it.height } + y = 0 + right.forEach { it.placeRelative(column + gap, y); y += it.height } + } + } +} /** A grip on the sheet's left edge: dragging it, or pressing left and right on a controller, resizes the sheet. */ @Composable @@ -1914,7 +1957,7 @@ private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (Strin } return } - SettingsGroup(stringResource(R.string.drawer_page_components), key = "game-components") { + DrawerComponentSettingsGroup(stringResource(R.string.drawer_game_components_note, gameProfile.name)) { DrawerStackedChoice( host = host, key = "game-cmp-proton", @@ -1957,12 +2000,6 @@ private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (Strin ) } } - Text( - stringResource(R.string.drawer_game_components_note, gameProfile.name), - fontSize = 12.sp, - color = colors.onSurfaceVariant, - modifier = Modifier.padding(horizontal = 4.dp, vertical = 12.dp), - ) return } val running = snap.protons.filter { it.inUseByGame } @@ -2003,7 +2040,7 @@ private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (Strin return } val p = view.proton - SettingsGroup(stringResource(R.string.drawer_page_components), key = "game-components") { + DrawerComponentSettingsGroup(stringResource(R.string.drawer_components_note)) { DrawerStackedChoice( host, "cmp-proton", stringResource(R.string.comp_proton), listOfNotNull( @@ -2039,10 +2076,16 @@ private fun ComponentsDrawerPage(host: MenuHost, a: DrawerActions, track: (Strin ) } } - Text( - stringResource(R.string.drawer_components_note), - fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 4.dp, vertical = 12.dp), - ) +} + +@Composable +internal fun DrawerComponentSettingsGroup(note: String, content: @Composable ColumnScope.() -> Unit) { + // The note stays visible when collapsed, but both belong to one drawer column item. + Column(Modifier.fillMaxWidth()) { + SettingsGroup(stringResource(R.string.drawer_page_components), key = "game-components", content = content) + Text(note, fontSize = 12.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier.padding(horizontal = 4.dp, vertical = 12.dp)) + } } @Composable diff --git a/app/src/test/java/com/droiddeck/launcher/ui/ComponentDownloadsDrawerTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/ComponentDownloadsDrawerTest.kt index 4d3f1852a5..f52ae99690 100644 --- a/app/src/test/java/com/droiddeck/launcher/ui/ComponentDownloadsDrawerTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/ui/ComponentDownloadsDrawerTest.kt @@ -3,24 +3,31 @@ package com.droiddeck.launcher.ui import androidx.compose.foundation.layout.Column import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.Text +import androidx.compose.runtime.State +import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.Modifier import androidx.compose.ui.input.InputMode import androidx.compose.ui.input.InputModeManager import androidx.compose.ui.input.key.Key import androidx.compose.ui.platform.LocalInputModeManager import androidx.compose.ui.platform.testTag +import androidx.compose.ui.semantics.SemanticsActions import androidx.compose.ui.test.assertIsFocused import androidx.compose.ui.test.ExperimentalTestApi import androidx.compose.ui.test.assertIsNotEnabled +import androidx.compose.ui.test.getUnclippedBoundsInRoot import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performKeyInput +import androidx.compose.ui.test.performSemanticsAction import androidx.compose.ui.test.pressKey import androidx.compose.ui.test.requestFocus import com.droiddeck.launcher.R import com.droiddeck.launcher.session.ComponentsManager import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -67,6 +74,29 @@ class ComponentDownloadsDrawerTest { assertEquals(listOf(nightly), requested) } + @Config(qualifiers = "w800dp-h800dp") + @Test fun nightlySelectionSurvivesCrossingTheColumnThreshold() { + val stable = ComponentsManager.CatalogItem("dxvk-3.1.1-linux.wcp", "dxvk", "Dxvk-Linux", "https://github.com/example/s", 100, "sha256:test") + val nightly = ComponentsManager.CatalogItem("DD-dxvk-3.1.1+153-nightly.wcp", "dxvk", ComponentsManager.DD_NIGHTLY, "https://github.com/example/n", 100, "sha256:test") + val twoColumns = mutableStateOf(false) + lateinit var menu: MenuHost + show(catalog = listOf(stable, nightly), twoColumns = twoColumns, captureHost = { menu = it }) + val chooser = compose.onNodeWithTag("cmp-download-dxvk") + val nightlyRow = compose.onNodeWithText(nightly.file.removeSuffix(".wcp")) + val narrowLeft = chooser.getUnclippedBoundsInRoot().left + chooser.performSemanticsAction(SemanticsActions.OnClick) + compose.onNodeWithText(RuntimeEnvironment.getApplication().getString(R.string.comp_channel_nightly)).performClick() + nightlyRow.assertExists() + compose.runOnIdle { menu.open = null; twoColumns.value = true } + assertTrue(chooser.getUnclippedBoundsInRoot().left > narrowLeft) + chooser.performSemanticsAction(SemanticsActions.OnClick) + nightlyRow.assertExists() + compose.runOnIdle { menu.open = null; twoColumns.value = false } + assertEquals(narrowLeft, chooser.getUnclippedBoundsInRoot().left) + chooser.performSemanticsAction(SemanticsActions.OnClick) + nightlyRow.assertExists() + } + @Test fun controllerPicksNightlyOnItsTabThenDownloadsItFromTheRow() { val stable = ComponentsManager.CatalogItem("dxvk-3.1.1-linux.wcp", "dxvk", "Dxvk-Linux", "https://github.com/example/s", 100, "sha256:test") val nightly = ComponentsManager.CatalogItem("DD-dxvk-3.1.1+153-nightly.wcp", "dxvk", ComponentsManager.DD_NIGHTLY, "https://github.com/example/n", 100, "sha256:test") @@ -107,18 +137,28 @@ class ComponentDownloadsDrawerTest { checking: Boolean = false, onRefresh: () -> Unit = {}, onDownload: (ComponentsManager.CatalogItem) -> Unit = {}, + twoColumns: State? = null, + captureHost: (MenuHost) -> Unit = {}, ) { compose.setContent { inputMode = LocalInputModeManager.current DroidDeckTheme { Column(Modifier.verticalScroll(rememberScrollState())) { - ComponentDownloadsDrawerGroup( - host = rememberMenuHost(), catalog = catalog, catalogAt = 0, - checking = checking, - packages = listOf(ComponentsManager.Package(stored.file, "dxvk", "2.3", "", 100)), - downloads = downloads, onRefresh = onRefresh, onDownload = onDownload, - track = { Modifier.testTag(it) }, - ) + val host = rememberMenuHost() + captureHost(host) + val content: @androidx.compose.runtime.Composable () -> Unit = { + ComponentDownloadsDrawerGroup( + host = host, catalog = catalog, catalogAt = 0, + checking = checking, + packages = listOf(ComponentsManager.Package(stored.file, "dxvk", "2.3", "", 100)), + downloads = downloads, onRefresh = onRefresh, onDownload = onDownload, + track = { Modifier.testTag(it) }, + ) + } + if (twoColumns == null) content() else DrawerColumns(twoColumns.value) { + SettingsGroup("Profile") { Text("Profile settings") } + content() + } } } } diff --git a/app/src/test/java/com/droiddeck/launcher/ui/DrawerColumnsTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/DrawerColumnsTest.kt new file mode 100644 index 0000000000..a5201db5b4 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/ui/DrawerColumnsTest.kt @@ -0,0 +1,48 @@ +package com.droiddeck.launcher.ui + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.height +import androidx.compose.material3.Text +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.testTag +import androidx.compose.ui.test.getUnclippedBoundsInRoot +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.unit.dp +import org.junit.Assert.assertTrue +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [28], qualifiers = "w800dp-h600dp") +class DrawerColumnsTest { + @get:Rule val compose = createRobolectricComposeRule() + + @Test fun theComponentNoteStaysInItsGroupAndSixGroupsSplitEvenly() { + val note = "Component note" + val componentRow = "Component row" + compose.setContent { + DroidDeckTheme { + DrawerColumns(two = true) { + repeat(3) { index -> Box(Modifier.height(32.dp).testTag("left-$index")) } + DrawerComponentSettingsGroup(note) { Text(componentRow) } + repeat(2) { index -> Box(Modifier.height(32.dp).testTag("right-$index")) } + } + } + } + val left = (0..2).map { compose.onNodeWithTag("left-$it").getUnclippedBoundsInRoot() } + val right = (0..1).map { compose.onNodeWithTag("right-$it").getUnclippedBoundsInRoot() } + val group = compose.onNodeWithText(componentRow).getUnclippedBoundsInRoot() + val footer = compose.onNodeWithText(note).getUnclippedBoundsInRoot() + assertTrue(left.all { it.left == left.first().left }) + assertTrue(right.all { it.left == right.first().left && it.left > left.first().left }) + assertTrue(group.left >= right.first().left) + assertTrue(footer.left >= right.first().left) + assertTrue(footer.top >= group.bottom) + assertTrue(right.first().top >= footer.bottom) + assertTrue(left.zipWithNext().all { (first, next) -> first.bottom <= next.top }) + } +} diff --git a/tools/agent/AGENTS.md b/tools/agent/AGENTS.md index d9b7deb09e..709dcbf181 100644 --- a/tools/agent/AGENTS.md +++ b/tools/agent/AGENTS.md @@ -57,6 +57,10 @@ The source is checked out at `/root/DroidDeck` once the Agent tab's build tools build in a process of its own and shows its progress; `dd-lab-build` follows its log. Run it in the background and keep checking, so the user can talk to you meanwhile. The restart ends your process, and the conversation continues on the new build. +- To try a change, commit it and go straight to `dd-lab-build`: it compiles the app, so a Gradle + compile first only adds time. It refuses changes since the installed build (`apkCommit` in + `droiddeckctl state`) that need a new APK. For a branch from a newer `origin/main`, cherry-pick + its commits onto a branch from `apkCommit` and build that. - Python tests run from the repository root: `python3 -m unittest tools.tests.test_x`. Some fail on the device on `origin/main` too; run them on a worktree of `origin/main` before blaming a change. - Gradle runs on the device once the build tools are set up, but slowly: run the test classes that cover