Yokan / rebuild
Course 1 8624561

Scrollbar.desktop.kt

composeApp/src/desktopMain/kotlin/eu/friedcutlet/yokan/ui/components/Scrollbar.desktop.kt

implementation79 lines
1package eu.friedcutlet.yokan.ui.components23import androidx.compose.foundation.ScrollState4import androidx.compose.foundation.ScrollbarStyle5import androidx.compose.foundation.VerticalScrollbar6import androidx.compose.foundation.layout.BoxScope7import androidx.compose.foundation.layout.fillMaxHeight8import androidx.compose.foundation.layout.padding9import androidx.compose.foundation.layout.width10import androidx.compose.foundation.lazy.LazyListState11import androidx.compose.foundation.lazy.grid.LazyGridState12import androidx.compose.foundation.rememberScrollbarAdapter13import androidx.compose.foundation.shape.RoundedCornerShape14import androidx.compose.material3.MaterialTheme15import androidx.compose.runtime.Composable16import androidx.compose.runtime.remember17import androidx.compose.ui.Alignment18import androidx.compose.ui.Modifier19import androidx.compose.ui.unit.dp2021/**22 * An always-visible, draggable scrollbar style. The Compose Desktop default23 * fades the thumb out when idle, which made it hard to tell a list was24 * scrollable or to grab the thumb. We keep the thumb visible at a steady25 * alpha and darken it on hover so it always reads as a draggable control.26 */27@Composable28private fun yokanScrollbarStyle(): ScrollbarStyle {29    val base = MaterialTheme.colorScheme.onSurface30    return remember(base) {31        ScrollbarStyle(32            minimalHeight = 32.dp,33            thickness = 10.dp,34            shape = RoundedCornerShape(5.dp),35            hoverDurationMillis = 200,36            unhoverColor = base.copy(alpha = 0.32f),37            hoverColor = base.copy(alpha = 0.60f),38        )39    }40}4142@Composable43internal actual fun BoxScope.PlatformVerticalScrollbar(state: LazyListState) {44    VerticalScrollbar(45        adapter = rememberScrollbarAdapter(state),46        style = yokanScrollbarStyle(),47        modifier = Modifier48            .align(Alignment.CenterEnd)49            .fillMaxHeight()50            .padding(vertical = 2.dp)51            .width(10.dp),52    )53}5455@Composable56internal actual fun BoxScope.PlatformVerticalScrollbar(state: LazyGridState) {57    VerticalScrollbar(58        adapter = rememberScrollbarAdapter(state),59        style = yokanScrollbarStyle(),60        modifier = Modifier61            .align(Alignment.CenterEnd)62            .fillMaxHeight()63            .padding(vertical = 2.dp)64            .width(10.dp),65    )66}6768@Composable69internal actual fun BoxScope.PlatformVerticalScrollbar(state: ScrollState) {70    VerticalScrollbar(71        adapter = rememberScrollbarAdapter(state),72        style = yokanScrollbarStyle(),73        modifier = Modifier74            .align(Alignment.CenterEnd)75            .fillMaxHeight()76            .padding(vertical = 2.dp)77            .width(10.dp),78    )79}80

Search chapters, reference and source filenames.