Scoop API

scoop:scoop.ui.component:0.1.0

src/tabs/appearance.scoop

Selected production source · src/tabs/appearance.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.ui.style.*
6internal fun tabTextColor(
7 theme: Theme,
8 variant: TabsVariant,
9 selected: Boolean,
10 visual: InteractionVisual
11): Color {
12 val colors = theme.tokens.palette
13 if (theme.preferences.highContrast)
14 return tabContrastPair(theme, variant, selected, visual).foreground
15 val foreground = if (!visual.enabled && theme.tokens.disabledOpacity >= 1.0)
16 colors.disabledText
17 else if (selected || (visual.enabled && (visual.hovered || visual.pressed)))
18 colors.background.foreground
19 else if (theme.tokens.mode == ThemeMode.Dark)
20 colors.muted.foreground
21 else
22 colors.background.foreground.withAlpha(colors.background.foreground.alpha * 0.6)
23 val fill = tabFill(theme, variant, selected, visual)
24 return componentBackground(
25 theme, foreground,
26 if (fill.alpha == 0.0) tabBackground(theme, variant) else fill
27 )
30private fun tabBackground(theme: Theme, variant: TabsVariant): Color = if (variant ==
31 TabsVariant.Default
33 theme.tokens.palette.muted.background
34else
35 theme.tokens.palette.background.background
37private fun tabContrastPair(
38 theme: Theme,
39 variant: TabsVariant,
40 selected: Boolean,
41 visual: InteractionVisual
42): ColorPair {
43 val colors = theme.tokens.palette
44 if (selected && variant == TabsVariant.Default)
45 return ColorPair(
46 colors.background.background,
47 if (visual.enabled) colors.background.foreground else colors.disabledText
48 )
49 if (visual.enabled && (visual.hovered || visual.pressed)) return colors.accent
50 if (variant == TabsVariant.Default) return colors.muted
51 return ColorPair(
52 colors.background.background,
53 if (visual.enabled) colors.background.foreground else colors.disabledText
54 )
57private fun tabFill(
58 theme: Theme,
59 variant: TabsVariant,
60 selected: Boolean,
61 visual: InteractionVisual
62): Color {
63 val colors = theme.tokens.palette
64 val dark = theme.tokens.mode == ThemeMode.Dark
65 val filled = selected && variant == TabsVariant.Default
66 val normal = if (!filled)
67 Color.Transparent
68 else if (dark)
69 colors.input.withAlpha(colors.input.alpha * 0.3)
70 else
71 colors.background.background
72 val pressed = if (!filled)
73 colors.background.foreground.withAlpha(colors.background.foreground.alpha * 0.08)
74 else
75 mixThemeColor(normal, colors.background.foreground, 0.08)
76 return if (theme.preferences.highContrast)
77 if (filled || (visual.enabled && (visual.hovered || visual.pressed)))
78 tabContrastPair(theme, variant, selected, visual).background
79 else
80 Color.Transparent
81 else
82 componentBackground(
83 theme,
84 StateColors(normal, normal, pressed, normal).resolve(visual),
85 tabBackground(theme, variant)
86 )
89internal fun tabOptions(
90 theme: Theme,
91 variant: TabsVariant,
92 selected: Boolean,
93 style: ButtonStyle,
94 visual: InteractionVisual
95): SurfaceOptions {
96 val colors = theme.tokens.palette
97 val dark = theme.tokens.mode == ThemeMode.Dark
98 val density = theme.tokens.typography.action.fontSize / 14.0
99 val filled = selected && variant == TabsVariant.Default
100 val fill = tabFill(theme, variant, selected, visual)
101 val local = styleOverride {
102 this.background(Some(Paint(fill)))
103 this
104 .border(
105 Some(
106 Border
107 .all(
108 density,
109 if (filled && (dark || theme.preferences.highContrast))
110 colors.input
111 else
112 Color.Transparent
113 )
114 )
115 )
116 this.corners(Corners.all(theme.tokens.corners.medium))
117 this.boxShadows([])
118 }
119 .then(style.surface.style)
120 return style
121 .surface
122 .copy {
123 if (this.suggestedSize == None) this.suggestedSize = Some(Size(0.0, 26.0 * density))
124 if (this.minimumSize == None) this.minimumSize = Some(Size(0.0, 0.0))
125 if (this.padding == None)
126 this.padding = Some(
127 Insets(6.0 * density, 2.0 * density, 6.0 * density, 2.0 * density)
128 )
129 this.style = style.states.apply(local, visual)
130 }