mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 15:26:04 +00:00
fix(ui): the empty Steam page's ball bounces edge to edge, and the logo traces in around it on the slam (#3050)
This commit is contained in:
1 parent
101139ec99
commit
f43cc43d05
4 files changed
+69
-42
No files matched your search
@@ -15,6 +15,7 @@ private fun Launcher(tab: String, games: List<com.droiddeck.launcher.frontend.Li
|
||||
PreviewHost { FrontEndScreen(sampleState(games = games, navigate = tab, ready = ready), sampleActions) }
|
||||
|
||||
@DroidDeckPreviews @Composable private fun SteamTabPreview() = Launcher("steam")
|
||||
@DroidDeckPreviews @Composable private fun SteamEmptyPreview() = Launcher("steam", games = emptyList())
|
||||
@DroidDeckPreviews @Composable private fun LibraryPreview() = Launcher("games")
|
||||
@DroidDeckPreviews @Composable private fun LibraryEmptyPreview() = Launcher("games", games = emptyList())
|
||||
@DroidDeckPreviews @Composable private fun StoresPreview() = Launcher("stores")
|
||||
|
||||
@@ -33,7 +33,9 @@ import androidx.compose.ui.graphics.drawscope.translate
|
||||
import androidx.compose.ui.graphics.lerp
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.layout.onSizeChanged
|
||||
import androidx.compose.ui.layout.positionInRoot
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -47,21 +49,30 @@ import kotlin.math.sin
|
||||
|
||||
@Composable
|
||||
internal fun EmptyLibrary(avoid: Rect?, wall: (@Composable () -> Unit)? = null, fade: @Composable () -> Unit) {
|
||||
val clock = rememberMarkClock(avoid)
|
||||
Box(Modifier.fillMaxSize().onSizeChanged { clock.page = Size(it.width.toFloat(), it.height.toFloat()) }) {
|
||||
var origin by remember { mutableStateOf(Offset.Zero) }
|
||||
val clock = rememberMarkClock(avoid?.translate(-origin.x, -origin.y))
|
||||
Box(
|
||||
Modifier.fillMaxSize()
|
||||
.onGloballyPositioned { origin = it.positionInRoot() }
|
||||
.onSizeChanged { clock.page = Size(it.width.toFloat(), it.height.toFloat()) },
|
||||
) {
|
||||
if (wall != null) wall() else EmptyWall(clock)
|
||||
fade()
|
||||
Mark(clock)
|
||||
}
|
||||
}
|
||||
|
||||
private const val TRACE_MS = 1250f
|
||||
private const val FILL_FROM = 450f
|
||||
private const val POP_FROM = 900f
|
||||
private const val IMPACT = 2200f
|
||||
private const val RIPPLE_MS = 1250f
|
||||
private const val HIT_MS = 900f
|
||||
private const val END = 3600f
|
||||
private const val REVEAL_MS = 2300f
|
||||
private const val TRACE_DRAW_MS = 900f
|
||||
private const val TRACE_FADE_MS = 500f
|
||||
private const val REVEAL_FILL_FROM = 600f
|
||||
private const val REVEAL_FILL_MS = 450f
|
||||
private const val REVEAL_FADE_FROM = 1700f
|
||||
private const val POKE = 880f
|
||||
private const val DRIFT_MS = 75_000f
|
||||
|
||||
@@ -82,8 +93,7 @@ private fun rememberMarkClock(avoid: Rect?): MarkClock {
|
||||
val haptics = LocalHapticFeedback.current
|
||||
val keepOff by rememberUpdatedState(avoid)
|
||||
val speed = with(LocalDensity.current) { 64.dp.toPx() }
|
||||
val inset = with(LocalDensity.current) { 10.dp.toPx() }
|
||||
val clearance = with(LocalDensity.current) { 16.dp.toPx() }
|
||||
val clearance = with(LocalDensity.current) { 4.dp.toPx() }
|
||||
LaunchedEffect(clock) {
|
||||
var last = -1L
|
||||
var vx = speed * 0.8f
|
||||
@@ -109,16 +119,28 @@ private fun rememberMarkClock(avoid: Rect?): MarkClock {
|
||||
|
||||
var x = clock.at.x + vx * dt / 1000f
|
||||
var y = clock.at.y + vy * dt / 1000f
|
||||
val hw = f.halfWidth
|
||||
val hh = f.halfHeight
|
||||
if (x - hw < inset) { x = inset + hw; vx = abs(vx) }
|
||||
if (x + hw > clock.page.width - inset) { x = clock.page.width - inset - hw; vx = -abs(vx) }
|
||||
if (y - hh < inset) { y = inset + hh; vy = abs(vy) }
|
||||
if (y + hh > clock.page.height - inset) { y = clock.page.height - inset - hh; vy = -abs(vy) }
|
||||
val hw = f.ball
|
||||
val hh = f.ball
|
||||
if (x - hw < 0f) { x = hw; vx = abs(vx) }
|
||||
if (x + hw > clock.page.width) { x = clock.page.width - hw; vx = -abs(vx) }
|
||||
if (y - hh < 0f) { y = hh; vy = abs(vy) }
|
||||
if (y + hh > clock.page.height) { y = clock.page.height - hh; vy = -abs(vy) }
|
||||
keepOff?.inflate(clearance)?.let { r ->
|
||||
if (x + hw > r.left && x - hw < r.right && y + hh > r.top && y - hh < r.bottom) {
|
||||
val outX = if (x < r.center.x) r.left - (x + hw) else r.right - (x - hw)
|
||||
val outY = if (y < r.center.y) r.top - (y + hh) else r.bottom - (y - hh)
|
||||
val nearX = x.coerceIn(r.left, r.right)
|
||||
val nearY = y.coerceIn(r.top, r.bottom)
|
||||
val gapX = x - nearX
|
||||
val gapY = y - nearY
|
||||
val gap = hypot(gapX, gapY)
|
||||
if (gap in 0.0001f..f.ball) {
|
||||
val nx = gapX / gap
|
||||
val ny = gapY / gap
|
||||
x = nearX + nx * f.ball
|
||||
y = nearY + ny * f.ball
|
||||
val into = vx * nx + vy * ny
|
||||
if (into < 0f) { vx -= 2f * into * nx; vy -= 2f * into * ny }
|
||||
} else if (gap <= 0.0001f) {
|
||||
val outX = if (x < r.center.x) r.left - f.ball - x else r.right + f.ball - x
|
||||
val outY = if (y < r.center.y) r.top - f.ball - y else r.bottom + f.ball - y
|
||||
if (abs(outX) < abs(outY)) { x += outX; vx = if (outX < 0) -abs(vx) else abs(vx) }
|
||||
else { y += outY; vy = if (outY < 0) -abs(vy) else abs(vy) }
|
||||
}
|
||||
@@ -294,30 +316,33 @@ private fun Mark(clock: MarkClock) {
|
||||
} else 0f
|
||||
|
||||
translate(0f, shake) {
|
||||
val fill = Out.transform(clamp01((intro - FILL_FROM) / 450f))
|
||||
if (fill > 0f) {
|
||||
val lift = 8f * k * (1f - fill)
|
||||
val edge = 5f * f.s
|
||||
LogoShape.left(left, 0f) { x, y -> f.px(x, y) + Offset(0f, lift + edge) }
|
||||
LogoShape.right(right) { x, y -> f.px(x, y) + Offset(0f, lift + edge) }
|
||||
drawPath(left, slabEdge.copy(alpha = fill))
|
||||
drawPath(right, slabEdge.copy(alpha = fill))
|
||||
LogoShape.left(left, 0f) { x, y -> f.px(x, y) + Offset(0f, lift) }
|
||||
LogoShape.right(right) { x, y -> f.px(x, y) + Offset(0f, lift) }
|
||||
drawPath(left, ink.copy(alpha = fill))
|
||||
drawPath(right, ink.copy(alpha = fill))
|
||||
}
|
||||
|
||||
if (intro < TRACE_MS) {
|
||||
val drawn = TraceEase.transform(clamp01(intro / 775f))
|
||||
val alpha = if (intro < 775f) 1f else 1f - (intro - 775f) / 475f
|
||||
LogoShape.left(left, 0f, f::px)
|
||||
LogoShape.right(right, f::px)
|
||||
for (half in listOf(left, right)) {
|
||||
measure.setPath(half, false)
|
||||
piece.reset()
|
||||
measure.getSegment(0f, measure.length * drawn, piece, true)
|
||||
drawPath(piece, pal.signal.copy(alpha = alpha), style = Stroke(2f * f.s))
|
||||
val since = t - IMPACT
|
||||
if (since in 0f..REVEAL_MS) {
|
||||
val fade = 1f - clamp01((since - REVEAL_FADE_FROM) / (REVEAL_MS - REVEAL_FADE_FROM))
|
||||
val fill = Out.transform(clamp01((since - REVEAL_FILL_FROM) / REVEAL_FILL_MS)) * fade
|
||||
if (fill > 0f) {
|
||||
val lift = 8f * k * (1f - fill / fade)
|
||||
val edge = 5f * f.s
|
||||
LogoShape.left(left, 0f) { x, y -> f.px(x, y) + Offset(0f, lift + edge) }
|
||||
LogoShape.right(right) { x, y -> f.px(x, y) + Offset(0f, lift + edge) }
|
||||
drawPath(left, slabEdge.copy(alpha = fill))
|
||||
drawPath(right, slabEdge.copy(alpha = fill))
|
||||
LogoShape.left(left, 0f) { x, y -> f.px(x, y) + Offset(0f, lift) }
|
||||
LogoShape.right(right) { x, y -> f.px(x, y) + Offset(0f, lift) }
|
||||
drawPath(left, ink.copy(alpha = fill))
|
||||
drawPath(right, ink.copy(alpha = fill))
|
||||
}
|
||||
val drawn = TraceEase.transform(clamp01(since / TRACE_DRAW_MS))
|
||||
val alpha = (if (since < TRACE_DRAW_MS) 1f else 1f - (since - TRACE_DRAW_MS) / TRACE_FADE_MS).coerceIn(0f, 1f) * fade
|
||||
if (alpha > 0f) {
|
||||
LogoShape.left(left, 0f, f::px)
|
||||
LogoShape.right(right, f::px)
|
||||
for (half in listOf(left, right)) {
|
||||
measure.setPath(half, false)
|
||||
piece.reset()
|
||||
measure.getSegment(0f, measure.length * drawn, piece, true)
|
||||
drawPath(piece, pal.signal.copy(alpha = alpha), style = Stroke(3f * f.s))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -189,6 +189,7 @@ internal fun LiftHero(
|
||||
onOpenChange: (Boolean) -> Unit = {},
|
||||
start: Dp = 44.dp,
|
||||
bottom: Dp = 44.dp,
|
||||
onTextBounds: (Rect) -> Unit = {},
|
||||
drop: DropSheetState? = null,
|
||||
overlay: @Composable BoxWithConstraintsScope.(lifted: () -> Float) -> Unit = {},
|
||||
) {
|
||||
@@ -573,7 +574,7 @@ internal fun LiftHero(
|
||||
}
|
||||
}
|
||||
|
||||
Column(Modifier.align(Alignment.BottomStart).padding(start = start, bottom = bottom, end = 20.dp)) {
|
||||
Column(Modifier.align(Alignment.BottomStart).padding(start = start, bottom = bottom, end = 20.dp).onGloballyPositioned { onTextBounds(it.boundsInRoot()) }) {
|
||||
Box(Modifier.graphicsLayer { alpha = 1f - wallSink() }) { words() }
|
||||
Spacer(Modifier.height(18.dp))
|
||||
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
|
||||
@@ -140,6 +140,7 @@ internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier)
|
||||
onOpen = a.onSteamSettings, onPrimary = a.onPlay,
|
||||
modifier = modifier.clipToBounds(),
|
||||
start = if (narrow) 20.dp else 44.dp, bottom = 44.dp,
|
||||
onTextBounds = { words = it },
|
||||
background = {
|
||||
when {
|
||||
games.isEmpty() -> EmptyLibrary(
|
||||
@@ -160,13 +161,12 @@ internal fun SteamHome(s: FrontEndState, a: FrontEndActions, modifier: Modifier)
|
||||
IntegrationSuggestion(s.integration, { a.onSteamIntegration(null) }, a.onDismissIntegration)
|
||||
}
|
||||
if (narrow) Column(
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.onPlaced { words = it.boundsInParent() },
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
Wordmark(30.dp)
|
||||
runtimeStatus()
|
||||
} else Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
modifier = Modifier.onPlaced { words = it.boundsInParent() },
|
||||
) {
|
||||
Wordmark(if (narrow) 30.dp else 40.dp)
|
||||
runtimeStatus()
|
||||
|
||||
Reference in new issue
Block a user