Scoop API

scoop:scoop.ui.component:0.1.0

src/builders/choice_groups.scoop

Selected production source · src/builders/choice_groups.scoop

1package scoop.ui.component
3import scoop.graphics.text.*
4import scoop.ui.*
5import scoop.ui.style.*
7public class RadioItemBuilder internal constructor() {
8 public var focus: FocusOptions = FocusOptions()
9 public var labelTarget: FieldTarget? = None
10 public var invalid: Boolean = false
11 public var semantics: ComponentSemantics = ComponentSemantics()
12 public var marker: RadioOptions = radioOptions()
13 public var content: ((RadioItemContent) -> View)? = None
14 public fun focus(configure: FocusOptionsBuilder.() -> Unit) {
15 focus = focus.copy(configure)
16 }
17 public fun marker(configure: RadioOptionsBuilder.() -> Unit) {
18 marker = marker.copy(configure)
19 }
22public class RadioGroupBuilder<T: Equals<T>> internal constructor() {
23 private val entries = ArrayList<RadioGroupEntry<T>>()
24 public var axis: FlexAxis = FlexAxis.Vertical
25 public var spacing: Double = 8.0
26 public var loop: Boolean = true
27 public var enabled: Boolean = true
28 public var invalid: Boolean = false
29 public var semantics: ComponentSemantics = ComponentSemantics()
30 public var fonts: FontCollection? = None
31 public var theme: ThemeSource? = None
32 public var style: StyleOverride = styleOverride()
33 public var key: ViewKey = ViewKey.Position
34 public fun style(configure: StyleOverrideBuilder.() -> Unit) {
35 style = style.copy(configure)
36 }
37 public fun add(entry: RadioGroupEntry<T>) {
38 entries.add(entry)
39 }
40 public fun item(choice: Choice<T>, configure: RadioItemBuilder.() -> Unit = {}) {
41 val builder = RadioItemBuilder()
42 builder.configure()
43 add(
44 RadioGroupEntry(
45 choice,
46 builder.focus,
47 builder.labelTarget,
48 builder.invalid,
49 builder.marker,
50 builder.content,
51 builder.semantics
52 )
53 )
54 }
55 internal fun snapshot(selected: Binding<T?>): RadioGroupProps<T> =
56 RadioGroupProps(
57 entries.toArray(),
58 selected,
59 axis,
60 spacing,
61 loop,
62 enabled,
63 invalid,
64 fonts,
65 theme,
66 style,
67 semantics
68 )
71public fun <T: Equals<T>> radioGroup(
72 selected: Binding<T?>,
73 configure: RadioGroupBuilder<T>.() -> Unit = {}
74): View = makeRadioGroup(selected, configure)
76internal fun <T: Equals<T>> makeRadioGroup(
77 selected: Binding<T?>,
78 configure: RadioGroupBuilder<T>.() -> Unit
79): View {
80 val builder = RadioGroupBuilder<T>()
81 builder.configure()
82 return component(
83 builder.snapshot(selected),
84 { current, mount -> RadioGroup(current, scope = mount) },
85 builder.key
86 )
89public class ToggleGroupItemBuilder internal constructor() {
90 public var content: ButtonContent? = None
91 public var focus: FocusOptions = FocusOptions()
92 public var invalid: Boolean = false
93 public var semantics: ComponentSemantics = ComponentSemantics()
94 public var style: ButtonStyle? = None
95 public fun focus(configure: FocusOptionsBuilder.() -> Unit) {
96 focus = focus.copy(configure)
97 }
98 public fun style(configure: ButtonStyleBuilder.() -> Unit) {
99 style = Some((style ?: buttonStyle { this.kind = SurfaceKind.Plain }).copy(configure))
100 }
103public class ToggleGroupBuilder<T: Equals<T>> internal constructor() {
104 private val entries = ArrayList<ToggleGroupEntry<T>>()
105 public var axis: FlexAxis = FlexAxis.Horizontal
106 public var spacing: Double = 8.0
107 public var loop: Boolean = true
108 public var enabled: Boolean = true
109 public var invalid: Boolean = false
110 public var semantics: ComponentSemantics = ComponentSemantics()
111 public var variant: ToggleVariant = ToggleVariant.Default
112 public var size: ToggleSize = ToggleSize.Default
113 public var fonts: FontCollection? = None
114 public var theme: ThemeSource? = None
115 public var style: StyleOverride = styleOverride()
116 public var key: ViewKey = ViewKey.Position
117 public fun style(configure: StyleOverrideBuilder.() -> Unit) {
118 style = style.copy(configure)
119 }
120 public fun add(entry: ToggleGroupEntry<T>) {
121 entries.add(entry)
122 }
123 public fun item(choice: Choice<T>, configure: ToggleGroupItemBuilder.() -> Unit = {}) {
124 val builder = ToggleGroupItemBuilder()
125 builder.configure()
126 add(
127 ToggleGroupEntry(
128 choice,
129 builder.content,
130 builder.focus,
131 builder.invalid,
132 builder.style,
133 builder.semantics
134 )
135 )
136 }
137 internal fun snapshot(selected: ToggleGroupSelection<T>): ToggleGroupProps<T> =
138 ToggleGroupProps(
139 entries.toArray(),
140 selected,
141 axis,
142 spacing,
143 loop,
144 enabled,
145 invalid,
146 variant,
147 size,
148 fonts,
149 theme,
150 style,
151 semantics
152 )
155public fun <T: Equals<T>> toggleGroup(
156 selected: Binding<T?>,
157 configure: ToggleGroupBuilder<T>.() -> Unit = {}
158): View = makeToggleGroup(ToggleGroupSelection.Single(selected), configure)
160public fun <T: Equals<T>> toggleGroup(
161 selected: Binding<Array<T>>,
162 configure: ToggleGroupBuilder<T>.() -> Unit = {}
163): View = makeToggleGroup(ToggleGroupSelection.Multiple(selected), configure)
165internal fun <T: Equals<T>> makeToggleGroup(
166 selected: ToggleGroupSelection<T>,
167 configure: ToggleGroupBuilder<T>.() -> Unit
168): View {
169 val builder = ToggleGroupBuilder<T>()
170 builder.configure()
171 return component(
172 builder.snapshot(selected),
173 { current, mount -> ToggleGroup(current, scope = mount) },
174 builder.key
175 )