EARHORNMUSIC UPnP · Android TV · Phones · Android Auto · GNU/Linux
Release 0.5.0

StaveFocusable.kt

Each line, with the release that last changed it.

0.5.01package dev.stave.ui.components
2
3import androidx.compose.foundation.border
4import androidx.compose.foundation.interaction.MutableInteractionSource
5import androidx.compose.foundation.interaction.collectIsFocusedAsState
6import androidx.compose.foundation.shape.RoundedCornerShape
7import androidx.compose.runtime.Composable
8import androidx.compose.runtime.getValue
9import androidx.compose.runtime.remember
10import androidx.compose.ui.Modifier
11import androidx.compose.ui.draw.clip
12import androidx.compose.ui.graphics.Color
13import androidx.compose.ui.unit.dp
14import dev.stave.ui.theme.AccentAmber
15import dev.stave.ui.theme.SurfaceRaised
16
17/**
18 * Adds the Earhorn focus visual: a 2dp amber border when focused, nothing
19 * otherwise (the caller paints its own background). Pair with a Modifier that
20 * declares focusability (e.g. clickable).
21 */
22@Composable
23fun Modifier.staveFocusable(
24 interactionSource: MutableInteractionSource,
25 cornerRadiusDp: Int = 8,
26): Modifier {
27 val focused by interactionSource.collectIsFocusedAsState()
28 val shape = remember(cornerRadiusDp) { RoundedCornerShape(cornerRadiusDp.dp) }
29 return this
30 .clip(shape)
31 .then(
32 if (focused) {
33 Modifier
34 .border(2.dp, AccentAmber, shape)
35 } else {
36 Modifier
37 }
38 )
39}