scoop:scoop.ui.component:0.1.0
src/builders/button.scoop
Selected production source · src/builders/button.scoop
1
package scoop.ui.component3
import scoop.graphics.text.*4
import scoop.ui.*5
import scoop.ui.style.ThemeSource6
import scoop.ui.text.InlineView8
/** Button input is published through Props, including the current click callback. */9
public open class ContentButtonBuilder internal constructor() {10
public var enabled: Boolean = true11
public var invalid: Boolean = false12
public var variant: ButtonVariant = ButtonVariant.Default13
public var size: ButtonSize = ButtonSize.Default14
public var group: GroupPosition? = None15
public var labelTarget: FieldTarget? = None16
public var style: ButtonStyle = defaultButtonStyle17
public var theme: ThemeSource? = None18
public var key: ViewKey = ViewKey.Position19
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
}29
}31
public open class ButtonBuilder internal constructor(): ContentButtonBuilder() {32
public var fonts: FontCollection? = None33
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
semantics47
)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
onClick57
)58
}60
/** Extra paragraph and inline options for a complete styled label. */61
public class StyledButtonBuilder internal constructor(): ButtonBuilder() {62
public var settings: ParagraphStyle? = None63
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)71
}73
internal fun makeTextButton(74
text: String,75
onClick: () -> Unit,76
configure: ButtonBuilder.() -> Unit77
): View {78
val builder = ButtonBuilder()79
builder.configure()80
return buttonView(builder.snapshot(text, onClick), builder.key)81
}83
internal fun makeStyledButton(84
text: StyledText,85
onClick: () -> Unit,86
configure: StyledButtonBuilder.() -> Unit87
): View {88
val builder = StyledButtonBuilder()89
builder.configure()90
return buttonView(builder.snapshot(text, onClick), builder.key)91
}93
private fun buttonView(input: ButtonProps, key: ViewKey): View =94
component(input, { props, mount -> Button(props, scope = mount) }, key, Some(buttonComparison))96
internal fun makeContentButton(97
content: View,98
onClick: () -> Unit,99
configure: ContentButtonBuilder.() -> Unit100
): 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.semantics117
),118
builder.key119
)120
}122
internal fun makeResolvedButton(123
content: (ActionContentStyle) -> View,124
onClick: () -> Unit,125
configure: ContentButtonBuilder.() -> Unit126
): 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.semantics143
),144
builder.key145
)146
}