Scoop API

scoop:scoop.ui.component:0.1.0

src/scroll/behavior_resolve.scoop

Selected production source · src/scroll/behavior_resolve.scoop

1package scoop.ui.component
3import scoop.surface.AnimationSpec
4import scoop.time.Duration
5import scoop.window.InteractionPreferences
7/** Resolves system facts once per update, without selecting a theme by platform name. */
8internal class ResolvedScrollbarBehavior(
9 val input: ScrollbarBehavior,
10 preferences: InteractionPreferences,
11 val baseThickness: Double,
12 themeReduced: Boolean = false
13) {
14 private val automatic =
15 when (input.preset) {
16 case FollowSystem -> preferences.autoHideScrollbars ?: false
17 case Static -> false
18 case Custom -> true
19 }
20 val autoHide = input.autoHide ?: automatic
21 val widen = input.widenOnHover ?: automatic
22 val shade = input.shadeOnHover ?: automatic
23 val reduceMotion = (preferences.reduceMotion ?: false) || themeReduced
24 val opaque = preferences.reduceTransparency ?: false
25 val idleWidth =
26 input.idleWidth ?:
27 if (automatic)
28 baseThickness / 2.0
29 else
30 baseThickness
31 val hoverWidth =
32 if (widen)
33 input.hoverWidth ?: baseThickness
34 else
35 idleWidth
36 val dragWidth =
37 if (widen)
38 input.dragWidth ?: baseThickness
39 else
40 idleWidth
41 val idleOpacity =
42 if (opaque)
43 1.0
44 else
45 input.idleOpacity ?:
46 if (automatic)
47 0.55
48 else
49 1.0
50 val hoverOpacity =
51 if (opaque)
52 1.0
53 else
54 if (shade)
55 input.hoverOpacity ?:
56 if (automatic)
57 0.85
58 else
59 1.0
60 else
61 idleOpacity
62 val dragOpacity =
63 if (opaque)
64 1.0
65 else
66 if (shade)
67 input.dragOpacity ?: 1.0
68 else
69 idleOpacity
70 val thickness =
71 lowerBound(
72 lowerBound(idleWidth, lowerBound(hoverWidth, dragWidth)),
73 input.minimumHitThickness ?: lowerBound(baseThickness, 12.0)
74 )
75 val edgeThickness = input.edgeThickness ?: this.thickness
76 val showTrack = input.showTrack ?: !automatic
78 fun transition(duration: Duration, transparency: Boolean = false): AnimationSpec? =
79 if (reduceMotion || (transparency && opaque) || duration == Duration.ZERO)
80 None
81 else
82 Some(AnimationSpec.Tween(duration))