scoop:scoop.ui.component:0.1.0
src/select/builder.scoop
Selected production source · src/select/builder.scoop
1
package scoop.ui.component3
import scoop.graphics.text.FontCollection4
import scoop.surface.AnimationSpec5
import scoop.ui.*6
import scoop.ui.style.*8
public class SelectItemBuilder internal constructor() {9
public var content: View? = None10
public var icon: View? = None11
public var focus: FocusOptions = FocusOptions()12
public var style: ButtonStyle = buttonStyle()13
public var semantics: ComponentSemantics = ComponentSemantics()14
public fun focus(configure: FocusOptionsBuilder.() -> Unit) {15
focus = focus.copy(configure)16
}17
public fun style(configure: ButtonStyleBuilder.() -> Unit) {18
style = style.copy(configure)19
}20
}22
public open class SelectContentBuilder<T: Equals<T>> internal constructor() {23
private val entries = ArrayList<SelectEntry<T>>()24
public fun item(choice: Choice<T>, configure: SelectItemBuilder.() -> Unit = {}) {25
val b = SelectItemBuilder();26
b.configure()27
entries.add(28
SelectEntry.Item(SelectItem(choice, b.content, b.icon, b.focus, b.style, b.semantics))29
)30
}31
public fun label(key: ViewKey, text: String) {32
label(key, PanelContent.Label(LabelProps(LabelText.Plain(text, None))))33
}34
public fun label(key: ViewKey, content: PanelContent) {35
entries.add(SelectEntry.Label(key, content))36
}37
public fun separator(key: ViewKey) {38
entries.add(SelectEntry.Separator(key))39
}40
public fun group(key: ViewKey, text: String, configure: SelectContentBuilder<T>.() -> Unit) {41
label(key, text);42
this.configure()43
}44
internal fun content(): SelectContent<T> = SelectContent(entries.toArray())45
}47
public class SelectBuilder<T: Equals<T>> internal constructor(): SelectContentBuilder<T>() {48
public var key: ViewKey = ViewKey.Position49
public var open: Binding<Boolean>? = None50
public var placeholder: String = "Select an option"51
public var unavailableText: String = "Unavailable selection"52
public var enabled: Boolean = true53
public var invalid: Boolean = false54
public var size: SelectSize = SelectSize.Default55
public var position: SelectPosition = SelectPosition.ItemAligned56
public var width: Double? = None57
public var maxHeight: Double = 320.058
public var scrollButtons: Boolean = true59
public var scroll: ScrollState? = None60
public var style: ButtonStyle = buttonStyle()61
public var semantics: ComponentSemantics = ComponentSemantics()62
public var popupStyle: StyleOverride = styleOverride()63
public var popupSemantics: ComponentSemantics = ComponentSemantics()64
public var theme: ThemeSource? = None65
public var fonts: FontCollection? = None66
public var focus: FocusOptions = FocusOptions()67
public var labelTarget: FieldTarget? = None68
public var popupFocus: OverlayFocusOptions = OverlayFocusOptions()69
public var mode: OverlayMode = OverlayMode.NonModal70
public var loop: Boolean = true71
public var typeahead: TypeaheadOptions? = None72
public var transition: StyleValue<AnimationSpec?> = StyleValue.Inherit73
public var handle: OverlayHandle? = None74
public var group: GroupPosition? = None75
public var valueContent: ((SelectValue<T>) -> View)? = None76
public var icon: View? = None77
public var onValueChange: (T?) -> Unit = {}78
public var onOpenChange: (Boolean) -> Unit = {}79
public var onCloseRequest: (OverlayCloseReason) -> Boolean = { _ -> true }80
public var onClosed: (OverlayCloseReason) -> Unit = {}81
public fun style(configure: ButtonStyleBuilder.() -> Unit) {82
style = style.copy(configure)83
}84
public fun popupStyle(configure: StyleOverrideBuilder.() -> Unit) {85
popupStyle = popupStyle.then(styleOverride(configure))86
}87
public fun focus(configure: FocusOptionsBuilder.() -> Unit) {88
focus = focus.copy(configure)89
}90
public fun popupFocus(configure: OverlayFocusOptionsBuilder.() -> Unit) {91
popupFocus = popupFocus.copy(configure)92
}93
internal fun snapshot(value: Binding<T?>): SelectProps<T> =94
SelectProps(95
value,96
content(),97
open,98
placeholder,99
unavailableText,100
enabled,101
invalid,102
size,103
position,104
width,105
maxHeight,106
scrollButtons,107
scroll,108
style,109
popupStyle,110
theme,111
fonts,112
focus,113
labelTarget,114
popupFocus,115
mode,116
loop,117
typeahead,118
transition,119
handle,120
group,121
valueContent,122
icon,123
onValueChange,124
onOpenChange,125
onCloseRequest,126
onClosed,127
semantics,128
popupSemantics129
)130
}132
public fun <T: Equals<T>> select(133
value: Binding<T?>,134
configure: SelectBuilder<T>.() -> Unit = {}135
): View = makeSelect(value, [], configure)137
public fun <T: Equals<T>> select(138
value: Binding<T?>,139
choices: Array<Choice<T>>,140
configure: SelectBuilder<T>.() -> Unit = {}141
): View = makeSelect(value, choices, configure)143
internal fun <T: Equals<T>> makeSelect(144
value: Binding<T?>,145
choices: Array<Choice<T>>,146
configure: SelectBuilder<T>.() -> Unit147
): View {148
val b = SelectBuilder<T>()149
for (choice in choices)150
b.item(choice)151
b.configure()152
return component(b.snapshot(value), { current, mount -> Select(current, scope = mount) }, b.key)153
}