package eu.friedcutlet.yokan.ui.components import androidx.compose.foundation.ScrollState import androidx.compose.foundation.ScrollbarStyle import androidx.compose.foundation.VerticalScrollbar import androidx.compose.foundation.layout.BoxScope import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.grid.LazyGridState import androidx.compose.foundation.rememberScrollbarAdapter import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp /** * An always-visible, draggable scrollbar style. The Compose Desktop default * fades the thumb out when idle, which made it hard to tell a list was * scrollable or to grab the thumb. We keep the thumb visible at a steady * alpha and darken it on hover so it always reads as a draggable control. */ @Composable private fun yokanScrollbarStyle(): ScrollbarStyle { val base = MaterialTheme.colorScheme.onSurface return remember(base) { ScrollbarStyle( minimalHeight = 32.dp, thickness = 10.dp, shape = RoundedCornerShape(5.dp), hoverDurationMillis = 200, unhoverColor = base.copy(alpha = 0.32f), hoverColor = base.copy(alpha = 0.60f), ) } } @Composable internal actual fun BoxScope.PlatformVerticalScrollbar(state: LazyListState) { VerticalScrollbar( adapter = rememberScrollbarAdapter(state), style = yokanScrollbarStyle(), modifier = Modifier .align(Alignment.CenterEnd) .fillMaxHeight() .padding(vertical = 2.dp) .width(10.dp), ) } @Composable internal actual fun BoxScope.PlatformVerticalScrollbar(state: LazyGridState) { VerticalScrollbar( adapter = rememberScrollbarAdapter(state), style = yokanScrollbarStyle(), modifier = Modifier .align(Alignment.CenterEnd) .fillMaxHeight() .padding(vertical = 2.dp) .width(10.dp), ) } @Composable internal actual fun BoxScope.PlatformVerticalScrollbar(state: ScrollState) { VerticalScrollbar( adapter = rememberScrollbarAdapter(state), style = yokanScrollbarStyle(), modifier = Modifier .align(Alignment.CenterEnd) .fillMaxHeight() .padding(vertical = 2.dp) .width(10.dp), ) }