Scoop API

scoop:scoop.ui.component:0.1.0

src/actions/content.scoop

Selected production source · src/actions/content.scoop

1package scoop.ui.component
3import scoop.graphics.text.*
4import scoop.ui.*
5import scoop.ui.style.InteractionVisual
7internal fun actionLineHeight(shape: ActionShape): Double? =
8 when (shape) {
9 case Tab(_, _) -> Some(20.0 / 14.0)
10 case Toggle(_, val size, _) -> Some(
11 20.0 /
12 (
13 if (size == ToggleSize.Sm)
14 12.8
15 else
16 14.0
17 )
18 )
19 case Badge -> Some(16.0 / 12.0)
20 case Button(val size) -> when (size) {
21 case Xs -> Some(16.0 / 12.0)
22 case IconXs -> Some(16.0 / 12.0)
23 case Sm -> Some(20.0 / 12.8)
24 case IconSm -> Some(20.0 / 12.8)
25 else -> None
26 }
27 }
29internal fun actionContentStyle(
30 text: TextStyle,
31 shape: ActionShape,
32 variant: ButtonVariant,
33 visual: InteractionVisual
34): ActionContentStyle {
35 val scale = text.fontSize / (14.0 * actionFontScale(shape))
36 return ActionContentStyle(
37 text,
38 actionIconSize(shape) * scale,
39 actionSpacing(shape) * scale,
40 visual,
41 variant == ButtonVariant.Link && visual.enabled && visual.hovered
42 )
45internal fun actionContent(content: ButtonContent, appearance: ActionContentStyle): View =
46 when (content) {
47 case Custom(val view) -> view
48 case Resolved(val build) -> build(appearance)
49 case Label(val label) -> {
50 val base =
51 when (label.baseStyle) {
52 case Some(val value) -> Some(value)
53 case None -> when (label.theme) {
54 case Some(_) -> None
55 case None -> Some(appearance.text)
56 }
57 }
58 component(
59 LabelProps(
60 label.text,
61 label.fonts,
62 label.settings,
63 label.inlines,
64 label.theme,
65 base,
66 if (label.underline == None && appearance.underline)
67 Some(appearance.text.color)
68 else
69 label.underline,
70 label.semantics
71 ),
72 { current, mount -> Label(current, scope = mount) }
73 )
74 }
75 }