Scoop API

scoop:scoop.ui.component:0.1.0

src/color_preferences.scoop

Selected production source · src/color_preferences.scoop

1package scoop.ui.component
3import scoop.graphics.Color
4import scoop.ui.style.*
6/** Resolve default translucent decoration over its known surface, preserving absent fills. */
7internal fun componentBackground(
8 theme: Theme,
9 color: Color,
10 background: Color = theme.tokens.palette.background.background
11): Color =
12 if (
13 (theme.preferences.highContrast || theme.preferences.reduceTransparency) &&
14 color.alpha >
15 0.0 &&
16 color.alpha <
17 1.0
18 )
19 mixThemeColor(background, color.withAlpha(1.0), color.alpha)
20 else
21 color
23/** High contrast colors have already been resolved against this theme surface. */
24internal fun componentTint(
25 theme: Theme,
26 color: Color,
27 amount: Double,
28 background: Color = theme.tokens.palette.background.background
29): Color =
30 if (amount == 0.0)
31 Color.Transparent
32 else
33 if (theme.preferences.highContrast)
34 color
35 else
36 componentBackground(theme, color.withAlpha(color.alpha * amount), background)
38internal fun componentFocusWidth(theme: Theme, width: Double): Double =
39 if (theme.preferences.highContrast)
40 lowerBound(2.0, width)
41 else
42 width
44/** Default text and edges use their actual, already resolved opaque surface. */
45internal fun componentForeground(
46 theme: Theme,
47 color: Color,
48 background: Color,
49 minimum: Double = 7.0
50): Color =
51 if (theme.preferences.highContrast)
52 contrastThemeColors(ColorPair(background, color), background, minimum).foreground
53 else
54 componentBackground(theme, color, background)
56internal fun componentSurfaceColors(theme: Theme, pair: ColorPair, canvas: Color): ColorPair {
57 if (theme.preferences.highContrast) {
58 val resolved = contrastThemeColors(pair, canvas)
59 // No fill keeps the host's already resolved surface behind this content.
60 return ColorPair(
61 if (pair.background.alpha == 0.0)
62 Color.Transparent
63 else
64 resolved.background,
65 resolved.foreground
66 )
67 }
68 val background = componentBackground(theme, pair.background, canvas)
69 return ColorPair(
70 background,
71 componentBackground(
72 theme,
73 pair.foreground,
74 if (background.alpha == 0.0)
75 canvas
76 else
77 background
78 )
79 )
82internal fun componentPanelBorder(
83 theme: Theme,
84 surface: ColorPair,
85 normal: Color = theme.tokens.palette.background.foreground.withAlpha(0.1)
86): Color = componentForeground(theme, normal, surface.background, 3.0)
88internal fun componentPanelSection(theme: Theme, surface: ColorPair): Color =
89 if (theme.preferences.highContrast)
90 surface.background
91 else
92 componentBackground(
93 theme,
94 theme.tokens.palette.muted.background.withAlpha(
95 theme.tokens.palette.muted.background.alpha * 0.5
96 ),
97 surface.background
98 )