Scoop API

scoop:scoop.ui.component:0.1.0

src/slider/values.scoop

Selected production source · src/slider/values.scoop

1package scoop.ui.component
3import scoop.ui.*
4import scoop.ui.style.*
6public class SliderThumbOptions public constructor(
7 public val focus: FocusOptions = FocusOptions(),
8 public val labelTarget: FieldTarget? = None,
9 public val semantics: ComponentSemantics? = None
12public class SliderProps public constructor(
13 public val values: Binding<Array<Double>>,
14 public val range: RangeSpec,
15 public val orientation: Orientation = Orientation.Horizontal,
16 public val enabled: Boolean = true,
17 public val invalid: Boolean = false,
18 public val keyboardStep: Double? = None,
19 public val thumbs: Array<SliderThumbOptions> = [],
20 public val labelTarget: FieldTarget? = None,
21 public val style: SliderStyle = sliderStyle(),
22 public val theme: ThemeSource? = None,
23 public val onValueCommit: (Array<Double>) -> Unit = {},
24 public val onValueCancel: (Array<Double>, DragCancelReason) -> Unit = { _, _ -> },
25 public val semantics: ComponentSemantics = ComponentSemantics()
26) {
27 init {
28 when (keyboardStep) {
29 case Some(val step) -> requireComponent(
30 step.isFinite() && step > 0.0,
31 "slider keyboard step must be finite and positive"
32 )
33 case None -> requireComponent(
34 range.step != None,
35 "continuous slider requires a keyboard step"
36 )
37 }
38 }
41public class SliderThumbBuilder internal constructor() {
42 public var focus: FocusOptions = FocusOptions()
43 public var labelTarget: FieldTarget? = None
44 public var semantics: ComponentSemantics? = None
45 public fun focus(configure: FocusOptionsBuilder.() -> Unit) {
46 focus = focus.copy(configure)
47 }
50public class SliderBuilder internal constructor() {
51 private val thumbs = ArrayList<SliderThumbOptions>()
52 public var orientation: Orientation = Orientation.Horizontal
53 public var enabled: Boolean = true
54 public var invalid: Boolean = false
55 public var keyboardStep: Double? = None
56 public var labelTarget: FieldTarget? = None
57 public var style: SliderStyle = sliderStyle()
58 public var theme: ThemeSource? = None
59 public var semantics: ComponentSemantics = ComponentSemantics()
60 public var onValueCommit: (Array<Double>) -> Unit = {}
61 public var onValueCancel: (Array<Double>, DragCancelReason) -> Unit = { _, _ -> }
62 public var key: ViewKey = ViewKey.Position
63 public fun style(configure: SliderStyleBuilder.() -> Unit) {
64 style = style.copy(configure)
65 }
66 public fun thumb(configure: SliderThumbBuilder.() -> Unit = {}) {
67 val builder = SliderThumbBuilder()
68 builder.configure()
69 addThumb(SliderThumbOptions(builder.focus, builder.labelTarget, builder.semantics))
70 }
71 public fun addThumb(options: SliderThumbOptions) {
72 thumbs.add(options)
73 }
74 internal fun snapshot(values: Binding<Array<Double>>, range: RangeSpec): SliderProps =
75 SliderProps(
76 values,
77 range,
78 orientation,
79 enabled,
80 invalid,
81 keyboardStep,
82 thumbs.toArray(),
83 labelTarget,
84 style,
85 theme,
86 onValueCommit,
87 onValueCancel,
88 semantics
89 )
92public fun slider(
93 values: Binding<Array<Double>>,
94 range: RangeSpec,
95 configure: SliderBuilder.() -> Unit = {}
96): View = makeSlider(values, range, configure)
98internal fun makeSlider(
99 values: Binding<Array<Double>>,
100 range: RangeSpec,
101 configure: SliderBuilder.() -> Unit
102): View {
103 val builder = SliderBuilder()
104 builder.configure()
105 return component(
106 builder.snapshot(values, range),
107 { current, mount -> Slider(current, scope = mount) },
108 builder.key
109 )