scoop:scoop.ui.component:0.1.0
src/field/group.scoop
Selected production source · src/field/group.scoop
1
package scoop.ui.component3
import scoop.graphics.text.*4
import scoop.ui.*5
import scoop.ui.style.*7
public enum FieldStackKind {8
Group, Content9
}11
public class FieldStackProps public constructor(12
public val children: Array<View>,13
public val kind: FieldStackKind = FieldStackKind.Group,14
public val spacing: Double? = None,15
public val theme: ThemeSource? = None,16
public val padding: Insets = Insets(),17
public val style: StyleOverride = styleOverride()18
) {19
init {20
fieldLength(spacing);21
padding.totals()22
}23
}25
public class FieldStack public constructor(26
private val props: Props<FieldStackProps>,27
scope: ComponentScope28
): Component(scope) {29
private val themes = ThemeAccess(scope)30
public override fun onMount() {31
themes.mount(props.value.theme)32
}33
public override fun render(): View {34
val input = props.value35
val density = themes.read(input.theme).tokens.typography.body.fontSize / 14.036
val content =37
makeColumn {38
this.addAll(input.children)39
this.spacing =40
input.spacing ?:41
(42
if (input.kind == FieldStackKind.Group)43
20.044
else45
2.046
) *47
density48
this.alignment = CrossAlignment.Stretch49
}50
return panelFrame(content, input.padding, input.style)51
}52
}54
public class FieldStackBuilder internal constructor(): ChildrenBuilder() {55
public var spacing: Double? = None56
public var theme: ThemeSource? = None57
public var padding: Insets = Insets()58
public var style: StyleOverride = styleOverride()59
public fun style(configure: StyleOverrideBuilder.() -> Unit) {60
style = style.copy(configure)61
}62
internal fun snapshot(kind: FieldStackKind): FieldStackProps =63
FieldStackProps(childrenSnapshot(), kind, spacing, theme, padding, style)64
}66
public fun fieldGroup(configure: FieldStackBuilder.() -> Unit = {}): View =67
makeFieldStack(FieldStackKind.Group, configure)69
public fun fieldContent(configure: FieldStackBuilder.() -> Unit = {}): View =70
makeFieldStack(FieldStackKind.Content, configure)72
internal fun makeFieldStack(kind: FieldStackKind, configure: FieldStackBuilder.() -> Unit): View {73
val builder = FieldStackBuilder()74
builder.configure()75
return component(76
builder.snapshot(kind),77
{ current, mount -> FieldStack(current, scope = mount) },78
builder.key79
)80
}82
public class FieldSetProps public constructor(83
public val content: View,84
public val legend: PanelContent? = None,85
public val variant: FieldLegendVariant = FieldLegendVariant.Legend,86
public val description: PanelContent? = None,87
public val spacing: Double? = None,88
public val fonts: FontCollection? = None,89
public val theme: ThemeSource? = None,90
public val padding: Insets = Insets(),91
public val style: StyleOverride = styleOverride()92
) {93
init {94
fieldLength(spacing);95
padding.totals()96
}97
}99
public class FieldSet public constructor(100
private val props: Props<FieldSetProps>,101
scope: ComponentScope102
): Component(scope) {103
private val themes = ThemeAccess(scope)104
public override fun onMount() {105
themes.mount(props.value.theme)106
}107
public override fun render(): View {108
val input = props.value109
val theme = themes.read(input.theme)110
val content =111
makeColumn {112
when (input.legend) {113
case Some(val value) -> this.add(114
panelSlot(115
panelCaption(116
value,117
fieldTextStyle(fieldLegendRole(input.variant), theme),118
input.fonts119
),120
0L121
)122
)123
case None -> {}124
}125
when (input.description) {126
case Some(val value) -> this.add(127
panelSlot(128
panelCaption(129
value,130
fieldTextStyle(FieldTextRole.Description, theme),131
input.fonts132
),133
1L134
)135
)136
case None -> {}137
}138
this.add(panelSlot(input.content, 2L))139
this.spacing = input.spacing ?: 16.0 * theme.tokens.typography.body.fontSize / 14.0140
this.alignment = CrossAlignment.Stretch141
}142
return panelFrame(content, input.padding, input.style)143
}144
}146
public class FieldSetBuilder internal constructor() {147
public var legend: PanelContent? = None148
public var description: PanelContent? = None149
public var variant: FieldLegendVariant = FieldLegendVariant.Legend150
public var spacing: Double? = None151
public var fonts: FontCollection? = None152
public var theme: ThemeSource? = None153
public var padding: Insets = Insets()154
public var style: StyleOverride = styleOverride()155
public var key: ViewKey = ViewKey.Position156
public fun legend(text: String) {157
legend = Some(fieldPlain(text))158
}159
public fun legend(text: StyledText) {160
legend = Some(fieldStyled(text))161
}162
public fun legend(content: View) {163
legend = Some(PanelContent.Custom(content))164
}165
public fun description(text: String) {166
description = Some(fieldPlain(text))167
}168
public fun description(text: StyledText) {169
description = Some(fieldStyled(text))170
}171
public fun description(content: View) {172
description = Some(PanelContent.Custom(content))173
}174
public fun style(configure: StyleOverrideBuilder.() -> Unit) {175
style = style.copy(configure)176
}177
internal fun snapshot(content: View): FieldSetProps =178
FieldSetProps(content, legend, variant, description, spacing, fonts, theme, padding, style)179
}181
public fun fieldSet(content: View, configure: FieldSetBuilder.() -> Unit = {}): View =182
makeFieldSet(content, configure)184
internal fun makeFieldSet(content: View, configure: FieldSetBuilder.() -> Unit): View {185
val builder = FieldSetBuilder()186
builder.configure()187
return component(188
builder.snapshot(content),189
{ current, mount -> FieldSet(current, scope = mount) },190
builder.key191
)192
}