scoop:scoop.ui.component:0.1.0
src/builders/label.scoop
Selected production source · src/builders/label.scoop
1
package scoop.ui.component3
import scoop.graphics.Color4
import scoop.graphics.text.*5
import scoop.ui.*6
import scoop.ui.style.ThemeSource7
import scoop.ui.text.InlineView9
/** Common options for both text models; configuration never acquires fonts. */10
public open class LabelBuilder internal constructor() {11
public var fonts: FontCollection? = None12
public var settings: ParagraphStyle? = None13
public var theme: ThemeSource? = None14
public var underline: Color? = None15
public var key: ViewKey = ViewKey.Position16
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 = semantics31
)32
}34
/** Plain text inherits the current theme and accepts a local span override. */35
public class PlainLabelBuilder internal constructor(): LabelBuilder() {36
public var style: SpanStyle? = None38
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))43
}45
/** Styled text carries its own complete style and optional inline view bindings. */46
public class StyledLabelBuilder internal constructor(): LabelBuilder() {47
public var inlines: Array<InlineView> = []49
internal fun snapshot(content: StyledText): LabelProps =50
properties(LabelText.Styled(content), inlines)51
}53
internal fun makePlainLabel(text: String, configure: PlainLabelBuilder.() -> Unit): View {54
val builder = PlainLabelBuilder()55
builder.configure()56
return labelView(builder.snapshot(text), builder.key)57
}59
internal fun makeStyledLabel(content: StyledText, configure: StyledLabelBuilder.() -> Unit): View {60
val builder = StyledLabelBuilder()61
builder.configure()62
return labelView(builder.snapshot(content), builder.key)63
}65
private fun labelView(input: LabelProps, key: ViewKey): View =66
component(input, { props, mount -> Label(props, scope = mount) }, key, Some(labelComparison))