scoop:scoop.ui.component:0.1.0
src/content/panel.scoop
Selected production source · src/content/panel.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.graphics.text.*5
import scoop.ui.*6
import scoop.ui.style.*8
/** Typed text or a custom view used by content components. */9
public enum PanelContent {10
Label(LabelProps), Custom(View)11
}13
public open class PanelBuilder internal constructor() {14
public var title: PanelContent? = None15
public var description: PanelContent? = None16
public var fonts: FontCollection? = None17
public var theme: ThemeSource? = None18
public var style: StyleOverride = styleOverride()19
public var key: ViewKey = ViewKey.Position20
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
}41
}43
internal fun panelCaption(44
content: PanelContent,45
base: TextStyle,46
fonts: FontCollection?,47
centered: Boolean = false48
): View =49
when (content) {50
case Custom(val view) -> view51
case Label(val input) -> component(52
LabelProps(53
input.text,54
if (!panelPresent(input.fonts))55
fonts56
else57
input.fonts,58
if (!panelPresent(input.settings) && centered)59
Some(paragraphStyle { this.alignment = TextAlignment.Center })60
else61
input.settings,62
input.inlines,63
input.theme,64
if (!panelPresent(input.baseStyle) && !panelPresent(input.theme))65
Some(base)66
else67
input.baseStyle,68
input.underline,69
input.semantics70
),71
{ current, mount -> Label(current, scope = mount) }72
)73
}75
internal fun panelFrame(76
content: View,77
padding: Insets = Insets(),78
visual: StyleOverride = styleOverride(),79
width: Double? = None,80
key: ViewKey = ViewKey.Position81
): View =82
frame(content) {83
this.padding = Some(padding)84
this.style = visual85
this.width = width86
this.key = key87
this.alignment = Alignment(AxisAlignment.Start, AxisAlignment.Start)88
}90
internal fun topBorder(color: Color): Border =91
Border.Physical(BorderEdges(top = BorderEdge(1.0, color)))93
internal fun bottomBorder(color: Color): Border =94
Border.Physical(BorderEdges(bottom = BorderEdge(1.0, color)))96
internal fun <T> panelPresent(value: T?): Boolean =97
when (value) {98
case Some(_) -> true;99
case None -> false100
}102
internal fun panelSlot(content: View, key: Long): View =103
panelFrame(content, key = ViewKey.Number(key))