Scoop API

scoop:scoop.ui.component:0.1.0

src/builders/tabs.scoop

Selected production source · src/builders/tabs.scoop

1package scoop.ui.component
3import scoop.graphics.text.*
4import scoop.ui.*
5import scoop.ui.style.*
7public class TabItemBuilder internal constructor() {
8 public var semantics: ComponentSemantics = ComponentSemantics()
9 public var trigger: ButtonContent? = None
10 public var focus: FocusOptions = FocusOptions()
11 public var retention: ContentRetention? = None
12 public var triggerStyle: ButtonStyle? = None
13 public var panelStyle: StyleOverride = styleOverride()
14 public fun trigger(text: String) {
15 trigger = Some(ButtonContent.Label(LabelProps(LabelText.Plain(text, None))))
16 }
17 public fun trigger(text: StyledText) {
18 trigger = Some(ButtonContent.Label(LabelProps(LabelText.Styled(text))))
19 }
20 public fun trigger(content: View) {
21 trigger = Some(ButtonContent.Custom(content))
22 }
23 public fun trigger(content: (ActionContentStyle) -> View) {
24 trigger = Some(ButtonContent.Resolved(content))
25 }
26 public fun focus(configure: FocusOptionsBuilder.() -> Unit) {
27 focus = focus.copy(configure)
28 }
29 public fun triggerStyle(configure: ButtonStyleBuilder.() -> Unit) {
30 triggerStyle =
31 Some((triggerStyle ?: buttonStyle { this.kind = SurfaceKind.Plain }).copy(configure))
32 }
33 public fun panelStyle(configure: StyleOverrideBuilder.() -> Unit) {
34 panelStyle = panelStyle.copy(configure)
35 }
38public class TabsBuilder<T: Equals<T>> internal constructor() {
39 public var semantics: ComponentSemantics = ComponentSemantics()
40 private val entries = ArrayList<TabEntry<T>>()
41 public var activation: TabActivation = TabActivation.Auto
42 public var axis: FlexAxis = FlexAxis.Horizontal
43 public var variant: TabsVariant = TabsVariant.Default
44 public var retention: ContentRetention = ContentRetention.Dispose
45 public var enabled: Boolean = true
46 public var loop: Boolean = true
47 public var spacing: Double = 8.0
48 public var fonts: FontCollection? = None
49 public var theme: ThemeSource? = None
50 public var style: StyleOverride = styleOverride()
51 public var listStyle: StyleOverride = styleOverride()
52 public var onValueChange: (T?) -> Unit = {}
53 public var key: ViewKey = ViewKey.Position
54 public fun add(entry: TabEntry<T>) {
55 entries.add(entry)
56 }
57 public fun item(choice: Choice<T>, content: View, configure: TabItemBuilder.() -> Unit = {}) {
58 val builder = TabItemBuilder()
59 builder.configure()
60 add(
61 TabEntry(
62 choice,
63 content,
64 builder.trigger,
65 builder.focus,
66 builder.retention,
67 builder.triggerStyle,
68 builder.panelStyle,
69 builder.semantics
70 )
71 )
72 }
73 public fun style(configure: StyleOverrideBuilder.() -> Unit) {
74 style = style.copy(configure)
75 }
76 public fun listStyle(configure: StyleOverrideBuilder.() -> Unit) {
77 listStyle = listStyle.copy(configure)
78 }
79 internal fun snapshot(selected: Binding<T?>): TabsProps<T> =
80 TabsProps(
81 entries.toArray(),
82 selected,
83 activation,
84 axis,
85 variant,
86 retention,
87 enabled,
88 loop,
89 spacing,
90 fonts,
91 theme,
92 style,
93 listStyle,
94 onValueChange,
95 semantics
96 )
99public fun <T: Equals<T>> tabs(
100 selected: Binding<T?>,
101 configure: TabsBuilder<T>.() -> Unit = {}
102): View = makeTabs(selected, configure)
104internal fun <T: Equals<T>> makeTabs(
105 selected: Binding<T?>,
106 configure: TabsBuilder<T>.() -> Unit
107): View {
108 val builder = TabsBuilder<T>()
109 builder.configure()
110 return component(
111 builder.snapshot(selected),
112 { current, mount -> Tabs(current, scope = mount) },
113 builder.key
114 )