Scoop API

scoop:scoop.ui.component:0.1.0

src/builders/badge.scoop

Selected production source · src/builders/badge.scoop

1package scoop.ui.component
3import scoop.graphics.text.*
4import scoop.ui.*
5import scoop.ui.style.ThemeSource
6import scoop.ui.text.InlineView
8public open class ContentBadgeBuilder internal constructor() {
9 public var onClick: (() -> Unit)? = None
10 public var variant: ButtonVariant = ButtonVariant.Default
11 public var enabled: Boolean = true
12 public var invalid: Boolean = false
13 public var style: ButtonStyle = buttonStyle()
14 public var theme: ThemeSource? = None
15 public var focus: FocusOptions = FocusOptions()
16 public var key: ViewKey = ViewKey.Position
17 public var semantics: ComponentSemantics = ComponentSemantics()
18 public fun style(configure: ButtonStyleBuilder.() -> Unit): Unit {
19 style = style.copy(configure)
20 }
21 public fun focus(configure: FocusOptionsBuilder.() -> Unit): Unit {
22 focus = focus.copy(configure)
23 }
24 internal fun snapshot(content: ButtonContent): BadgeProps =
25 BadgeProps(content, onClick, variant, enabled, invalid, style, theme, focus, semantics)
28public open class BadgeBuilder internal constructor(): ContentBadgeBuilder() {
29 public var fonts: FontCollection? = None
32public class StyledBadgeBuilder internal constructor(): BadgeBuilder() {
33 public var settings: ParagraphStyle? = None
34 public var inlines: Array<InlineView> = []
35 public fun settings(configure: ParagraphStyleBuilder.() -> Unit): Unit {
36 settings = Some((settings ?: paragraphStyle()).copy(configure))
37 }
40internal fun makeTextBadge(text: String, configure: BadgeBuilder.() -> Unit): View {
41 val builder = BadgeBuilder()
42 builder.configure()
43 return badgeView(
44 builder.snapshot(
45 ButtonContent.Label(LabelProps(LabelText.Plain(text, None), builder.fonts))
46 ),
47 builder.key
48 )
51internal fun makeStyledBadge(text: StyledText, configure: StyledBadgeBuilder.() -> Unit): View {
52 val builder = StyledBadgeBuilder()
53 builder.configure()
54 return badgeView(
55 builder.snapshot(
56 ButtonContent.Label(
57 LabelProps(LabelText.Styled(text), builder.fonts, builder.settings, builder.inlines)
58 )
59 ),
60 builder.key
61 )
64internal fun makeContentBadge(content: View, configure: ContentBadgeBuilder.() -> Unit): View {
65 val builder = ContentBadgeBuilder()
66 builder.configure()
67 return badgeView(builder.snapshot(ButtonContent.Custom(content)), builder.key)
70internal fun makeResolvedBadge(
71 content: (ActionContentStyle) -> View,
72 configure: ContentBadgeBuilder.() -> Unit
73): View {
74 val builder = ContentBadgeBuilder()
75 builder.configure()
76 return badgeView(builder.snapshot(ButtonContent.Resolved(content)), builder.key)
79private fun badgeView(input: BadgeProps, key: ViewKey): View =
80 component(input, { current, mount -> Badge(current, scope = mount) }, key)