Scoop API

scoop:scoop.ui.component:0.1.0

src/choice/source_builder.scoop

Selected production source · src/choice/source_builder.scoop

1package scoop.ui.component
3import scoop.graphics.text.StyledText
4import scoop.ui.*
5import scoop.ui.style.*
7public class ChoiceItemBuilder internal constructor() {
8 public var keywords: Array<String> = []
9 public var content: View? = None
10 public var icon: View? = None
11 public var style: StyleOverride = styleOverride()
12 public fun style(configure: StyleOverrideBuilder.() -> Unit) {
13 style = style.copy(configure)
14 }
17public class ChoiceContentBuilder<T: Equals<T>> internal constructor() {
18 private val entries = ArrayList<ChoiceEntry<T>>()
19 public fun add(entry: ChoiceEntry<T>) {
20 entries.add(entry)
21 }
22 public fun item(choice: Choice<T>, configure: ChoiceItemBuilder.() -> Unit = {}) {
23 val builder = ChoiceItemBuilder()
24 builder.configure()
25 entries.add(
26 ChoiceEntry.Item(
27 ChoiceItem(choice, builder.keywords, builder.content, builder.icon, builder.style)
28 )
29 )
30 }
31 public fun group(key: ViewKey, title: String, configure: ChoiceContentBuilder<T>.() -> Unit) {
32 group(key, PanelContent.Label(LabelProps(LabelText.Plain(title, None))), configure)
33 }
34 public fun group(
35 key: ViewKey,
36 title: StyledText,
37 configure: ChoiceContentBuilder<T>.() -> Unit
38 ) {
39 group(key, PanelContent.Label(LabelProps(LabelText.Styled(title))), configure)
40 }
41 public fun group(key: ViewKey, title: View, configure: ChoiceContentBuilder<T>.() -> Unit) {
42 group(key, PanelContent.Custom(title), configure)
43 }
44 public fun group(
45 key: ViewKey,
46 title: PanelContent,
47 configure: ChoiceContentBuilder<T>.() -> Unit
48 ) {
49 entries.add(ChoiceEntry.Label(key, title))
50 val group = ChoiceContentBuilder<T>()
51 group.configure()
52 for (entry in group.entries)
53 entries.add(entry)
54 }
55 public fun separator(key: ViewKey) {
56 entries.add(ChoiceEntry.Separator(key))
57 }
58 internal fun snapshot(): ChoiceContent<T> = ChoiceContent(entries.toArray())
61public fun <T: Equals<T>> choiceItems(configure: ChoiceContentBuilder<T>.() -> Unit): ChoiceContent<
62 T
63> {
64 val builder = ChoiceContentBuilder<T>()
65 builder.configure()
66 return builder.snapshot()