Scoop API

scoop:scoop.ui.component:0.1.0

src/builders/label.scoop

Selected production source · src/builders/label.scoop

1package scoop.ui.component
3import scoop.graphics.Color
4import scoop.graphics.text.*
5import scoop.ui.*
6import scoop.ui.style.ThemeSource
7import scoop.ui.text.InlineView
9/** Common options for both text models; configuration never acquires fonts. */
10public open class LabelBuilder internal constructor() {
11 public var fonts: FontCollection? = None
12 public var settings: ParagraphStyle? = None
13 public var theme: ThemeSource? = None
14 public var underline: Color? = None
15 public var key: ViewKey = ViewKey.Position
16 public var semantics: ComponentSemantics = ComponentSemantics()
18 public fun settings(configure: ParagraphStyleBuilder.() -> Unit): Unit {
19 settings = Some((settings ?: paragraphStyle()).copy(configure))
20 }
22 internal fun properties(text: LabelText, inlines: Array<InlineView> = []): LabelProps =
23 LabelProps(
24 text,
25 fonts,
26 settings,
27 inlines,
28 theme,
29 underline = underline,
30 semantics = semantics
31 )
34/** Plain text inherits the current theme and accepts a local span override. */
35public class PlainLabelBuilder internal constructor(): LabelBuilder() {
36 public var style: SpanStyle? = None
38 public fun style(configure: SpanStyleBuilder.() -> Unit): Unit {
39 style = Some(configureOptionalSpanStyle(style, configure))
40 }
42 internal fun snapshot(text: String): LabelProps = properties(LabelText.Plain(text, style))
45/** Styled text carries its own complete style and optional inline view bindings. */
46public class StyledLabelBuilder internal constructor(): LabelBuilder() {
47 public var inlines: Array<InlineView> = []
49 internal fun snapshot(content: StyledText): LabelProps =
50 properties(LabelText.Styled(content), inlines)
53internal fun makePlainLabel(text: String, configure: PlainLabelBuilder.() -> Unit): View {
54 val builder = PlainLabelBuilder()
55 builder.configure()
56 return labelView(builder.snapshot(text), builder.key)
59internal fun makeStyledLabel(content: StyledText, configure: StyledLabelBuilder.() -> Unit): View {
60 val builder = StyledLabelBuilder()
61 builder.configure()
62 return labelView(builder.snapshot(content), builder.key)
65private fun labelView(input: LabelProps, key: ViewKey): View =
66 component(input, { props, mount -> Label(props, scope = mount) }, key, Some(labelComparison))