scoop:scoop.ui.component:0.1.0
src/tabs/appearance.scoop
Selected production source · src/tabs/appearance.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.ui.style.*6
internal fun tabTextColor(7
theme: Theme,8
variant: TabsVariant,9
selected: Boolean,10
visual: InteractionVisual11
): Color {12
val colors = theme.tokens.palette13
if (theme.preferences.highContrast)14
return tabContrastPair(theme, variant, selected, visual).foreground15
val foreground = if (!visual.enabled && theme.tokens.disabledOpacity >= 1.0)16
colors.disabledText17
else if (selected || (visual.enabled && (visual.hovered || visual.pressed)))18
colors.background.foreground19
else if (theme.tokens.mode == ThemeMode.Dark)20
colors.muted.foreground21
else22
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 fill27
)28
}30
private fun tabBackground(theme: Theme, variant: TabsVariant): Color = if (variant ==31
TabsVariant.Default32
)33
theme.tokens.palette.muted.background34
else35
theme.tokens.palette.background.background37
private fun tabContrastPair(38
theme: Theme,39
variant: TabsVariant,40
selected: Boolean,41
visual: InteractionVisual42
): ColorPair {43
val colors = theme.tokens.palette44
if (selected && variant == TabsVariant.Default)45
return ColorPair(46
colors.background.background,47
if (visual.enabled) colors.background.foreground else colors.disabledText48
)49
if (visual.enabled && (visual.hovered || visual.pressed)) return colors.accent50
if (variant == TabsVariant.Default) return colors.muted51
return ColorPair(52
colors.background.background,53
if (visual.enabled) colors.background.foreground else colors.disabledText54
)55
}57
private fun tabFill(58
theme: Theme,59
variant: TabsVariant,60
selected: Boolean,61
visual: InteractionVisual62
): Color {63
val colors = theme.tokens.palette64
val dark = theme.tokens.mode == ThemeMode.Dark65
val filled = selected && variant == TabsVariant.Default66
val normal = if (!filled)67
Color.Transparent68
else if (dark)69
colors.input.withAlpha(colors.input.alpha * 0.3)70
else71
colors.background.background72
val pressed = if (!filled)73
colors.background.foreground.withAlpha(colors.background.foreground.alpha * 0.08)74
else75
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).background79
else80
Color.Transparent81
else82
componentBackground(83
theme,84
StateColors(normal, normal, pressed, normal).resolve(visual),85
tabBackground(theme, variant)86
)87
}89
internal fun tabOptions(90
theme: Theme,91
variant: TabsVariant,92
selected: Boolean,93
style: ButtonStyle,94
visual: InteractionVisual95
): SurfaceOptions {96
val colors = theme.tokens.palette97
val dark = theme.tokens.mode == ThemeMode.Dark98
val density = theme.tokens.typography.action.fontSize / 14.099
val filled = selected && variant == TabsVariant.Default100
val fill = tabFill(theme, variant, selected, visual)101
val local = styleOverride {102
this.background(Some(Paint(fill)))103
this104
.border(105
Some(106
Border107
.all(108
density,109
if (filled && (dark || theme.preferences.highContrast))110
colors.input111
else112
Color.Transparent113
)114
)115
)116
this.corners(Corners.all(theme.tokens.corners.medium))117
this.boxShadows([])118
}119
.then(style.surface.style)120
return style121
.surface122
.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
}131
}