scoop:scoop.ui.component:0.1.0
src/input/motion.scoop
Selected production source · src/input/motion.scoop
1
package scoop.ui.component3
import scoop.surface.*4
import scoop.ui.ComponentScope5
import scoop.ui.style.InteractionVisual7
/** The only clocks are the two animations already owned by the Surface scope. */8
internal class InteractionMotion(scope: ComponentScope, initial: InteractionVisual) {9
private val hover =10
scope.animation(11
if (initial.enabled && initial.hovered)12
1.013
else14
0.015
)16
private val press =17
scope.animation(18
if (initial.enabled && initial.pressed)19
1.020
else21
0.022
)23
fun update(visual: InteractionVisual, hoverSpec: AnimationSpec?, pressSpec: AnimationSpec?) {24
changeProgress(25
hover,26
if (visual.enabled && visual.hovered)27
1.028
else29
0.0,30
if (visual.enabled)31
hoverSpec32
else33
None34
)35
changeProgress(36
press,37
if (visual.enabled && visual.pressed)38
1.039
else40
0.0,41
if (visual.enabled)42
pressSpec43
else44
None45
)46
}47
fun sample(visual: InteractionVisual): InteractionVisual =48
InteractionVisual(49
visual.enabled,50
visual.hovered,51
visual.pressed,52
visual.focusVisible,53
Some(hover.value),54
Some(press.value),55
visual.invalid56
)57
}59
internal fun changeProgress(value: Animatable<Double>, target: Double, transition: AnimationSpec?) {60
when (transition) {61
case Some(val spec) -> {62
if (value.target != target)63
value.animateTo(target, spec)64
}65
case None -> {66
if (67
value.value !=68
target ||69
value.state ==70
AnimationState.Running ||71
value.state ==72
AnimationState.Paused73
)74
value.snapTo(target)75
}76
}77
}