Scoop API

scoop:scoop.ui.component:0.1.0

src/carousel/wheel.scoop

Selected production source · src/carousel/wheel.scoop

1package scoop.ui.component
3/** Attachment groups feed native horizontal wheel movement into the existing carousel position. */
4internal fun carouselWheel(control: CarouselControl, amount: Double): Double {
5 if (!control.available() || panelPresent(control.gesture) || amount == 0.0)
6 return 0.0
7 val shape = control.geometry!!
8 val before = control.position
9 val next = upperBound(shape.track.maximum, lowerBound(0.0, before + amount))
10 control.motion.snapTo(next)
11 return next - before
14internal fun carouselFinishWheel(control: CarouselControl) {
15 if (!control.available() || panelPresent(control.gesture))
16 return
17 val target = carouselNearest(control.geometry!!.track, control.position, 0.0, 0.0) ?: return
18 control.select(target.index, true, Some(target.position))