scoop:scoop.ui.component:0.1.0
src/choice/source_builder.scoop
Selected production source · src/choice/source_builder.scoop
1
package scoop.ui.component3
import scoop.graphics.text.StyledText4
import scoop.ui.*5
import scoop.ui.style.*7
public class ChoiceItemBuilder internal constructor() {8
public var keywords: Array<String> = []9
public var content: View? = None10
public var icon: View? = None11
public var style: StyleOverride = styleOverride()12
public fun style(configure: StyleOverrideBuilder.() -> Unit) {13
style = style.copy(configure)14
}15
}17
public 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>.() -> Unit38
) {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>.() -> Unit48
) {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())59
}61
public fun <T: Equals<T>> choiceItems(configure: ChoiceContentBuilder<T>.() -> Unit): ChoiceContent<62
T63
> {64
val builder = ChoiceContentBuilder<T>()65
builder.configure()66
return builder.snapshot()67
}