scoop:scoop.ui.component:0.1.0
src/actions/toggle_appearance.scoop
Selected production source · src/actions/toggle_appearance.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.ui.style.*6
internal fun toggleOptions(7
theme: Theme,8
variant: ToggleVariant,9
size: ToggleSize,10
selected: Boolean,11
style: ButtonStyle,12
visual: InteractionVisual13
): SurfaceOptions {14
val colors = theme.tokens.palette15
val density = theme.tokens.typography.action.fontSize / 14.016
val height =17
when (size) {18
case Sm -> 28.0;19
case Default -> 32.0;20
case Lg -> 36.021
} *22
density23
val normal =24
if (selected)25
colors.muted.background26
else27
Color.Transparent28
val sampled =29
StateColors(30
normal,31
colors.muted.background,32
mixThemeColor(colors.muted.background, colors.background.foreground, 0.08),33
normal34
).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
visual43
).background44
else45
Color.Transparent46
else47
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
else56
None57
)58
this.corners(59
Corners.all(60
if (size == ToggleSize.Sm)61
upperBound(theme.tokens.corners.medium, 12.0)62
else63
theme.tokens.corners.large64
)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
}77
}