Scoop API

scoop:scoop.ui.component:0.1.0

src/content/panel.scoop

Selected production source · src/content/panel.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.graphics.text.*
5import scoop.ui.*
6import scoop.ui.style.*
8/** Typed text or a custom view used by content components. */
9public enum PanelContent {
10 Label(LabelProps), Custom(View)
13public open class PanelBuilder internal constructor() {
14 public var title: PanelContent? = None
15 public var description: PanelContent? = None
16 public var fonts: FontCollection? = None
17 public var theme: ThemeSource? = None
18 public var style: StyleOverride = styleOverride()
19 public var key: ViewKey = ViewKey.Position
20 public fun title(text: String): Unit {
21 title = Some(PanelContent.Label(LabelProps(LabelText.Plain(text, None))))
22 }
23 public fun title(text: StyledText): Unit {
24 title = Some(PanelContent.Label(LabelProps(LabelText.Styled(text))))
25 }
26 public fun title(content: View): Unit {
27 title = Some(PanelContent.Custom(content))
28 }
29 public fun description(text: String): Unit {
30 description = Some(PanelContent.Label(LabelProps(LabelText.Plain(text, None))))
31 }
32 public fun description(text: StyledText): Unit {
33 description = Some(PanelContent.Label(LabelProps(LabelText.Styled(text))))
34 }
35 public fun description(content: View): Unit {
36 description = Some(PanelContent.Custom(content))
37 }
38 public fun style(configure: StyleOverrideBuilder.() -> Unit): Unit {
39 style = style.copy(configure)
40 }
43internal fun panelCaption(
44 content: PanelContent,
45 base: TextStyle,
46 fonts: FontCollection?,
47 centered: Boolean = false
48): View =
49 when (content) {
50 case Custom(val view) -> view
51 case Label(val input) -> component(
52 LabelProps(
53 input.text,
54 if (!panelPresent(input.fonts))
55 fonts
56 else
57 input.fonts,
58 if (!panelPresent(input.settings) && centered)
59 Some(paragraphStyle { this.alignment = TextAlignment.Center })
60 else
61 input.settings,
62 input.inlines,
63 input.theme,
64 if (!panelPresent(input.baseStyle) && !panelPresent(input.theme))
65 Some(base)
66 else
67 input.baseStyle,
68 input.underline,
69 input.semantics
70 ),
71 { current, mount -> Label(current, scope = mount) }
72 )
73 }
75internal fun panelFrame(
76 content: View,
77 padding: Insets = Insets(),
78 visual: StyleOverride = styleOverride(),
79 width: Double? = None,
80 key: ViewKey = ViewKey.Position
81): View =
82 frame(content) {
83 this.padding = Some(padding)
84 this.style = visual
85 this.width = width
86 this.key = key
87 this.alignment = Alignment(AxisAlignment.Start, AxisAlignment.Start)
88 }
90internal fun topBorder(color: Color): Border =
91 Border.Physical(BorderEdges(top = BorderEdge(1.0, color)))
93internal fun bottomBorder(color: Color): Border =
94 Border.Physical(BorderEdges(bottom = BorderEdge(1.0, color)))
96internal fun <T> panelPresent(value: T?): Boolean =
97 when (value) {
98 case Some(_) -> true;
99 case None -> false
100 }
102internal fun panelSlot(content: View, key: Long): View =
103 panelFrame(content, key = ViewKey.Number(key))