mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
feat(ui): reflow settings pages in narrow panes
This commit is contained in:
1 parent
e31b674493
commit
d01b536f1b
3 files changed
+92
-51
No files matched your search
@@ -727,7 +727,8 @@ private fun Pane(
|
||||
onSelect: (String) -> Unit, onAndroidAppClick: (HomeApp.LaunchableApp) -> Unit,
|
||||
onOpenDeveloperOptions: () -> Unit, onRequestWirelessAdb: (Boolean) -> Unit,
|
||||
) {
|
||||
Box(modifier = modifier) {
|
||||
BoxWithConstraints(modifier = modifier) {
|
||||
CompositionLocalProvider(LocalNarrowPane provides (maxWidth < NarrowPaneWidth)) {
|
||||
val backdropArt: File? = when {
|
||||
s.pageKey != null && page != null -> null
|
||||
selected.startsWith("app:") -> s.steamGames.firstOrNull { "app:${it.appId}" == selected }?.art
|
||||
@@ -747,6 +748,7 @@ private fun Pane(
|
||||
if (page != null && key == s.pageKey) page()
|
||||
else Content(s, key, a, Modifier.fillMaxSize(), onSelect, onAndroidAppClick, onOpenDeveloperOptions, onRequestWirelessAdb)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1248,9 +1250,9 @@ private fun SectionTitle(t: String, detail: String?) {
|
||||
|
||||
private val Shape16 = RoundedCornerShape(16.dp)
|
||||
|
||||
/** One level up, as Back and B do: a real button, big enough to hit. */
|
||||
/** One level up, as Back and B do: a real button, big enough to hit ([compact]: for the tightest layouts). */
|
||||
@Composable
|
||||
private fun BackLink(label: String, onClick: () -> Unit) {
|
||||
internal fun BackLink(label: String, compact: Boolean = false, onClick: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
@@ -1258,7 +1260,7 @@ private fun BackLink(label: String, onClick: () -> Unit) {
|
||||
val shape = RoundedCornerShape(22.dp)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.paneItem("back:$label").heightIn(min = 44.dp)
|
||||
modifier = Modifier.paneItem("back:$label").heightIn(min = if (compact) 36.dp else 44.dp)
|
||||
.clip(shape)
|
||||
.background(if (hot) pal.signal.copy(alpha = 0.14f) else Color.White.copy(alpha = 0.04f))
|
||||
.border(2.dp, if (hot) pal.signal else Color.Transparent, shape)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
// Sizes that decide how the launcher reflows on 4:3 and square screens (480x360 or 480x480 dp) as
|
||||
// well as on the 16:9 ones it was first laid out for.
|
||||
|
||||
/** A page narrower than this reflows: settings rows stack, grids drop columns, posters go. */
|
||||
val NarrowPaneWidth = 520.dp
|
||||
|
||||
/** Whether the page being drawn is narrow - the pane beside the rail on a 4:3 or square screen. */
|
||||
val LocalNarrowPane = compositionLocalOf { false }
|
||||
|
||||
/** Too narrow a screen for a labelled rail: the rail shows icons only. */
|
||||
@Composable
|
||||
internal fun isNarrowScreen(): Boolean = LocalConfiguration.current.screenWidthDp < 600
|
||||
|
||||
/** Too short a screen for a hero banner: a landscape phone, a 4:3 or a near-square handheld. */
|
||||
@Composable
|
||||
internal fun isShortScreen(): Boolean = LocalConfiguration.current.screenHeightDp < 440
|
||||
@@ -254,7 +254,14 @@ fun SettingsRow(label: String, hint: String?, highlighted: Boolean = false, cont
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val bg by animateColorAsState(if (highlighted) pal.signal.copy(alpha = 0.10f) else Color.Transparent, Motion.tw(200), label = "rowBg")
|
||||
Row(
|
||||
// A narrow page stacks the control under its label, so neither squeezes the other.
|
||||
if (LocalNarrowPane.current) Column(
|
||||
modifier = Modifier.fillMaxWidth().background(bg).padding(start = 14.dp, end = 14.dp, top = 11.dp, bottom = 12.dp),
|
||||
) {
|
||||
Text(label, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground)
|
||||
if (hint != null) Text(hint, fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(top = 2.dp))
|
||||
Box(Modifier.padding(top = 8.dp)) { control() }
|
||||
} else Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.fillMaxWidth().background(bg).padding(horizontal = 14.dp, vertical = 11.dp),
|
||||
) {
|
||||
@@ -343,62 +350,71 @@ fun SettingsPage(
|
||||
val scrollState = scroll ?: rememberScrollState()
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val dim by animateFloatAsState(if (host.open != null) 0.6f else 1f, Motion.tw(220), label = "pageDim")
|
||||
val narrow = LocalNarrowPane.current && !compactLayout
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize().padding(
|
||||
horizontal = if (compactLayout) 14.dp else 22.dp,
|
||||
vertical = if (compactLayout) 6.dp else 18.dp,
|
||||
horizontal = if (compactLayout) 14.dp else if (narrow) 16.dp else 22.dp,
|
||||
vertical = if (compactLayout) 6.dp else if (narrow) 12.dp else 18.dp,
|
||||
),
|
||||
verticalArrangement = Arrangement.spacedBy(if (compactLayout) 2.dp else 0.dp),
|
||||
) {
|
||||
Rise(0) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
// Outlined when a controller's focus is on it, like every other control here.
|
||||
val backSrc = remember { MutableInteractionSource() }
|
||||
val backHot = backSrc.collectIsFocusedAsState().value || backSrc.collectIsHoveredAsState().value
|
||||
Text(
|
||||
"‹ Back", fontSize = if (compactLayout) 11.sp else 12.sp, fontWeight = FontWeight.SemiBold,
|
||||
color = if (backHot) LocalPalette.current.signal else colors.onSurfaceVariant,
|
||||
modifier = Modifier.clip(RoundedCornerShape(8.dp))
|
||||
.border(2.dp, if (backHot) LocalPalette.current.signal else Color.Transparent, RoundedCornerShape(8.dp))
|
||||
.hoverable(backSrc).clickable(interactionSource = backSrc, indication = null, onClick = onBack)
|
||||
.padding(horizontal = 6.dp, vertical = if (compactLayout) 2.dp else 4.dp),
|
||||
)
|
||||
if (eyebrow != null) {
|
||||
Spacer(Modifier.width(10.dp))
|
||||
Eyebrow(eyebrow)
|
||||
if (narrow) {
|
||||
// Back and the title share one line: a 4:3 screen has no height to spare.
|
||||
Rise(0) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
modifier = Modifier.padding(bottom = 6.dp),
|
||||
) {
|
||||
BackLink("Back", compact = true, onClick = onBack)
|
||||
Text(
|
||||
title, fontSize = 20.sp, fontWeight = FontWeight.Bold, color = colors.onBackground,
|
||||
maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f),
|
||||
)
|
||||
if (action != null) action()
|
||||
}
|
||||
}
|
||||
}
|
||||
Rise(1) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Box(Modifier.weight(1f)) {
|
||||
if (compactLayout) {
|
||||
Text(
|
||||
title,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = colors.onBackground,
|
||||
modifier = Modifier.padding(vertical = 2.dp),
|
||||
)
|
||||
} else {
|
||||
Title(title)
|
||||
if (lede != null) Rise(1) { Lede(lede) }
|
||||
} else {
|
||||
Rise(0) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
BackLink("Back", compact = compactLayout, onClick = onBack)
|
||||
if (eyebrow != null) {
|
||||
Spacer(Modifier.width(10.dp))
|
||||
Eyebrow(eyebrow)
|
||||
}
|
||||
}
|
||||
if (action != null) action()
|
||||
}
|
||||
}
|
||||
if (lede != null) Rise(2) {
|
||||
if (compactLayout) {
|
||||
Text(
|
||||
lede,
|
||||
fontSize = 12.sp,
|
||||
color = colors.onSurfaceVariant,
|
||||
modifier = Modifier.padding(bottom = 3.dp),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
} else {
|
||||
Lede(lede)
|
||||
Rise(1) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Box(Modifier.weight(1f)) {
|
||||
if (compactLayout) {
|
||||
Text(
|
||||
title,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = colors.onBackground,
|
||||
modifier = Modifier.padding(vertical = 2.dp),
|
||||
)
|
||||
} else {
|
||||
Title(title)
|
||||
}
|
||||
}
|
||||
if (action != null) action()
|
||||
}
|
||||
}
|
||||
if (lede != null) Rise(2) {
|
||||
if (compactLayout) {
|
||||
Text(
|
||||
lede,
|
||||
fontSize = 12.sp,
|
||||
color = colors.onSurfaceVariant,
|
||||
modifier = Modifier.padding(bottom = 3.dp),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
} else {
|
||||
Lede(lede)
|
||||
}
|
||||
}
|
||||
}
|
||||
Rise(3, Modifier.weight(1f).fillMaxWidth()) {
|
||||
|
||||
Reference in new issue
Block a user