feat: game page with art backdrop and frosted controls (#1738)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-28 19:33:33 -04:00
1 parent 1e92d10fa5
commit 87572a7f91
12 files changed
+603 -138

No files matched your search

@@ -33,6 +33,9 @@ import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.layout.layout
import kotlinx.coroutines.delay
import androidx.compose.runtime.setValue
import androidx.compose.runtime.getValue
@@ -40,6 +43,20 @@ import androidx.compose.runtime.getValue
/** A grid of cards with a game page that floods out of the opened card and drains back into it. */
internal val LocalDetailFloor = compositionLocalOf<() -> Float> { { Float.MAX_VALUE } }
/** How far the host reaches past the page's padding, so a game page can paint to the screen edge and still inset its content. */
internal class DetailInset(val horizontal: Dp, val top: Dp)
internal val LocalDetailInset = compositionLocalOf { DetailInset(0.dp, 0.dp) }
private fun Modifier.bleed(horizontal: Dp, top: Dp): Modifier =
if (horizontal == 0.dp && top == 0.dp) this else layout { measurable, constraints ->
val h = horizontal.roundToPx()
val t = top.roundToPx()
val placeable = measurable.measure(
Constraints.fixed(constraints.maxWidth + h * 2, if (constraints.hasBoundedHeight) constraints.maxHeight + t else constraints.minHeight),
)
layout(constraints.maxWidth, placeable.height - t) { placeable.place(-h, -t) }
}
@OptIn(androidx.compose.ui.ExperimentalComposeUiApi::class)
@Composable
internal fun CardDetailHost(
@@ -48,6 +65,8 @@ internal fun CardDetailHost(
gridScrolled: () -> Boolean,
onDetailFocus: (Boolean) -> Unit,
modifier: Modifier = Modifier,
bleedHorizontal: Dp = 0.dp,
bleedTop: Dp = 0.dp,
wrap: @Composable (key: String, content: @Composable () -> Unit) -> Unit = { _, content -> content() },
grid: @Composable () -> Unit,
detail: @Composable (key: String) -> Unit,
@@ -86,7 +105,7 @@ internal fun CardDetailHost(
val gridAlpha by animateFloatAsState(if (covering) 0f else 1f, if (covering) Motion.tw(320, 80) else Motion.tw(300, 100), label = "gridFade")
val fade = with(density) { 14.dp.toPx() }
Box(
modifier.clipToBounds()
modifier.bleed(bleedHorizontal, bleedTop).clipToBounds()
.onGloballyPositioned { viewportAt = it.positionInRoot(); viewportH = it.size.height }
.graphicsLayer { compositingStrategy = androidx.compose.ui.graphics.CompositingStrategy.Offscreen }
.drawWithContent {
@@ -100,7 +119,7 @@ internal fun CardDetailHost(
) {
CompositionLocalProvider(LocalFrontFocus provides if (covering) null else ff) {
Column(
modifier = Modifier.fillMaxSize()
modifier = Modifier.fillMaxSize().padding(horizontal = bleedHorizontal).padding(top = bleedTop)
.graphicsLayer { scaleX = gridScale; scaleY = gridScale; alpha = gridAlpha }
.focusProperties { enter = { if (coveringNow.value) FocusRequester.Cancel else FocusRequester.Default } }
.focusGroup(),
@@ -111,7 +130,7 @@ internal fun CardDetailHost(
val body: @Composable () -> Unit = {
Column(
Modifier.fillMaxSize().pointerInput(Unit) { detectTapGestures { } }
.verticalScroll(detailScroll).padding(top = 4.dp, bottom = 16.dp),
.verticalScroll(detailScroll).padding(bottom = 16.dp),
) {
Column(
Modifier.fillMaxWidth()
@@ -120,7 +139,7 @@ internal fun CardDetailHost(
.focusGroup(),
) {
val floor = { viewportAt.y + viewportH - with(density) { 16.dp.toPx() } - detailScroll.value }
CompositionLocalProvider(LocalDetailFloor provides floor) { detail(key) }
CompositionLocalProvider(LocalDetailFloor provides floor, LocalDetailInset provides DetailInset(bleedHorizontal, bleedTop + 4.dp)) { detail(key) }
}
}
}
@@ -841,9 +841,8 @@ private fun SettingCard(label: String, value: String, id: String, modifier: Modi
verticalArrangement = Arrangement.spacedBy(3.dp),
modifier = modifier.paneItem(id)
.graphicsLayer { scaleX = scale; scaleY = scale }
.clip(Shape14)
.background(if (hot) pal.signal.copy(alpha = 0.10f) else colors.surface)
.glideBorder(hot, Shape14, pal.signal, pal.line2)
.then(if (LocalGlass.current != null) Modifier.glass(Shape14, if (hot) 0.04f else 0f) else Modifier.clip(Shape14).background(if (hot) pal.signal.copy(alpha = 0.10f) else colors.surface))
.glideBorder(hot, Shape14, pal.signal, if (LocalGlass.current != null) Color.Transparent else pal.line2)
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = Role.Button, onClick = onClick)
.controllerConfirm(onClick = onClick)
.padding(horizontal = 14.dp, vertical = 12.dp),
@@ -32,6 +32,7 @@ import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Settings
@@ -163,6 +164,8 @@ internal fun PrimaryButton(
) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val pillMode = LocalPillButtons.current
val btnShape = if (pillMode) CircleShape else Shape12
val frontFocus = if (main) LocalFrontFocus.current else null
if (frontFocus != null) DisposableEffect(Unit) {
frontFocus.primaryAttached++
@@ -180,22 +183,22 @@ internal fun PrimaryButton(
horizontalArrangement = if (fill) Arrangement.spacedBy(8.dp, Alignment.CenterHorizontally) else Arrangement.spacedBy(8.dp),
modifier = modifier.then(track)
.onGloballyPositioned { placed[0] = it }
.heightIn(min = if (compact) 44.dp else 48.dp)
.heightIn(min = if (pillMode) 40.dp else if (compact) 44.dp else 48.dp)
.then(if (frontFocus != null) Modifier.focusRequester(frontFocus.primary).onFocusChanged { if (it.isFocused) frontFocus.last = FrontFocus.PRIMARY } else Modifier)
.graphicsLayer { alpha = if (LaunchOrigin.flooding === placed) 0f else 1f; scaleX = scale; scaleY = scale; shadowElevation = if (enabled) lift.dp.toPx() else 0f; shape = Shape12; clip = false; ambientShadowColor = pal.signal; spotShadowColor = pal.signal }
.clip(Shape12)
.graphicsLayer { alpha = if (LaunchOrigin.flooding === placed) 0f else 1f; scaleX = scale; scaleY = scale; shadowElevation = if (enabled) lift.dp.toPx() else 0f; shape = btnShape; clip = false; ambientShadowColor = pal.signal; spotShadowColor = pal.signal }
.clip(btnShape)
.background(if (enabled) Brush.linearGradient(listOf(colors.primary, pal.primary2)) else Brush.linearGradient(listOf(colors.surfaceVariant, colors.surfaceVariant)))
.then(if (enabled) Modifier else Modifier.border(1.dp, pal.line2, Shape12))
.glideBorder(hot, Shape12, pal.signal, hotFillAlpha = 0f)
.then(if (enabled) Modifier else Modifier.border(1.dp, pal.line2, btnShape))
.glideBorder(hot, btnShape, pal.signal, hotFillAlpha = 0f)
.hoverable(src).clickable(role = Role.Button, interactionSource = src, indication = null, enabled = enabled) {
placed[0]?.takeIf { it.isAttached }?.let { LaunchOrigin.mark(it.boundsInRoot(), placed) }
onClick()
}
.padding(
start = if (fill) 12.dp else if (large) 20.dp else if (compact) 10.dp else if (icon != null) 14.dp else 18.dp,
end = if (fill) 12.dp else if (large) 26.dp else if (compact) 10.dp else 18.dp,
top = if (large) 16.dp else if (compact) 7.dp else 11.dp,
bottom = if (large) 16.dp else if (compact) 7.dp else 11.dp,
start = if (fill) 12.dp else if (large) 20.dp else if (pillMode) 18.dp else if (compact) 10.dp else if (icon != null) 14.dp else 18.dp,
end = if (fill) 12.dp else if (large) 26.dp else if (pillMode) 20.dp else if (compact) 10.dp else 18.dp,
top = if (large) 16.dp else if (pillMode) 8.dp else if (compact) 7.dp else 11.dp,
bottom = if (large) 16.dp else if (pillMode) 8.dp else if (compact) 7.dp else 11.dp,
),
) {
val fg = if (enabled) colors.onPrimary else colors.onSurfaceVariant
@@ -240,22 +243,24 @@ internal fun ProgressLabel(label: @Composable (Modifier) -> Unit, progress: Floa
@Composable
internal fun SecondaryButton(text: String, enabled: Boolean = true, compact: Boolean = false, modifier: Modifier = Modifier, progress: Float? = null, onClick: () -> Unit) {
val colors = MaterialTheme.colorScheme
val pill = LocalPillButtons.current
val shape = if (pill) CircleShape else Shape12
val src = remember { MutableInteractionSource() }
val hot = rememberHot(src) && enabled
val pressed by src.collectIsPressedAsState()
val scale by animateFloatAsState(if (pressed) 0.955f else if (hot) 1.02f else 1f, Motion.sp(0.5f, Spring.StiffnessMedium), label = "secScale")
val pal = LocalPalette.current
val fill by animateColorAsState(if (hot) pal.signal.copy(alpha = 0.14f) else Color.White.copy(alpha = 0.03f), Motion.tw(250), label = "secFill")
val fill by animateColorAsState(if (hot) pal.signal.copy(alpha = 0.14f) else Color.White.copy(alpha = if (pill) 0.09f else 0.03f), Motion.tw(250), label = "secFill")
Box(
contentAlignment = Alignment.Center,
modifier = modifier.paneItem("btn:$text").downToFirstTile().heightIn(min = if (compact) 44.dp else 48.dp).graphicsLayer { scaleX = scale; scaleY = scale }.clip(Shape12).background(fill).glideBorder(hot, Shape12, pal.signal, pal.line2)
modifier = modifier.paneItem("btn:$text").downToFirstTile().heightIn(min = if (pill) 40.dp else if (compact) 44.dp else 48.dp).graphicsLayer { scaleX = scale; scaleY = scale }.clip(shape).background(fill).glideBorder(hot, shape, pal.signal, if (pill) Color.White.copy(alpha = 0.14f) else pal.line2)
.alpha(if (enabled) 1f else 0.5f)
.hoverable(src).clickable(role = androidx.compose.ui.semantics.Role.Button, interactionSource = src, indication = LocalIndication.current, enabled = enabled, onClick = onClick)
.controllerConfirm(enabled = enabled, onClick = onClick)
.padding(horizontal = if (compact) 10.dp else 16.dp, vertical = if (compact) 7.dp else 11.dp),
.padding(horizontal = if (pill) 16.dp else if (compact) 10.dp else 16.dp, vertical = if (pill) 8.dp else if (compact) 7.dp else 11.dp),
) {
ProgressLabel({ m -> Text(text, fontSize = if (compact) 12.sp else 15.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 0.5.sp, color = colors.onBackground, maxLines = 1, modifier = m) },
progress, fontSize = if (compact) 12.sp else 15.sp)
ProgressLabel({ m -> Text(text, fontSize = if (compact || pill) 13.sp else 15.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 0.5.sp, color = colors.onBackground, maxLines = 1, modifier = m) },
progress, fontSize = if (compact || pill) 13.sp else 15.sp)
}
}
@@ -1,6 +1,15 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.LocalIndication
import androidx.compose.ui.semantics.Role
import androidx.compose.runtime.CompositionLocalProvider
import com.droiddeck.launcher.stores.GameFacts
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.graphics.Shadow
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
@@ -29,6 +38,8 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.outlined.Edit
import androidx.compose.material.icons.outlined.VideogameAsset
import androidx.compose.material.icons.filled.Check
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
@@ -170,7 +181,7 @@ internal fun GameDetail(
val scored = scores != null && (scores.metacritic != Lookup.None || scores.hltb != Lookup.None)
val prefix = game?.protonPrefix?.takeIf { it.isDirectory }
val tabs = buildList {
if (description.isNotBlank() || developer.isNotBlank() || publisher.isNotBlank() || releaseDate.isNotBlank() || (scored && stacked)) add(GameTab.ABOUT)
if (description.isNotBlank() || developer.isNotBlank() || publisher.isNotBlank() || releaseDate.isNotBlank() || scored || (!s.shortcutPicker && title.isNotBlank() && title != id)) add(GameTab.ABOUT)
if (achievementState != null) add(GameTab.ACHIEVEMENTS)
val cloud = game?.library == Library.XBOX_CLOUD
if (game != null && !cloud) add(GameTab.LAUNCH)
@@ -196,61 +207,64 @@ internal fun GameDetail(
val at = tabs.indexOf(tab).coerceAtLeast(0)
picked = tabs[(at + step + tabs.size) % tabs.size]
}
Column(Modifier.fillMaxWidth().onFocusChanged { inPage = it.hasFocus }.bumpers(onPrevious = { cycle(-1) }, onNext = { cycle(1) })) {
Rise(0) {
Box(Modifier.padding(bottom = 12.dp)) { BackLink(backLabel, compact = true, onClick = onBack) }
}
val hero: @Composable () -> Unit = {
DisposableEffect(Unit) { onDispose { StoresMotion.heroAt = null } }
GameHero(
title, item, installed, game,
Modifier.fillMaxWidth().heightIn(min = if (narrow) 170.dp else 210.dp).onGloballyPositioned { StoresMotion.heroAt = it.boundsInRoot() },
corner = {
if (!s.shortcutPicker) Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
if (installed != null && installed.sidecar.store == Store.ITCH) ItchCheckButton(installed)
RemoveButton(title, game, installed, a)
}
},
scores = scores.takeIf { !stacked },
) {
HeroEyebrow(source, game, item, installed, download?.location ?: failed?.location)
GameTitle(title, game?.logo ?: item?.logoUrl, if (narrow) 26.sp else 34.sp)
if (!failed?.error.isNullOrBlank()) Text(
failed!!.error!!, fontSize = 13.sp, lineHeight = 17.sp, fontWeight = FontWeight.Medium,
color = MaterialTheme.colorScheme.error, maxLines = 3, overflow = TextOverflow.Ellipsis,
)
Spacer(Modifier.height(4.dp))
GameActions(store, id, game, item, installed, s, a, Modifier.focusRequester(lead))
}
}
if (StoresMotion.heroLands) hero() else Rise(1) { hero() }
if (!s.shortcutPicker) Rise(2) {
GameResourcesRow(title.takeUnless { it == id }.orEmpty(), game, Modifier.padding(top = 6.dp))
}
if (tab != null) Rise(2) {
Column(Modifier.fillMaxWidth().padding(top = 14.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) {
val labels = tabs.map { t ->
when (t) {
GameTab.ABOUT -> stringResource(R.string.game_tab_about)
GameTab.ACHIEVEMENTS -> achievementState?.list?.takeIf { it.isNotEmpty() }?.let { list ->
stringResource(R.string.game_tab_achievements_count, stringResource(R.string.achievements_title), achievementState.done, list.size)
} ?: stringResource(R.string.achievements_title)
GameTab.LAUNCH -> stringResource(R.string.game_tab_launch)
GameTab.SAVES -> stringResource(if (Store.byId(source).let { it == Store.GOG || it == Store.EPIC }) R.string.game_tab_saves_cloud else R.string.games_saves)
GameTab.INSTALL -> stringResource(R.string.game_tab_install)
val art: Any? = game?.hero ?: item?.imageUrl ?: installed?.sidecar?.hero ?: installed?.sidecar?.cover
val artModel: Any? = if (art is String) cardArtRequest(art, item?.tallImageUrl) else art
val inSteam = !s.shortcutPicker && source != Library.SOURCE_STEAM && (game != null || installed != null) && !(game?.library == Library.XBOX_CLOUD && installed == null)
val inset = LocalDetailInset.current
GameBackdrop(artModel, art ?: game?.art, hueOf(title), fadeTop = inset.top < 8.dp, onArtPlaced = { StoresMotion.heroAt = it }) {
Column(Modifier.fillMaxWidth().padding(horizontal = inset.horizontal).padding(top = inset.top).onFocusChanged { inPage = it.hasFocus }.bumpers(onPrevious = { cycle(-1) }, onNext = { cycle(1) })) {
Rise(0) {
Row(Modifier.fillMaxWidth().padding(bottom = 8.dp), verticalAlignment = Alignment.CenterVertically) {
Box(Modifier.glass(CircleShape)) { BackLink(backLabel, compact = true, onClick = onBack) }
Spacer(Modifier.weight(1f))
if (!s.shortcutPicker) CompositionLocalProvider(LocalPillButtons provides true) {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
if (installed != null && installed.sidecar.store == Store.ITCH) ItchCheckButton(installed)
RemoveButton(title, game, installed, a)
}
}
}
TabStrip(
labels, tabs.indexOf(tab), { picked = tabs[it] }, Modifier.onFocusChanged { onStrip = it.hasFocus },
focusRequesters = tabs.map { tabFocus.getValue(it) }, bumpers = tabs.size > 1, compact = narrow,
)
Box(Modifier.fillMaxWidth().onFocusChanged { if (inPanel && !it.hasFocus) dropped++; inPanel = it.hasFocus }.testTag("game-tab-${tab.name.lowercase()}")) {
when (tab) {
GameTab.ABOUT -> AboutTab(developer, publisher, releaseDate, description, scores, stacked)
GameTab.ACHIEVEMENTS -> achievementState?.let { st -> AchievementsTab(StoreAchievements.forSource(store?.id)?.label.orEmpty(), st) }
GameTab.LAUNCH -> if (game != null) LaunchTab(game, s, a, hopRail)
GameTab.SAVES -> if (game != null && prefix != null) SavesTab(game, prefix, a)
GameTab.INSTALL -> InstallTab(game, installed, item, store)
}
val header: @Composable () -> Unit = {
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
GameStatusLine(source, game, item, installed, download?.location ?: failed?.location, inSteam)
GameTitle(title, game?.logo ?: item?.logoUrl, if (narrow) 30.sp else 40.sp)
if (!failed?.error.isNullOrBlank()) Text(
failed!!.error!!, fontSize = 13.sp, lineHeight = 17.sp, fontWeight = FontWeight.Medium,
color = MaterialTheme.colorScheme.error, maxLines = 3, overflow = TextOverflow.Ellipsis,
)
Spacer(Modifier.height(2.dp))
GameCapsule(scores) { GameActions(store, id, game, item, installed, s, a, Modifier.focusRequester(lead), compactMenu = stacked) }
}
}
if (StoresMotion.heroLands) header() else Rise(1) { header() }
if (tab != null) Rise(2) {
Column(Modifier.fillMaxWidth().padding(top = 14.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
val labels = tabs.map { t ->
when (t) {
GameTab.ABOUT -> stringResource(R.string.game_tab_about)
GameTab.ACHIEVEMENTS -> achievementState?.list?.takeIf { it.isNotEmpty() && !stacked }?.let { list ->
stringResource(R.string.game_tab_achievements_count, stringResource(R.string.achievements_title), achievementState.done, list.size)
} ?: stringResource(R.string.achievements_title)
GameTab.LAUNCH -> stringResource(R.string.game_tab_launch)
GameTab.SAVES -> stringResource(if (Store.byId(source).let { it == Store.GOG || it == Store.EPIC }) R.string.game_tab_saves_cloud else R.string.games_saves)
GameTab.INSTALL -> stringResource(R.string.game_tab_install)
}
}
GameTabBar(
labels, tabs.indexOf(tab), { picked = tabs[it] }, Modifier.onFocusChanged { onStrip = it.hasFocus },
focusRequesters = tabs.map { tabFocus.getValue(it) }, bumpers = tabs.size > 1, compact = stacked,
)
Box(Modifier.fillMaxWidth().onFocusChanged { if (inPanel && !it.hasFocus) dropped++; inPanel = it.hasFocus }.testTag("game-tab-${tab.name.lowercase()}")) {
when (tab) {
GameTab.ABOUT -> AboutTab(developer, publisher, releaseDate, description, scores, stacked) {
if (!s.shortcutPicker) GameResourcesRow(title.takeUnless { it == id }.orEmpty(), game)
}
GameTab.ACHIEVEMENTS -> achievementState?.let { st -> AchievementsTab(StoreAchievements.forSource(store?.id)?.label.orEmpty(), st) }
GameTab.LAUNCH -> if (game != null) LaunchTab(game, s, a, hopRail)
GameTab.SAVES -> if (game != null && prefix != null) SavesTab(game, prefix, a)
GameTab.INSTALL -> InstallTab(game, installed, item, store)
}
}
}
}
@@ -259,42 +273,21 @@ internal fun GameDetail(
}
@Composable
private fun GameHero(
title: String, item: CatalogItem?, installed: InstalledStoreGame?, game: Library.SteamGame?, modifier: Modifier,
corner: @Composable BoxScope.() -> Unit, scores: GameScores?, content: @Composable ColumnScope.() -> Unit,
) {
val colors = MaterialTheme.colorScheme
Box(modifier.clip(Shape16).background(artBrush(hueOf(title)))) {
val wide: Any? = game?.hero ?: item?.imageUrl ?: installed?.sidecar?.hero ?: installed?.sidecar?.cover
if (wide != null) {
// The card it came from keeps its own bitmap under the hero until the wide art is decoded.
val request = if (wide is String) cardArtRequest(wide, item?.tallImageUrl) else wide
AsyncImage(model = request, contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier.matchParentSize())
} else game?.art?.let { art ->
AsyncImage(
model = art, contentDescription = null, contentScale = ContentScale.Crop,
modifier = Modifier.matchParentSize().blur(24.dp).graphicsLayer { scaleX = 1.3f; scaleY = 1.3f },
)
}
Spacer(Modifier.matchParentSize().background(Brush.horizontalGradient(0f to colors.background.copy(alpha = 0.94f), 0.55f to colors.background.copy(alpha = 0.58f), 1f to Color.Transparent)))
var scoresWidth by remember { mutableStateOf(0) }
if (scores != null) {
Spacer(Modifier.matchParentSize().background(Brush.horizontalGradient(0.45f to Color.Transparent, 1f to colors.background.copy(alpha = 0.75f))))
HeroScores(scores, Modifier.align(Alignment.BottomEnd).padding(end = 16.dp, bottom = 18.dp).onSizeChanged { scoresWidth = it.width })
}
val scoresSpace = with(LocalDensity.current) { if (scores != null && scoresWidth > 0) scoresWidth.toDp() + 16.dp else 0.dp }
Column(
verticalArrangement = Arrangement.spacedBy(6.dp),
modifier = Modifier.align(Alignment.BottomStart).padding(start = 22.dp, end = 22.dp + scoresSpace, top = 18.dp, bottom = 18.dp),
content = content,
)
Box(Modifier.align(Alignment.TopEnd).padding(12.dp), content = corner)
private fun SourceBadge(source: String) {
val c = sourceColours(source)
Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(7.dp),
modifier = Modifier.glass(CircleShape, 0.06f).padding(horizontal = 10.dp, vertical = 4.dp),
) {
Box(Modifier.size(8.dp).clip(CircleShape).background(c.dot))
Text(sourceLabel(source), fontSize = 11.sp, fontWeight = FontWeight.Bold, letterSpacing = 0.8.sp, color = MaterialTheme.colorScheme.onBackground, maxLines = 1)
}
}
@Composable
private fun HeroEyebrow(source: String, game: Library.SteamGame?, item: CatalogItem?, installed: InstalledStoreGame?, downloadAt: String?) {
private fun GameStatusLine(source: String, game: Library.SteamGame?, item: CatalogItem?, installed: InstalledStoreGame?, downloadAt: String?, inSteam: Boolean) {
val ctx = LocalContext.current
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val folder = installed?.folder ?: game?.gameFiles
val passName = item?.includedWith.orEmpty()
@@ -310,10 +303,68 @@ private fun HeroEyebrow(source: String, game: Library.SteamGame?, item: CatalogI
else -> listOf(stringResource(R.string.stores_eyebrow_store))
}
val size = if (folder != null && (installed != null || game != null)) diskSize(installed, folder) else (item?.sizeBytes ?: 0L).takeIf { it > 0 }
val line = (state + listOfNotNull(size?.let { formatBytes(it) })).filter { it.isNotBlank() }.joinToString(" · ")
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
SourceChip(source)
Text(line.uppercase(), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.2.sp, color = pal.signal, maxLines = 1, overflow = TextOverflow.Ellipsis)
val line = (state + listOfNotNull(size?.let { formatBytes(it) })).filter { it.isNotBlank() }.joinToString(" · ").replaceFirstChar { it.uppercase() }
val muted = colors.onBackground.copy(alpha = 0.78f)
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
SourceBadge(source)
Text(line, fontSize = 12.sp, color = muted, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f, fill = false))
if (inSteam) {
Text("·", fontSize = 12.sp, color = muted.copy(alpha = 0.5f))
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(5.dp)) {
Icon(Icons.Outlined.VideogameAsset, contentDescription = null, tint = muted, modifier = Modifier.size(15.dp))
Text(stringResource(R.string.stores_in_steam_label), fontSize = 12.sp, color = muted, maxLines = 1)
Icon(Icons.Filled.Check, contentDescription = null, tint = pal.good, modifier = Modifier.size(14.dp))
}
}
}
}
/** One frosted pill that holds the game's actions and its headline scores. */
@Composable
private fun GameCapsule(scores: GameScores?, actions: @Composable () -> Unit) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().glass(RoundedCornerShape(30.dp)).padding(6.dp),
) {
CompositionLocalProvider(LocalPillButtons provides true) { Box(Modifier.weight(1f)) { actions() } }
if (scores != null) CapsuleScores(scores, Modifier.padding(start = 8.dp, end = 10.dp))
}
}
@Composable
private fun GameTabBar(
tabs: List<String>, selected: Int, onSelect: (Int) -> Unit,
modifier: Modifier = Modifier, focusRequesters: List<FocusRequester>? = null,
bumpers: Boolean = true, compact: Boolean = false,
) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
Row(modifier.fillMaxWidth().glass(CircleShape).padding(4.dp), verticalAlignment = Alignment.CenterVertically) {
if (bumpers) BumperKey("LB", stringResource(R.string.widgets_prev_tab)) { onSelect((selected + tabs.size - 1) % tabs.size) }
tabs.forEachIndexed { i, label ->
val on = i == selected
val src = remember { MutableInteractionSource() }
val hot = rememberHot(src)
val pick = { onSelect(i) }
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.weight(1f)
.testTag("tab-$i")
.then(focusRequesters?.getOrNull(i)?.let { Modifier.focusRequester(it) } ?: Modifier)
.clip(CircleShape)
.background(if (on) pal.signal.copy(alpha = 0.3f) else if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent)
.glideBorder(hot, CircleShape, pal.signal, if (on) pal.signal.copy(alpha = 0.5f) else Color.Transparent)
.hoverable(src).selectable(selected = on, interactionSource = src, indication = null, role = Role.Tab, onClick = pick)
.controllerConfirm(onClick = pick)
.padding(horizontal = 6.dp, vertical = if (compact) 8.dp else 10.dp),
) {
Text(
label, fontSize = if (compact) 13.sp else 14.sp, fontWeight = if (on) FontWeight.Bold else FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis,
color = if (on || hot) colors.onBackground else colors.onSurfaceVariant,
)
}
}
if (bumpers) BumperKey("RB", stringResource(R.string.widgets_next_tab)) { onSelect((selected + 1) % tabs.size) }
}
}
@@ -323,17 +374,18 @@ private fun GameTitle(title: String, logo: Any?, titleSize: TextUnit) {
if (logo != null && !failed) AsyncImage(
model = logo, contentDescription = title, contentScale = ContentScale.Fit, alignment = Alignment.CenterStart,
onError = { failed = true },
modifier = Modifier.padding(vertical = 4.dp).height((titleSize.value * 2.2f).dp).widthIn(max = (titleSize.value * 9f).dp).testTag("game-logo"),
modifier = Modifier.padding(vertical = 4.dp).height((titleSize.value * 1.5f).dp).widthIn(max = (titleSize.value * 7f).dp).clip(RoundedCornerShape(10.dp)).testTag("game-logo"),
) else Text(
title, fontSize = titleSize, lineHeight = titleSize * 1.12f, fontWeight = FontWeight.Black,
color = MaterialTheme.colorScheme.onBackground, maxLines = 2, overflow = TextOverflow.Ellipsis,
style = TextStyle(shadow = Shadow(Color.Black.copy(alpha = 0.55f), blurRadius = 24f)),
)
}
@Composable
internal fun GameActions(
store: Store?, id: String?, game: Library.SteamGame?, item: CatalogItem?, installed: InstalledStoreGame?,
s: FrontEndState, a: FrontEndActions, leadOn: Modifier,
s: FrontEndState, a: FrontEndActions, leadOn: Modifier, compactMenu: Boolean = false,
) {
val ctx = LocalContext.current
val storeKey = if (store != null && id != null) "${store.id}:$id" else null
@@ -356,11 +408,12 @@ internal fun GameActions(
) {
if (game != null) a.onSteamGame(game) else if (store != null && id != null) launchStoreGame(ctx, store, id, s, a)
}
if ((game?.source ?: store?.id) != Library.SOURCE_STEAM) ActionChip(stringResource(R.string.stores_in_steam), ok = true)
if (game != null) {
FileButtons(game, a)
GameShortcutMenu(game, a)
EditArtButton(game)
if (compactMenu) GameMoreMenu(game, a) else {
FileButtons(game, a)
GameShortcutMenu(game, a)
EditArtButton(game)
}
}
if (store == Store.ITCH && installed != null) ItchUpdateButton(installed, download == null && StoresState.uninstalling[installed.key] == null)
if (store == Store.GOG && installed != null) GogMaintenanceActions(installed)
@@ -521,10 +574,10 @@ private fun GameShortcutMenu(g: Library.SteamGame, a: FrontEndActions) {
/** The pencil opens the editor each kind of game always had: the shortcut editor for added games, art for the rest. */
@Composable
private fun EditArtButton(g: Library.SteamGame) {
private fun rememberEditArt(g: Library.SteamGame): (() -> Unit)? {
val ctx = LocalContext.current
val folder = g.gameFiles
val open: (() -> Unit)? = when {
return when {
g.library == Library.ADDED && g.source == Library.ADDED && folder != null -> {
{ GamesDialogState.editing = EditRequest(folder.path, openTarget = false, fromSummary = false, preview = EditPreview.of(ctx, g, folder.path)) }
}
@@ -532,21 +585,47 @@ private fun EditArtButton(g: Library.SteamGame) {
g.library == Library.ADDED && g.source != Library.ADDED && folder != null -> { { GamesDialogState.storeArt = g } }
else -> null
}
if (open != null) IconAction(Icons.Outlined.Edit, stringResource(R.string.common_edit), "game:edit", onClick = open)
}
@Composable
private fun EditArtButton(g: Library.SteamGame) {
val open = rememberEditArt(g) ?: return
IconAction(Icons.Outlined.Edit, stringResource(R.string.game_edit_art), "game:edit", onClick = open)
}
/** Narrow screens keep one More button in the capsule instead of a row of small ones. */
@Composable
private fun GameMoreMenu(g: Library.SteamGame, a: FrontEndActions) {
var open by remember(g.gameId) { mutableStateOf(false) }
val edit = rememberEditArt(g)
Box {
SecondaryButton(stringResource(R.string.game_more)) { open = !open }
AnchoredMenu(open, onDismiss = { open = false }, title = stringResource(R.string.game_more), compact = true) { first ->
var lead: FocusRequester? = first
fun take(): FocusRequester? = lead.also { lead = null }
g.gameFiles?.takeIf { it.isDirectory }?.let { dir -> MenuItem(stringResource(R.string.games_files), checked = false, focusRequester = take()) { open = false; a.onBrowseFiles(dir) } }
g.protonPrefix?.takeIf { it.isDirectory }?.let { dir -> MenuItem(stringResource(R.string.games_prefix), checked = false, focusRequester = take()) { open = false; a.onBrowseFiles(dir) } }
MenuItem(stringResource(R.string.game_shortcut_add), checked = false, focusRequester = take()) { open = false; a.onGameShortcut(g) }
MenuItem(stringResource(R.string.game_file_export), checked = false) { open = false; a.onExportGameFile(g) }
MenuItem(stringResource(R.string.game_link_copy), checked = false) { open = false; a.onCopyGameLink(g) }
edit?.let { run -> MenuItem(stringResource(R.string.game_edit_art), checked = false) { open = false; run() } }
}
}
}
@Composable
internal fun IconAction(icon: androidx.compose.ui.graphics.vector.ImageVector, label: String, id: String, danger: Boolean = false, enabled: Boolean = true, onClick: () -> Unit) {
val colors = MaterialTheme.colorScheme
val shape = if (LocalPillButtons.current) CircleShape else Shape12
val pal = LocalPalette.current
val src = remember { MutableInteractionSource() }
val hot = rememberHot(src) && enabled
val accent = if (danger) colors.error else pal.signal
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.paneItem(id).downToFirstTile().size(44.dp).clip(Shape12)
modifier = Modifier.paneItem(id).downToFirstTile().size(if (LocalPillButtons.current) 40.dp else 44.dp).clip(shape)
.background(if (hot) accent.copy(alpha = if (danger) 0.22f else 0.14f) else if (danger) Color.Black.copy(alpha = 0.34f) else Color.White.copy(alpha = 0.03f))
.glideBorder(hot, Shape12, accent, pal.line2)
.glideBorder(hot, shape, accent, pal.line2)
.alpha(if (enabled) 1f else 0.45f)
.hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, role = androidx.compose.ui.semantics.Role.Button, enabled = enabled, onClick = onClick)
.controllerConfirm(enabled = enabled, onClick = onClick)
@@ -628,14 +707,10 @@ private fun InstallButton(label: String, modifier: Modifier = Modifier, onInstal
}
}
@OptIn(ExperimentalLayoutApi::class)
@Composable
private fun AboutTab(developer: String, publisher: String, releaseDate: String, description: String, scores: GameScores?, stacked: Boolean) {
Column(verticalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth().tabPanel()) {
if (scores != null) Box(Modifier.readable()) { StoreGameFacts(developer, publisher, releaseDate, scores, scoresInHero = !stacked) }
else if (developer.isNotBlank() || publisher.isNotBlank() || releaseDate.isNotBlank()) {
val parts = listOf(developer, publisher, com.droiddeck.launcher.stores.GameFacts.releaseLabel(releaseDate).orEmpty()).filter { it.isNotBlank() }.distinct()
Text(parts.joinToString(" · "), fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.readable())
}
private fun AboutTab(developer: String, publisher: String, releaseDate: String, description: String, scores: GameScores?, stacked: Boolean, resources: @Composable () -> Unit) {
val aboutText: @Composable () -> Unit = {
if (description.isNotBlank()) {
val floor = LocalDetailFloor.current
val density = LocalDensity.current
@@ -644,12 +719,35 @@ private fun AboutTab(developer: String, publisher: String, releaseDate: String,
StoreAbout(description, room, Modifier.fillMaxWidth().then(fill))
}
}
if (stacked) Column(verticalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.fillMaxWidth().tabPanel()) {
val released = GameFacts.releaseLabel(releaseDate).orEmpty()
val credits = listOf(developer, publisher, released).filter { it.isNotBlank() }.distinct()
if (credits.isNotEmpty()) FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.readable()) {
credits.forEachIndexed { i, part ->
Text(
part, fontSize = 13.sp, fontWeight = if (i == 0 && part == developer) FontWeight.SemiBold else FontWeight.Normal,
color = if (i == 0 && part == developer) MaterialTheme.colorScheme.onBackground else MaterialTheme.colorScheme.onSurfaceVariant, maxLines = 1,
modifier = Modifier.clip(CircleShape).background(Color.White.copy(alpha = 0.07f)).border(1.dp, Color.White.copy(alpha = 0.12f), CircleShape).padding(horizontal = 12.dp, vertical = 6.dp),
)
}
}
aboutText()
resources()
} else Row(horizontalArrangement = Arrangement.spacedBy(12.dp), verticalAlignment = Alignment.Top, modifier = Modifier.fillMaxWidth()) {
if (description.isNotBlank()) Column(Modifier.weight(1.3f).tabPanel()) { aboutText() }
Column((if (description.isNotBlank()) Modifier.weight(1f) else Modifier.fillMaxWidth()).tabPanel(), verticalArrangement = Arrangement.spacedBy(4.dp)) {
Text(headingUppercase(stringResource(R.string.store_details)), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(start = 8.dp, bottom = 4.dp))
if (scores != null) StoreDetailRows(developer, publisher, releaseDate, scores) else StoreDetailRows(developer, publisher, releaseDate, GameScores(Lookup.None, Lookup.None))
Box(Modifier.padding(top = 8.dp)) { resources() }
}
}
}
private val AboutHeight = 260.dp
@Composable
internal fun Modifier.tabPanel(): Modifier {
if (LocalGlass.current != null) return glass(RoundedCornerShape(22.dp), 0.22f).padding(horizontal = 18.dp, vertical = 14.dp)
val shape = RoundedCornerShape(16.dp)
return clip(shape).background(MaterialTheme.colorScheme.surface).border(1.dp, LocalPalette.current.line, shape).padding(horizontal = 16.dp, vertical = 14.dp)
}
@@ -681,7 +779,7 @@ private fun StoreAbout(text: String, height: Dp, modifier: Modifier = Modifier)
Text(text, fontSize = 14.sp, lineHeight = 21.sp, color = colors.onSurfaceVariant, modifier = Modifier.verticalScroll(scroll).padding(horizontal = 4.dp, vertical = 6.dp))
if (scroll.value < scroll.maxValue) Box(
Modifier.align(Alignment.BottomCenter).fillMaxWidth().height(28.dp)
.background(Brush.verticalGradient(listOf(Color.Transparent, colors.surface))),
.background(Brush.verticalGradient(listOf(Color.Transparent, if (LocalGlass.current != null) colors.background.copy(alpha = 0.72f) else colors.surface))),
)
}
}
@@ -835,12 +933,12 @@ internal fun Modifier.readable(): Modifier {
}
@Composable
private fun FactRow(label: String, value: String) {
internal fun FactRow(label: String, value: String, labelWidth: androidx.compose.ui.unit.Dp = 150.dp) {
Row(
horizontalArrangement = Arrangement.spacedBy(16.dp),
modifier = Modifier.fillMaxWidth().readable().padding(horizontal = 8.dp, vertical = 7.dp),
) {
Text(label, fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.width(150.dp))
Text(label, fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.width(labelWidth))
Text(value, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onBackground, modifier = Modifier.weight(1f), maxLines = 2, overflow = TextOverflow.Ellipsis)
}
}
@@ -0,0 +1,277 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.BiasAlignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.geometry.isSpecified
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.ColorMatrix
import androidx.compose.ui.graphics.CompositingStrategy
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.Paint
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.clipRect
import androidx.compose.ui.graphics.drawscope.translate
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.LayoutCoordinates
import androidx.compose.ui.layout.boundsInRoot
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.imageLoader
import coil.compose.rememberAsyncImagePainter
import coil.request.ImageRequest
import coil.size.Precision
import kotlin.math.max
/** Buttons in a capsule render as pills; elsewhere they keep their rounded-rectangle shape. */
internal val LocalPillButtons = compositionLocalOf { false }
/**
* The page's blurred art, shared so frosted surfaces can draw the part of it behind them.
* Coordinates are read when drawing, so a surface and the backdrop always agree on where they are.
*/
internal class GlassBackdrop {
var painter: Painter? = null
var coords: LayoutCoordinates? = null
var light: Boolean = false
var ready by mutableStateOf(false)
fun offsetOf(surface: LayoutCoordinates?): Offset? {
val base = coords?.takeIf { it.isAttached } ?: return null
val at = surface?.takeIf { it.isAttached } ?: return null
return base.localPositionOf(at, Offset.Zero)
}
fun paint(scope: DrawScope, size: Size) {
val art = painter ?: return
scope.drawCover(art, size, if (light) LightAmbient else DarkAmbient)
}
/** Drawn inside a layer, so it fades what was painted before it toward the page's end. */
fun fadeBottom(scope: DrawScope, size: Size) {
val fade = minOf(size.height * 0.5f, with(scope) { 240.dp.toPx() })
if (size.height <= 0f) return
scope.drawRect(Brush.verticalGradient((1f - fade / size.height) to Color.Black, 1f to Color.Transparent), size = size, blendMode = BlendMode.DstIn)
}
}
internal val LocalGlass = compositionLocalOf<GlassBackdrop?> { null }
private val DarkAmbient = ColorFilter.colorMatrix(
ColorMatrix().apply {
setToSaturation(1.3f)
timesAssign(ColorMatrix(floatArrayOf(0.55f, 0f, 0f, 0f, 0f, 0f, 0.55f, 0f, 0f, 0f, 0f, 0f, 0.55f, 0f, 0f, 0f, 0f, 0f, 1f, 0f)))
},
)
private val LightAmbient = ColorFilter.colorMatrix(ColorMatrix().apply { setToSaturation(1.1f) })
private fun DrawScope.drawCover(painter: Painter, into: Size, filter: ColorFilter) {
val intrinsic = painter.intrinsicSize
if (!intrinsic.isSpecified) return
val iw = intrinsic.width
val ih = intrinsic.height
if (iw <= 0f || ih <= 0f || into.width <= 0f || into.height <= 0f) return
val scale = max(into.width / iw, into.height / ih)
val w = iw * scale
val h = ih * scale
clipRect(0f, 0f, into.width, into.height) {
translate((into.width - w) * AmbientBiasX, (into.height - h) * AmbientBiasY) {
with(painter) { draw(Size(w, h), colorFilter = filter) }
}
}
}
private const val AmbientBiasX = 0.6f
private const val AmbientBiasY = 0.05f
private fun ambientRequest(ctx: android.content.Context, model: Any?): ImageRequest? =
model?.let { ImageRequest.Builder(ctx).data(it).size(AmbientPixels, AmbientPixels).precision(Precision.EXACT).memoryCacheKey("wash:$it").build() }
private const val AmbientPixels = 6
/** How washed-out the art is: average brightness less its saturation, from a tiny decode, so pale art is dimmed while dark and vivid art are left alone. */
@Composable
private fun rememberArtBrightness(model: Any?): Float {
val ctx = LocalContext.current
val data = (model as? ImageRequest)?.data ?: model
val brightness by produceState(0.3f, data) {
if (data == null) return@produceState
val request = ImageRequest.Builder(ctx).data(data).size(SamplePixels, SamplePixels).precision(Precision.EXACT)
.allowHardware(false).memoryCacheKey("lum:$data").build()
val bitmap = (ctx.imageLoader.execute(request).drawable as? android.graphics.drawable.BitmapDrawable)?.bitmap ?: return@produceState
var light = 0.0
var saturation = 0.0
for (y in 0 until bitmap.height) for (x in 0 until bitmap.width) {
val pixel = Color(bitmap.getPixel(x, y))
val top = maxOf(pixel.red, pixel.green, pixel.blue)
light += pixel.luminance()
if (top > 0f) saturation += (top - minOf(pixel.red, pixel.green, pixel.blue)) / top
}
val count = bitmap.width * bitmap.height
value = ((light - SaturationWeight * saturation) / count).toFloat().coerceAtLeast(0f)
}
return brightness
}
private const val SamplePixels = 8
private const val SaturationWeight = 0.6
/**
* A page whose game art fills the background: a blurred wash behind everything and the sharp art
* across the top, fading into the page. Surfaces inside draw frosted glass over the wash.
*/
@Composable
internal fun GameBackdrop(
art: Any?, ambient: Any?, fallbackHue: Float,
fadeTop: Boolean,
modifier: Modifier = Modifier,
onArtPlaced: (androidx.compose.ui.geometry.Rect?) -> Unit = {},
content: @Composable () -> Unit,
) {
val ctx = LocalContext.current
val colors = MaterialTheme.colorScheme
val glass = remember { GlassBackdrop() }
glass.light = colors.background.luminance() > 0.5f
val wash = rememberAsyncImagePainter(remember(ambient) { ambientRequest(ctx, ambient ?: art) })
glass.painter = if (ambient != null || art != null) wash else null
val edge = 24.dp
val artMin = with(LocalDensity.current) { ArtMin.toPx() }
Box(
modifier.fillMaxWidth().onGloballyPositioned {
glass.coords = it
if (!glass.ready) glass.ready = true
if (art == null) {
val at = it.boundsInRoot()
onArtPlaced(Rect(at.left, at.top, at.right, at.top + artMin))
}
},
) {
DisposableEffect(art == null) { onDispose { if (art == null) onArtPlaced(null) } }
Box(
Modifier.matchParentSize()
.graphicsLayer { compositingStrategy = CompositingStrategy.Offscreen }
.drawWithContent {
if (glass.painter == null) drawRect(artBrush(fallbackHue), alpha = 0.55f) else glass.paint(this, size)
drawRect(colors.background.copy(alpha = if (glass.light) 0.7f else 0.58f))
if (fadeTop) drawRect(Brush.verticalGradient(0f to Color.Transparent, (edge.toPx() / size.height).coerceAtMost(0.5f) to Color.Black), blendMode = BlendMode.DstIn)
glass.fadeBottom(this, size)
},
)
if (art != null) ArtLayer(art, ambient ?: art, fadeTop, onArtPlaced)
CompositionLocalProvider(LocalGlass provides glass) { content() }
}
}
@Composable
private fun ArtLayer(model: Any?, sample: Any?, fadeTop: Boolean, onPlaced: (androidx.compose.ui.geometry.Rect?) -> Unit) {
val colors = MaterialTheme.colorScheme
val light = colors.background.luminance() > 0.5f
val pale = ((rememberArtBrightness(sample) - 0.28f) / 0.5f).coerceIn(0f, 1f)
val dim = if (light) 1f else 1f - 0.4f * pale
val artFilter = remember(dim) { ColorFilter.colorMatrix(ColorMatrix(floatArrayOf(dim, 0f, 0f, 0f, 0f, 0f, dim, 0f, 0f, 0f, 0f, 0f, dim, 0f, 0f, 0f, 0f, 0f, 1f, 0f))) }
BoxWithConstraints(Modifier.fillMaxWidth()) {
val height = (maxWidth * 0.4f).coerceIn(ArtMin, ArtMax)
DisposableEffect(Unit) { onDispose { onPlaced(null) } }
Box(
Modifier.fillMaxWidth().height(height)
.onGloballyPositioned { onPlaced(it.boundsInRoot()) }
.graphicsLayer { compositingStrategy = CompositingStrategy.Offscreen }
.drawWithContent {
drawContent()
drawRect(Brush.horizontalGradient(0.08f to Color.Transparent, 0.55f to Color.Black), blendMode = BlendMode.DstIn)
drawRect(Brush.verticalGradient(0.55f to Color.Black, 1f to Color.Transparent), blendMode = BlendMode.DstIn)
if (fadeTop) drawRect(Brush.verticalGradient(0f to Color.Transparent, (24.dp.toPx() / size.height) to Color.Black), blendMode = BlendMode.DstIn)
},
) {
AsyncImage(
model = model, contentDescription = null, contentScale = ContentScale.Crop,
alignment = BiasAlignment(0.45f, -0.35f),
colorFilter = artFilter,
modifier = Modifier.matchParentSize(),
)
Box(
Modifier.matchParentSize().drawBehind {
drawRect(colors.background.copy(alpha = if (light) 0.1f else 0.12f + 0.3f * pale))
drawRect(
Brush.radialGradient(
0f to colors.background.copy(alpha = if (light) 0.5f else 0.66f),
0.55f to colors.background.copy(alpha = if (light) 0.2f else 0.3f),
1f to Color.Transparent,
center = Offset(size.width * 0.22f, size.height * 0.55f), radius = size.width * 0.55f,
),
)
},
)
}
}
}
private val ArtMin = 220.dp
private val ArtMax = 340.dp
/** A frosted surface: the page's wash behind it, a dark tint, and a thin rim. Plain surface when there is no backdrop. */
@Composable
internal fun Modifier.glass(shape: Shape, lift: Float = 0f): Modifier {
val g = LocalGlass.current
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
if (g == null) return clip(shape).background(colors.surface).border(1.dp, pal.line2, shape)
val light = g.light
val tint = colors.background.copy(alpha = if (light) 0.62f else 0.46f + lift)
val rim = if (light) Color.Black.copy(alpha = 0.1f) else Color.White.copy(alpha = 0.12f + lift)
val self = remember { arrayOfNulls<LayoutCoordinates>(1) }
var placed by remember { mutableIntStateOf(0) }
val last = remember { longArrayOf(Long.MIN_VALUE) }
return clip(shape)
.onGloballyPositioned { c ->
self[0] = c
val at = g.offsetOf(c) ?: return@onGloballyPositioned
val key = (at.x.toLong() shl 32) xor (at.y.toLong() and 0xffffffffL)
if (key != last[0]) { last[0] = key; placed++ }
}
.drawBehind {
val base = g.coords?.size
if (placed >= 0 && g.ready && base != null) g.offsetOf(self[0])?.let { at ->
val wash = Size(base.width.toFloat(), base.height.toFloat())
drawIntoCanvas { canvas ->
canvas.saveLayer(Rect(0f, 0f, size.width, size.height), Paint())
translate(-at.x, -at.y) { g.paint(this, wash); g.fadeBottom(this, wash) }
canvas.restore()
}
}
drawRect(tint)
}
.border(1.dp, rim, shape)
}
@@ -18,6 +18,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.OpenInNew
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
@@ -70,7 +71,8 @@ private fun ResourceLink(link: GameResource) {
val pal = LocalPalette.current
val source = remember { MutableInteractionSource() }
val hot = rememberHot(source)
val shape = RoundedCornerShape(8.dp)
val glass = LocalGlass.current != null
val shape = if (glass) RoundedCornerShape(99.dp) else RoundedCornerShape(8.dp)
val label = stringResource(link.label)
val description = listOfNotNull(label, link.detail?.let { stringResource(it) }, stringResource(R.string.game_resources_browser)).joinToString(". ")
val open = { openUrl(ctx, link.url) }
@@ -78,13 +80,13 @@ private fun ResourceLink(link: GameResource) {
Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(5.dp),
modifier = Modifier.paneItem("resource:${link.label}").heightIn(min = 44.dp).clip(shape)
.background(if (hot) pal.signal.copy(alpha = 0.08f) else Color.Transparent)
.glideBorder(hot, shape, pal.signal, restColor = Color.Transparent)
.background(if (hot) pal.signal.copy(alpha = 0.14f) else if (glass) Color.White.copy(alpha = 0.07f) else Color.Transparent)
.glideBorder(hot, shape, pal.signal, restColor = if (glass) Color.White.copy(alpha = 0.12f) else Color.Transparent)
.semantics { contentDescription = description }
.hoverable(source).clickable(interactionSource = source, indication = LocalIndication.current, role = Role.Button, onClick = open)
.controllerConfirm(onClick = open).padding(horizontal = 8.dp),
.controllerConfirm(onClick = open).padding(horizontal = if (glass) 14.dp else 8.dp),
) {
Text(label, fontSize = 12.sp, fontWeight = FontWeight.Medium, color = tint, maxLines = 1)
Text(label, fontSize = if (glass) 13.sp else 12.sp, fontWeight = FontWeight.Medium, color = if (glass && !hot) MaterialTheme.colorScheme.onBackground else tint, maxLines = 1)
Icon(Icons.AutoMirrored.Filled.OpenInNew, contentDescription = null, tint = tint.copy(alpha = 0.65f), modifier = Modifier.size(11.dp))
}
}
@@ -6,6 +6,8 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.background
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Build
import androidx.compose.material3.Text
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.*
@@ -88,7 +90,10 @@ internal fun GogMaintenanceActions(game: InstalledStoreGame) {
SecondaryButton(stringResource(R.string.gog_update, check.version.ifBlank { game.sidecar.title }), enabled = !busy, modifier = Modifier.testTag("gog-update")) { prepare(GogOperation.UPDATE) }
}
androidx.compose.foundation.layout.Box {
SecondaryButton(stringResource(if (busy) R.string.common_checking else R.string.gog_maintenance), enabled = !busy && !active, modifier = Modifier.testTag("gog-maintenance")) { menu = !menu }
val manageLabel = stringResource(if (busy) R.string.common_checking else R.string.gog_maintenance)
if (LocalPillButtons.current) androidx.compose.foundation.layout.Box(Modifier.testTag("gog-maintenance")) {
IconAction(Icons.Outlined.Build, manageLabel, "game:gog-maintenance", enabled = !busy && !active) { menu = !menu }
} else SecondaryButton(manageLabel, enabled = !busy && !active, modifier = Modifier.testTag("gog-maintenance")) { menu = !menu }
AnchoredMenu(menu, { menu = false }, title = stringResource(R.string.gog_maintenance), compact = true) { first ->
MenuItem(stringResource(R.string.common_update), checked = false) { prepare(GogOperation.UPDATE) }
MenuItem(stringResource(R.string.gog_check), checked = false, focusRequester = first) { menu = false; GogMaintenance.check(ctx, game, true) }
@@ -310,6 +310,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
gridScrolled = { grid.firstVisibleItemIndex > 0 || grid.firstVisibleItemScrollOffset > 0 },
onDetailFocus = { detailFocused = it },
modifier = modifier.padding(horizontal = if (narrow) 14.dp else 22.dp).padding(top = if (narrow) 10.dp else 14.dp),
bleedHorizontal = if (narrow) 14.dp else 22.dp, bleedTop = if (narrow) 10.dp else 14.dp,
wrap = { key, content -> StoreTheme(GameRef.parse(key).let { r -> r.store ?: r.game(s.steamGames)?.source?.let { Store.byId(it) } }) { content() } },
grid = {
LibraryGrid(
@@ -210,7 +210,7 @@ internal fun TabStrip(
}
@Composable
private fun BumperKey(label: String, description: String, onClick: () -> Unit) {
internal fun BumperKey(label: String, description: String, onClick: () -> Unit) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val cap = RoundedCornerShape(7.dp)
@@ -177,6 +177,60 @@ internal fun StoreGameFacts(developer: String, publisher: String, releaseDate: S
}
}
/** The headline scores, small enough to sit inside the action capsule. */
@Composable
internal fun CapsuleScores(scores: GameScores, modifier: Modifier = Modifier) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(2.dp), modifier = modifier) {
Looked(scores.metacritic, exit = fadeOut()) { lookup ->
val found = (lookup as? Lookup.Found)?.value
CapsuleStat(stringResource(R.string.stores_fact_metacritic), found?.url, showLabel = false) {
if (found != null) MetacriticBadge(found.score, small = true) else Placeholder(28.dp)
}
}
Looked(scores.hltb, exit = fadeOut()) { lookup ->
val found = (lookup as? Lookup.Found)?.value
val lead = found?.let { hltbRuns(it).firstOrNull() }
CapsuleStat(lead?.second ?: stringResource(R.string.stores_hltb_main), found?.url) {
if (lead != null) Text(hltbTime(lead.first), fontSize = 17.sp, fontWeight = FontWeight.Bold, color = MaterialTheme.colorScheme.onBackground, maxLines = 1)
else Placeholder(40.dp)
}
}
}
}
@Composable
private fun CapsuleStat(label: String, link: String?, showLabel: Boolean = true, value: @Composable () -> Unit) {
val colors = MaterialTheme.colorScheme
val src = remember { MutableInteractionSource() }
val hot = link != null && rememberHot(src)
Row(
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(7.dp),
modifier = Modifier.then(linkSurface(label, link, src, hot, CapsuleStatShape)).padding(horizontal = 10.dp, vertical = 6.dp),
) {
value()
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(3.dp)) {
val tint = colors.onSurfaceVariant.copy(alpha = if (hot) 1f else 0.85f)
if (showLabel) Text(label.uppercase(), fontSize = 10.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.sp, color = tint, maxLines = 1)
if (link != null) Icon(Icons.AutoMirrored.Filled.OpenInNew, contentDescription = if (showLabel) null else label, tint = tint, modifier = Modifier.size(10.dp))
}
}
}
/** Credits and times as label and value rows, for the details panel. */
@Composable
internal fun StoreDetailRows(developer: String, publisher: String, releaseDate: String, scores: GameScores) {
val released = remember(releaseDate) { GameFacts.releaseLabel(releaseDate) }
val publishedBy = publisher.takeUnless { it.isBlank() || it.trim().equals(developer.trim(), ignoreCase = true) }
val credits = listOf(
stringResource(R.string.stores_fact_developer) to developer,
stringResource(R.string.stores_fact_publisher) to publishedBy.orEmpty(),
stringResource(R.string.stores_fact_released) to released.orEmpty(),
).filter { it.second.isNotBlank() }
val runs = ((scores.hltb as? Lookup.Found)?.value)?.let { hltbRuns(it) }.orEmpty()
credits.forEach { (label, value) -> FactRow(label, value, labelWidth = 96.dp) }
runs.forEach { (secs, what) -> FactRow(what, hltbTime(secs), labelWidth = 96.dp) }
}
@Composable
private fun LineLink(label: String, link: String, content: @Composable () -> Unit) {
val pal = LocalPalette.current
@@ -202,6 +256,7 @@ private fun <T> Looked(lookup: Lookup<T>, exit: ExitTransition, content: @Compos
}
private val StatShape = RoundedCornerShape(12.dp)
private val CapsuleStatShape = RoundedCornerShape(99.dp)
private val LinkShape = RoundedCornerShape(10.dp)
private val BadgeHeight = 32.dp
@@ -349,6 +349,7 @@ internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier
},
onDetailFocus = { detailFocused = it },
modifier = Modifier.fillMaxWidth().weight(1f).onSizeChanged { viewportH = with(density) { it.height.toDp() } },
bleedHorizontal = padH,
wrap = { key, content -> StoreTheme(Store.byId(key.substringBefore(':')) ?: store) { content() } },
grid = {
AnimatedContent(