diff --git a/app/src/main/java/com/droiddeck/launcher/ui/AddAppDialog.kt b/app/src/main/java/com/droiddeck/launcher/ui/AddAppDialog.kt index 4212dc5769..9ce92870dc 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/AddAppDialog.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/AddAppDialog.kt @@ -46,6 +46,7 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Check import androidx.compose.material.icons.outlined.Apps import androidx.compose.material.icons.outlined.Terminal import androidx.compose.material3.Icon @@ -489,10 +490,17 @@ private fun SuggestedIcon(url: String, selected: Boolean, onClick: () -> Unit) { Box( contentAlignment = Alignment.Center, modifier = Modifier.size(44.dp).graphicsLayer { scaleX = scale; scaleY = scale }.clip(Shape12).background(colors.surface) - .glideBorder(hot || selected, Shape12, pal.signal, pal.line2) + .glideBorder(hot, Shape12, pal.signal, pal.line2) .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, onClick = onClick) .controllerConfirm(onClick = onClick), - ) { AsyncImage(model = ImageRequest.Builder(LocalContext.current).data(url).crossfade(true).build(), contentDescription = stringResource(R.string.add_app_icon), contentScale = ContentScale.Fit, modifier = Modifier.size(34.dp)) } + ) { + AsyncImage(model = ImageRequest.Builder(LocalContext.current).data(url).crossfade(true).build(), contentDescription = stringResource(R.string.add_app_icon), contentScale = ContentScale.Fit, modifier = Modifier.size(34.dp)) + // The chosen one is ticked; the ring stays with focus. + if (selected) Box( + contentAlignment = Alignment.Center, + modifier = Modifier.align(Alignment.TopEnd).padding(2.dp).size(14.dp).clip(androidx.compose.foundation.shape.CircleShape).background(pal.signal), + ) { Icon(Icons.Filled.Check, contentDescription = null, tint = pal.onSignal, modifier = Modifier.size(10.dp)) } + } } /** The chosen file, or none yet, laid out like the app's text fields, with the button that picks it. */ diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FocusGlide.kt b/app/src/main/java/com/droiddeck/launcher/ui/FocusGlide.kt index 8949c082d8..90e27aede0 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FocusGlide.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FocusGlide.kt @@ -44,6 +44,8 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collectLatest import kotlinx.coroutines.launch import kotlin.math.abs +import kotlin.math.hypot +import kotlinx.coroutines.coroutineScope // One focus ring for a whole screen that slides from control to control. When focus moves, the // edge on the side it is heading springs ahead and the trailing edge catches up a beat later, so @@ -84,6 +86,20 @@ internal class FocusGlide(val view: View) { internal val LocalFocusGlide = staticCompositionLocalOf { null } +/** Floods on screen (a launch, a stop, the return from one): every ring keeps out of the way of them. */ +internal object RingVeil { + var count by mutableIntStateOf(0) +} + +/** Keeps the focus ring off while this is in the composition. */ +@Composable +internal fun VeilRing() { + DisposableEffect(Unit) { + RingVeil.count++ + onDispose { RingVeil.count-- } + } +} + private fun cornerOf(shape: Shape, size: Size, dir: LayoutDirection, density: Density): Float = when (val o = shape.createOutline(size, dir, density)) { is Outline.Rounded -> o.roundRect.topLeftCornerRadius.x @@ -131,6 +147,12 @@ private fun follow(): AnimationSpec = Motion.sp(1f, 2400f) /** How long after a focus move the ring keeps its stretchy springs and keeps checking where it is. */ private const val SETTLE_MS = 450L +/** Moves closer together than this are a held direction: the ring runs along as one, no stretch. */ +private const val REPEAT_MS = 180L + +/** A move further than this goes as a droplet: pinched to a drop, carried across, opened onto the control. */ +private val FAR = 360.dp + /** * Hosts the sliding focus ring for everything inside it. The ring is drawn over [content], in the * host's space, so put the host inside anything that moves as a whole (a sheet that slides in). @@ -145,7 +167,8 @@ internal fun FocusGlideHost(modifier: Modifier = Modifier, content: @Composable val corner = remember { Animatable(0f) } val alpha = remember { Animatable(0f) } val scope = rememberCoroutineScope() - val jobs = remember { arrayOfNulls(5) } + // An edge each, the corner, and a droplet carrying all of them. + val jobs = remember { arrayOfNulls(6) } val cur = glide.current var lastColor by remember { mutableStateOf(Color.Transparent) } if (cur != null) lastColor = cur.color @@ -158,11 +181,43 @@ internal fun FocusGlideHost(modifier: Modifier = Modifier, content: @Composable var movedAt = 0L var dirSpecs: List> = List(4) { follow() } var delays = LongArray(4) + var lastMove = 0L fun go(i: Int, v: Float, spec: AnimationSpec, wait: Long) { + jobs[5]?.cancel() + // Picks up the speed it is going at: restarting from rest on every step of a held + // direction is what made it stutter. + val speed = edges[i].velocity jobs[i]?.cancel() jobs[i] = scope.launch { if (wait > 0) delay(Motion.ms(wait.toInt()).toLong()) - edges[i].animateTo(v, spec) + edges[i].animateTo(v, spec, initialVelocity = if (wait > 0) 0f else speed) + } + } + /** Pinch into a drop where it is, carry it over leading edge first, open it onto [b]. */ + fun droplet(s: GlideSource, b: Rect, leadIdx: Int) { + jobs.forEach { it?.cancel() } + val size = s.coords?.size?.let { Size(it.width.toFloat(), it.height.toFloat()) } ?: b.size + val endCorner = cornerOf(s.shape, size, dir, density) + jobs[5] = scope.launch { + val r = with(density) { 7.dp.toPx() } + fun dot(c: Offset) = listOf(c.x - r, c.y - r, c.x + r, c.y + r) + val here = Offset((edges[0].value + edges[2].value) / 2f, (edges[1].value + edges[3].value) / 2f) + coroutineScope { + launch { corner.animateTo(r, Motion.tw(130)) } + dot(here).forEachIndexed { i, v -> launch { edges[i].animateTo(v, Motion.tw(130)) } } + } + // Leading edge a touch quicker, so the drop pulls out a little on the way without + // turning into a streak (the box can only stretch square to the screen). + val trailIdx = (leadIdx + 2) % 4 + coroutineScope { + dot(b.center).forEachIndexed { i, v -> + launch { edges[i].animateTo(v, when (i) { leadIdx -> Motion.sp(0.85f, 360f); trailIdx -> Motion.sp(0.85f, 290f); else -> Motion.sp(0.85f, 320f) }) } + } + } + coroutineScope { + launch { corner.animateTo(endCorner, Motion.sp(0.8f, 500f)) } + listOf(b.left, b.top, b.right, b.bottom).forEachIndexed { i, v -> launch { edges[i].animateTo(v, Motion.sp(0.62f, 700f)) } } + } } } fun cornerTo(s: GlideSource, b: Rect, snap: Boolean) { @@ -171,7 +226,7 @@ internal fun FocusGlideHost(modifier: Modifier = Modifier, content: @Composable jobs[4]?.cancel() jobs[4] = scope.launch { if (snap) corner.snapTo(r) else corner.animateTo(r, Motion.sp(0.8f, 500f)) } } - snapshotFlow { Triple(glide.current, glide.moves, glide.hidden) }.collectLatest { (src, _, hidden) -> + snapshotFlow { Triple(glide.current, glide.moves, glide.hidden || RingVeil.count > 0) }.collectLatest { (src, _, hidden) -> if (hidden) { jobs.forEach { it?.cancel() } alpha.snapTo(0f) @@ -194,6 +249,7 @@ internal fun FocusGlideHost(modifier: Modifier = Modifier, content: @Composable if (b == null) { if (first) scope.launch { alpha.animateTo(0f, Motion.tw(140)) } } else if (first) { + var dropped = false val prev = shown val wasShowing = prev != null && alpha.targetValue > 0f shown = src @@ -215,15 +271,24 @@ internal fun FocusGlideHost(modifier: Modifier = Modifier, content: @Composable val horizontal = abs(dx) >= abs(dy) val leadIdx = if (horizontal) (if (dx >= 0) 2 else 0) else (if (dy >= 0) 3 else 1) val trailIdx = (leadIdx + 2) % 4 - dirSpecs = List(4) { i -> when (i) { leadIdx -> lead(); trailIdx -> trail(); else -> Motion.sp(0.7f, 520f) } } - delays = LongArray(4) { i -> if (i == trailIdx) 30L else 0L } - cornerTo(src, b, snap = false) + val now = System.nanoTime() + val held = (now - lastMove) / 1_000_000 < REPEAT_MS + lastMove = now scope.launch { alpha.animateTo(1f, Motion.tw(120)) } + dropped = !held && hypot(dx, dy) > with(density) { FAR.toPx() } + if (dropped) droplet(src, b, leadIdx) + else { + // A held direction runs along as one piece; a single press stretches. + dirSpecs = if (held) List(4) { Motion.sp(0.9f, 900f) } + else List(4) { i -> when (i) { leadIdx -> lead(); trailIdx -> trail(); else -> Motion.sp(0.7f, 520f) } } + delays = LongArray(4) { i -> if (i == trailIdx && !held) 30L else 0L } + cornerTo(src, b, snap = false) + } } movedAt = System.nanoTime() - listOf(b.left, b.top, b.right, b.bottom).forEachIndexed { i, v -> go(i, v, dirSpecs[i], delays[i]) } + if (!dropped) listOf(b.left, b.top, b.right, b.bottom).forEachIndexed { i, v -> go(i, v, dirSpecs[i], delays[i]) } last = b - } else if (b != last) { + } else if (b != last && jobs[5]?.isActive != true) { // It moved under the ring: keep the stretch while the move is fresh, else follow. val fresh = (System.nanoTime() - movedAt) / 1_000_000 < SETTLE_MS listOf(b.left, b.top, b.right, b.bottom).forEachIndexed { i, v -> go(i, v, if (fresh) dirSpecs[i] else follow(), 0L) } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndGames.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndGames.kt index 6486e62941..9a46fb2a6b 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndGames.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndGames.kt @@ -226,7 +226,7 @@ private fun GameRow(g: Library.SteamGame, selected: Boolean, onSelect: () -> Uni modifier = Modifier.fillMaxWidth().paneItem("game:${g.appId}") .clip(Shape12) .background(if (selected) pal.signal.copy(alpha = 0.14f) else if (hovered) Color.White.copy(alpha = 0.05f) else Color.Transparent) - .glideBorder(focused, Shape12, pal.signal, if (selected) pal.signal else Color.Transparent, restWidth = 2.dp) + .glideBorder(focused, Shape12, pal.signal) .hoverable(src).clickable(interactionSource = src, indication = LocalIndication.current, onClick = onSelect) .controllerConfirm(onClick = onLaunch) .padding(horizontal = 10.dp, vertical = 6.dp), diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt index 234b7dde4e..80f5794152 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -419,13 +419,14 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com // A tile or button that opens a page goes away with the page it was on, and focus with it; // the pad then had nothing to move from (a press landed back on the rail's first item). So // once the new page is in, a controller lands on its main button. - // Closing a page: it stays on screen while it leaves (and holds focus there), so hand focus - // back now to the control it was opened from, and the ring folds back onto that. + // Backing out of a page: it stays on screen while it leaves (and holds focus there), so hand + // focus back now to the control it was opened from. Not when the page closed because + // another rail item was picked: focus is on the rail then, and stays there. var openPage by remember { mutableStateOf(null) } LaunchedEffect(s.pageKey) { val closed = openPage != null && s.pageKey == null openPage = s.pageKey - if (!closed || processSettingsPageVisible || inputModeManager.inputMode != InputMode.Keyboard) return@LaunchedEffect + if (!closed || frontFocus.focusedRail != null || processSettingsPageVisible || inputModeManager.inputMode != InputMode.Keyboard) return@LaunchedEffect withFrameNanos { } runCatching { frontFocus.paneEntry().requestFocus() } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/GpuDriversPanel.kt b/app/src/main/java/com/droiddeck/launcher/ui/GpuDriversPanel.kt index f21f63bfd1..f3f9dd6310 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/GpuDriversPanel.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/GpuDriversPanel.kt @@ -244,12 +244,13 @@ private fun ModeCard(icon: ImageVector, title: String, hint: String, selected: B val pal = LocalPalette.current val src = remember { MutableInteractionSource() } val hot = rememberHot(src) - val fill = if (hot) pal.signal.copy(alpha = 0.14f) else if (selected) pal.signal.copy(alpha = 0.08f) else Color.Transparent + // Selection is the radio; the ring is only ever focus. + val fill = if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp), modifier = modifier.paneItem("gpu-mode:$title").heightIn(min = 56.dp) .clip(Shape14).background(colors.surface).background(fill) - .border(if (hot) 2.dp else 1.dp, if (hot || selected) pal.signal else pal.line, Shape14) + .glideBorder(hot, Shape14, pal.signal, pal.line) .hoverable(src).clickable(interactionSource = src, indication = null, role = Role.RadioButton, onClick = onClick) .controllerConfirm(onClick = onClick) .padding(horizontal = 14.dp, vertical = 10.dp), @@ -270,12 +271,12 @@ private fun PairLine(p: PairRow, busy: Boolean, percent: Int, enabled: Boolean, val src = remember { MutableInteractionSource() } val hot = rememberHot(src) val usable = enabled && p.complete && !p.active - val fill = if (hot) pal.signal.copy(alpha = 0.14f) else if (p.active) pal.signal.copy(alpha = 0.08f) else Color.Transparent + val fill = if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.fillMaxWidth().paneItem("pair:${p.key}").heightIn(min = 56.dp) .clip(Shape12).background(colors.surface).background(fill) - .border(if (hot) 2.dp else 1.dp, if (hot || p.active) pal.signal else pal.line, Shape12) + .glideBorder(hot, Shape12, pal.signal, pal.line) .hoverable(src).clickable(interactionSource = src, indication = null, enabled = usable, role = Role.RadioButton, onClick = onClick) .controllerConfirm(enabled = usable, onClick = onClick) .padding(horizontal = 14.dp, vertical = 8.dp), diff --git a/app/src/main/java/com/droiddeck/launcher/ui/LaunchFlood.kt b/app/src/main/java/com/droiddeck/launcher/ui/LaunchFlood.kt index 3a85362278..e416e9cdb0 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/LaunchFlood.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/LaunchFlood.kt @@ -139,6 +139,7 @@ internal fun LaunchFlood( val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val start = fromColors ?: (colors.primary to pal.primary2) + VeilRing() // Left, top, right, bottom: 0 on the button, 1 on the page's edge. Springs overshoot past the // edge, off the page, so the wobble is felt in the pull and never seen as a shrink. val edges = remember { List(4) { Animatable(0f) } } @@ -211,6 +212,7 @@ internal fun FloodReturn(flood: Color, to: Rect?, onProgress: (Float) -> Unit, o val colors = MaterialTheme.colorScheme val pal = LocalPalette.current val edges = remember { List(4) { Animatable(1f) } } + VeilRing() val fade = remember { Animatable(1f) } val landed by rememberUpdatedState(onLanded) val progress by rememberUpdatedState(onProgress) @@ -253,6 +255,7 @@ internal fun FloodReturn(flood: Color, to: Rect?, onProgress: (Float) -> Unit, o @Composable internal fun FloodGather(flood: Color, ball: Pair?, onLanded: () -> Unit) { val gather = remember { Animatable(0f) } + VeilRing() var started by remember { mutableStateOf(false) } val landed by rememberUpdatedState(onLanded) LaunchedEffect(ball != null) { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/UpdatesPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/UpdatesPage.kt index 22c3948df1..5adf3c6248 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/UpdatesPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/UpdatesPage.kt @@ -293,13 +293,14 @@ private fun ChannelCard( val pal = LocalPalette.current val src = remember { MutableInteractionSource() } val hot = rememberHot(src) - // Focus shows at once, as on the Components page: no ripple, no fade. - val fill = if (hot) pal.signal.copy(alpha = 0.14f) else if (selected) pal.signal.copy(alpha = 0.08f) else Color.Transparent + // Focus shows at once, as on the Components page: no ripple, no fade. Selection is the radio + // dot, never a ring of its own: the ring is only ever focus. + val fill = if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(14.dp), modifier = Modifier.fillMaxWidth().paneItem("channel:$title") - .clip(Shape14).background(colors.surface).background(fill).glideBorder(hot, Shape14, pal.signal, if (selected) pal.signal else pal.line) + .clip(Shape14).background(colors.surface).background(fill).glideBorder(hot, Shape14, pal.signal, pal.line) .alpha(if (enabled) 1f else 0.55f) .hoverable(src) .clickable(interactionSource = src, indication = null, enabled = enabled, role = Role.RadioButton, onClick = onClick) @@ -316,9 +317,16 @@ private fun ChannelCard( } Text(hint, fontSize = 12.5.sp, color = colors.onSurfaceVariant, maxLines = 1, overflow = TextOverflow.Ellipsis) } - Box(contentAlignment = Alignment.Center, modifier = Modifier.size(22.dp).clip(CircleShape).border(2.dp, if (selected) pal.signal else pal.line2, CircleShape)) { - if (selected) Box(Modifier.size(11.dp).clip(CircleShape).background(pal.signal)) - } + RadioDot(selected) + } +} + +/** The one mark of a chosen option: a filled dot in a ring, beside it. */ +@Composable +private fun RadioDot(selected: Boolean, size: androidx.compose.ui.unit.Dp = 22.dp) { + val pal = LocalPalette.current + Box(contentAlignment = Alignment.Center, modifier = Modifier.size(size).clip(CircleShape).border(2.dp, if (selected) pal.signal else pal.line2, CircleShape)) { + if (selected) Box(Modifier.size(size / 2).clip(CircleShape).background(pal.signal)) } } @@ -335,8 +343,8 @@ private fun TestRow(t: Release, selected: Boolean, onClick: () -> Unit) { modifier = Modifier.fillMaxWidth().paneItem("test:${t.pr}") .heightIn(min = 52.dp) .clip(Shape12) - .background(colors.surface).background(if (hot) pal.signal.copy(alpha = 0.14f) else if (selected) pal.signal.copy(alpha = 0.08f) else Color.Transparent) - .glideBorder(hot, Shape12, pal.signal, if (selected) pal.signal else pal.line) + .background(colors.surface).background(if (hot) pal.signal.copy(alpha = 0.14f) else Color.Transparent) + .glideBorder(hot, Shape12, pal.signal, pal.line) .hoverable(src) .clickable(interactionSource = src, indication = null, role = Role.RadioButton, onClick = onClick) .controllerConfirm(onClick = onClick) @@ -347,6 +355,7 @@ private fun TestRow(t: Release, selected: Boolean, onClick: () -> Unit) { Text(t.title.ifBlank { stringResource(R.string.upd_pr, t.pr) }, fontSize = 13.5.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) Text(if (t.apk == null) stringResource(R.string.upd_not_built) else stringResource(R.string.upd_updated, ago(t.publishedAt)), fontSize = 12.sp, color = colors.onSurfaceVariant) } + RadioDot(selected, 20.dp) } }