Scoop API

scoop:scoop.ui.component:0.1.0

src/actions/toggle_appearance.scoop

Selected production source · src/actions/toggle_appearance.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.ui.style.*
6internal fun toggleOptions(
7 theme: Theme,
8 variant: ToggleVariant,
9 size: ToggleSize,
10 selected: Boolean,
11 style: ButtonStyle,
12 visual: InteractionVisual
13): SurfaceOptions {
14 val colors = theme.tokens.palette
15 val density = theme.tokens.typography.action.fontSize / 14.0
16 val height =
17 when (size) {
18 case Sm -> 28.0;
19 case Default -> 32.0;
20 case Lg -> 36.0
21 } *
22 density
23 val normal =
24 if (selected)
25 colors.muted.background
26 else
27 Color.Transparent
28 val sampled =
29 StateColors(
30 normal,
31 colors.muted.background,
32 mixThemeColor(colors.muted.background, colors.background.foreground, 0.08),
33 normal
34 ).resolve(visual)
35 val fill =
36 if (theme.preferences.highContrast)
37 if (selected || (visual.enabled && (visual.hovered || visual.pressed)))
38 actionContrastPair(
39 theme,
40 ActionShape.Toggle(variant, size, selected),
41 ButtonVariant.Default,
42 visual
43 ).background
44 else
45 Color.Transparent
46 else
47 componentBackground(theme, sampled)
48 val border = controlBorder(theme, style.surface, visual, colors.input)
49 val local =
50 styleOverride {
51 this.background(Some(Paint(fill)))
52 this.border(
53 if (variant == ToggleVariant.Outline)
54 Some(Border.all(density, border))
55 else
56 None
57 )
58 this.corners(
59 Corners.all(
60 if (size == ToggleSize.Sm)
61 upperBound(theme.tokens.corners.medium, 12.0)
62 else
63 theme.tokens.corners.large
64 )
65 )
66 this.boxShadows([])
67 }.then(style.surface.style)
68 return style.surface.copy {
69 if (this.suggestedSize == None)
70 this.suggestedSize = Some(Size(height, height))
71 if (this.minimumSize == None)
72 this.minimumSize = Some(Size(0.0, 0.0))
73 if (this.padding == None)
74 this.padding = Some(Insets(10.0 * density, 0.0, 10.0 * density, 0.0))
75 this.style = style.states.apply(local, visual)
76 }