scoop:scoop.ui.component:0.1.0
src/color_preferences.scoop
Selected production source · src/color_preferences.scoop
1
package scoop.ui.component3
import scoop.graphics.Color4
import scoop.ui.style.*6
/** Resolve default translucent decoration over its known surface, preserving absent fills. */7
internal fun componentBackground(8
theme: Theme,9
color: Color,10
background: Color = theme.tokens.palette.background.background11
): Color =12
if (13
(theme.preferences.highContrast || theme.preferences.reduceTransparency) &&14
color.alpha >15
0.0 &&16
color.alpha <17
1.018
)19
mixThemeColor(background, color.withAlpha(1.0), color.alpha)20
else21
color23
/** High contrast colors have already been resolved against this theme surface. */24
internal fun componentTint(25
theme: Theme,26
color: Color,27
amount: Double,28
background: Color = theme.tokens.palette.background.background29
): Color =30
if (amount == 0.0)31
Color.Transparent32
else33
if (theme.preferences.highContrast)34
color35
else36
componentBackground(theme, color.withAlpha(color.alpha * amount), background)38
internal fun componentFocusWidth(theme: Theme, width: Double): Double =39
if (theme.preferences.highContrast)40
lowerBound(2.0, width)41
else42
width44
/** Default text and edges use their actual, already resolved opaque surface. */45
internal fun componentForeground(46
theme: Theme,47
color: Color,48
background: Color,49
minimum: Double = 7.050
): Color =51
if (theme.preferences.highContrast)52
contrastThemeColors(ColorPair(background, color), background, minimum).foreground53
else54
componentBackground(theme, color, background)56
internal 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.Transparent63
else64
resolved.background,65
resolved.foreground66
)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
canvas76
else77
background78
)79
)80
}82
internal 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)88
internal fun componentPanelSection(theme: Theme, surface: ColorPair): Color =89
if (theme.preferences.highContrast)90
surface.background91
else92
componentBackground(93
theme,94
theme.tokens.palette.muted.background.withAlpha(95
theme.tokens.palette.muted.background.alpha * 0.596
),97
surface.background98
)