Scoop API

scoop:scoop.ui.component:0.1.0

src/scroll/behavior.scoop

Selected production source · src/scroll/behavior.scoop

1package scoop.ui.component
3import scoop.time.Duration
5public enum ScrollbarPreset {
6 FollowSystem, Static, Custom
7}
9public enum ScrollbarTrackPress {
10 Page, Jump
13public enum ScrollbarPlacement {
14 Overlay, Gutter
17/** Immutable activity and feedback options; shape and colors stay in the theme. */
18public class ScrollbarBehavior internal constructor(
19 public val preset: ScrollbarPreset = ScrollbarPreset.FollowSystem,
20 public val autoHide: Boolean? = None,
21 public val idleDelay: Duration = Duration.milliseconds(1000L),
22 public val fadeIn: Duration = Duration.milliseconds(100L),
23 public val fadeOut: Duration = Duration.milliseconds(250L),
24 public val revealOnScroll: Boolean = true,
25 public val revealOnViewportHover: Boolean = false,
26 public val revealOnEdgeHover: Boolean = true,
27 public val revealOnKeyboard: Boolean = true,
28 public val widenOnHover: Boolean? = None,
29 public val shadeOnHover: Boolean? = None,
30 public val idleWidth: Double? = None,
31 public val hoverWidth: Double? = None,
32 public val dragWidth: Double? = None,
33 public val expandDuration: Duration = Duration.milliseconds(120L),
34 public val contractDuration: Duration = Duration.milliseconds(180L),
35 public val idleOpacity: Double? = None,
36 public val hoverOpacity: Double? = None,
37 public val dragOpacity: Double? = None,
38 public val shadeDuration: Duration = Duration.milliseconds(120L),
39 public val minimumHitThickness: Double? = None,
40 public val edgeThickness: Double? = None,
41 public val showTrack: Boolean? = None,
42 public val trackPress: ScrollbarTrackPress = ScrollbarTrackPress.Page,
43 public val repeatDelay: Duration? = Some(Duration.milliseconds(400L)),
44 public val repeatInterval: Duration = Duration.milliseconds(60L),
45 public val placement: ScrollbarPlacement = ScrollbarPlacement.Overlay
46) {
47 init {
48 for (value in [idleDelay, fadeIn, fadeOut, expandDuration, contractDuration, shadeDuration])
49 requireComponent(value >= Duration.ZERO, "negative scrollbar duration")
50 when (repeatDelay) {
51 case Some(val value) -> requireComponent(
52 value >= Duration.ZERO,
53 "negative scrollbar repeat delay"
54 )
55 case None -> {}
56 }
57 requireComponent(
58 repeatInterval > Duration.ZERO,
59 "scrollbar repeat interval must be positive"
60 )
61 for (value in [idleWidth, hoverWidth, dragWidth, minimumHitThickness, edgeThickness])
62 when (value) {
63 case Some(val width) -> nonnegative(width, "invalid scrollbar width")
64 case None -> {}
65 }
66 for (value in [idleOpacity, hoverOpacity, dragOpacity])
67 when (value) {
68 case Some(val opacity) -> requireComponent(
69 opacity.isFinite() && opacity >= 0.0 && opacity <= 1.0,
70 "invalid scrollbar opacity"
71 )
72 case None -> {}
73 }
74 }
75 public fun copy(configure: ScrollbarBehaviorBuilder.() -> Unit = {}): ScrollbarBehavior =
76 configureScrollbarBehavior(this, configure)
79public fun scrollbarBehavior(
80 configure: ScrollbarBehaviorBuilder.() -> Unit = {}
81): ScrollbarBehavior = configureScrollbarBehavior(ScrollbarBehavior(), configure)