mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
Lay wide session drawer pages out in two columns (#3694)
Keep drawer content composed when changing width, and keep component notes within their groups so columns stay balanced.
This commit is contained in:
1 parent
26b11c6838
commit
fe6f8638c6
4 files changed
+154
-19
No files matched your search
@@ -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
|
||||
@@ -666,6 +669,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)
|
||||
@@ -682,6 +686,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
|
||||
SessionDrawerPage.ACHIEVEMENTS -> a.achievementsGame?.let { DrawerAchievementsPage(it, a.achievementsTitle, track) }
|
||||
SessionDrawerPage.AGENT -> Unit
|
||||
}
|
||||
}
|
||||
} }
|
||||
}
|
||||
}
|
||||
@@ -1557,6 +1562,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
|
||||
@@ -1893,7 +1936,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",
|
||||
@@ -1936,12 +1979,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 }
|
||||
@@ -1982,7 +2019,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(
|
||||
@@ -2018,10 +2055,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
|
||||
|
||||
Reference in new issue
Block a user