Scoop API

scoop:scoop.ui.component:0.1.0

src/builders/button.scoop

Selected production source · src/builders/button.scoop

1package scoop.ui.component
3import scoop.graphics.text.*
4import scoop.ui.*
5import scoop.ui.style.ThemeSource
6import scoop.ui.text.InlineView
8/** Button input is published through Props, including the current click callback. */
9public open class ContentButtonBuilder internal constructor() {
10 public var enabled: Boolean = true
11 public var invalid: Boolean = false
12 public var variant: ButtonVariant = ButtonVariant.Default
13 public var size: ButtonSize = ButtonSize.Default
14 public var group: GroupPosition? = None
15 public var labelTarget: FieldTarget? = None
16 public var style: ButtonStyle = defaultButtonStyle
17 public var theme: ThemeSource? = None
18 public var key: ViewKey = ViewKey.Position
19 public var focus: FocusOptions = FocusOptions()
20 public var semantics: ComponentSemantics = ComponentSemantics()
22 public fun style(configure: ButtonStyleBuilder.() -> Unit): Unit {
23 style = style.copy(configure)
24 }
26 public fun focus(configure: FocusOptionsBuilder.() -> Unit): Unit {
27 focus = focus.copy(configure)
28 }
31public open class ButtonBuilder internal constructor(): ContentButtonBuilder() {
32 public var fonts: FontCollection? = None
33 internal fun properties(label: LabelProps, onClick: () -> Unit): ButtonProps =
34 ButtonProps(
35 ButtonContent.Label(label),
36 onClick,
37 enabled,
38 style,
39 theme,
40 focus,
41 invalid,
42 variant,
43 size,
44 group,
45 labelTarget,
46 semantics
47 )
49 internal fun snapshot(text: String, onClick: () -> Unit): ButtonProps =
50 properties(
51 LabelProps(
52 LabelText.Plain(text, None),
53 fonts,
54 Some(paragraphStyle { alignment = TextAlignment.Center })
55 ),
56 onClick
57 )
60/** Extra paragraph and inline options for a complete styled label. */
61public class StyledButtonBuilder internal constructor(): ButtonBuilder() {
62 public var settings: ParagraphStyle? = None
63 public var inlines: Array<InlineView> = []
65 public fun settings(configure: ParagraphStyleBuilder.() -> Unit): Unit {
66 settings = Some((settings ?: paragraphStyle()).copy(configure))
67 }
69 internal fun snapshot(text: StyledText, onClick: () -> Unit): ButtonProps =
70 properties(LabelProps(LabelText.Styled(text), fonts, settings, inlines), onClick)
73internal fun makeTextButton(
74 text: String,
75 onClick: () -> Unit,
76 configure: ButtonBuilder.() -> Unit
77): View {
78 val builder = ButtonBuilder()
79 builder.configure()
80 return buttonView(builder.snapshot(text, onClick), builder.key)
83internal fun makeStyledButton(
84 text: StyledText,
85 onClick: () -> Unit,
86 configure: StyledButtonBuilder.() -> Unit
87): View {
88 val builder = StyledButtonBuilder()
89 builder.configure()
90 return buttonView(builder.snapshot(text, onClick), builder.key)
93private fun buttonView(input: ButtonProps, key: ViewKey): View =
94 component(input, { props, mount -> Button(props, scope = mount) }, key, Some(buttonComparison))
96internal fun makeContentButton(
97 content: View,
98 onClick: () -> Unit,
99 configure: ContentButtonBuilder.() -> Unit
100): View {
101 val builder = ContentButtonBuilder()
102 builder.configure()
103 return buttonView(
104 ButtonProps(
105 ButtonContent.Custom(content),
106 onClick,
107 builder.enabled,
108 builder.style,
109 builder.theme,
110 builder.focus,
111 builder.invalid,
112 builder.variant,
113 builder.size,
114 builder.group,
115 builder.labelTarget,
116 builder.semantics
117 ),
118 builder.key
119 )
122internal fun makeResolvedButton(
123 content: (ActionContentStyle) -> View,
124 onClick: () -> Unit,
125 configure: ContentButtonBuilder.() -> Unit
126): View {
127 val builder = ContentButtonBuilder()
128 builder.configure()
129 return buttonView(
130 ButtonProps(
131 ButtonContent.Resolved(content),
132 onClick,
133 builder.enabled,
134 builder.style,
135 builder.theme,
136 builder.focus,
137 builder.invalid,
138 builder.variant,
139 builder.size,
140 builder.group,
141 builder.labelTarget,
142 builder.semantics
143 ),
144 builder.key
145 )