Scoop API

scoop:scoop.ui.component:0.1.0

src/carousel/values.scoop

Selected production source · src/carousel/values.scoop

1package scoop.ui.component
3import scoop.surface.*
4import scoop.time.Duration
5import scoop.ui.*
6import scoop.ui.style.*
8public enum CarouselItemSize {
9 Fraction(Double), Length(Double), Content
12public class CarouselAutoplay public constructor(
13 public val interval: Duration,
14 public val pauseOnHover: Boolean = true,
15 public val pauseOnFocus: Boolean = true
16) {
17 init {
18 requireComponent(interval > Duration.ZERO, "carousel autoplay interval must be positive")
19 }
22public class CarouselViewportOptions public constructor(
23 public val padding: Double = 4.0,
24 public val focus: FocusOptions = FocusOptions(),
25 public val style: StyleOverride = styleOverride()
26) {
27 init {
28 nonnegative(padding, "invalid carousel viewport padding")
29 }
32public class CarouselButtonOptions public constructor(
33 public val visible: Boolean = true,
34 public val focus: FocusOptions = FocusOptions(),
35 public val style: ButtonStyle = buttonStyle(),
36 public val content: View? = None,
37 public val semantics: ComponentSemantics = ComponentSemantics()
40public struct CarouselSnapshot(
41 val index: Long = -1L,
42 val key: ViewKey? = None,
43 val count: Long = 0L,
44 val canPrevious: Boolean = false,
45 val canNext: Boolean = false,
46 val looping: Boolean = false,
47 val dragging: Boolean = false
50public class CarouselProps public constructor(
51 public val source: ItemSource,
52 public val selected: Binding<Long>? = None,
53 public val initialIndex: Long = 0L,
54 public val itemSize: (Long) -> CarouselItemSize = { _ -> CarouselItemSize.Fraction(1.0) },
55 public val orientation: Orientation = Orientation.Horizontal,
56 public val loop: Boolean = false,
57 public val enabled: Boolean = true,
58 public val length: Double? = None,
59 public val spacing: Double = 16.0,
60 public val dragThreshold: Double = 4.0,
61 public val projectionSeconds: Double = 0.15,
62 public val autoplay: CarouselAutoplay? = None,
63 public val handle: CarouselHandle? = None,
64 public val viewport: CarouselViewportOptions = CarouselViewportOptions(),
65 public val previous: CarouselButtonOptions = CarouselButtonOptions(),
66 public val next: CarouselButtonOptions = CarouselButtonOptions(),
67 public val theme: ThemeSource? = None,
68 public val style: StyleOverride = styleOverride(),
69 public val transition: StyleValue<AnimationSpec?> = StyleValue.Inherit,
70 public val onSelect: (Long, ViewKey) -> Unit = { _, _ -> Unit },
71 public val onDragCancel: (DragCancelReason) -> Unit = {},
72 public val nativeSwipe: Boolean = true,
73 public val semantics: ComponentSemantics = ComponentSemantics()
74) {
75 init {
76 requireComponent(source.count >= 0L, "negative carousel item count")
77 nonnegative(spacing, "invalid carousel spacing")
78 nonnegative(dragThreshold, "invalid carousel drag threshold")
79 nonnegative(projectionSeconds, "invalid carousel projection duration")
80 when (length) {
81 case Some(val value) -> nonnegative(value, "invalid carousel length")
82 case None -> {}
83 }
84 }
87internal fun carouselExtent(size: CarouselItemSize, viewport: Double, spacing: Double): Double? =
88 when (size) {
89 case Content -> None
90 case Length(val value) -> {
91 nonnegative(value, "invalid carousel item length");
92 Some(value)
93 }
94 case Fraction(val value) -> {
95 requireComponent(value.isFinite() && value > 0.0, "invalid carousel item fraction")
96 val extent = lowerBound(0.0, viewport * value - spacing * (1.0 - value))
97 nonnegative(extent, "carousel item extent overflow")
98 Some(extent)
99 }
100 }