scoop:scoop.ui.component:0.1.0
src/slider/style.scoop
Selected production source · src/slider/style.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.surface.AnimationSpec5
import scoop.ui.style.*7
public class SliderStyle internal constructor(8
public val length: Double? = None,9
public val thickness: Double? = None,10
public val thumbSize: Double? = None,11
public val hitInsets: Insets? = None,12
public val track: StyleOverride = styleOverride(),13
public val range: StyleOverride = styleOverride(),14
public val thumb: StyleOverride = styleOverride(),15
public val states: InteractionStyles = interactionStyles(),16
public val transition: StyleValue<AnimationSpec?> = StyleValue.Inherit17
) {18
init {19
for (size in [length, thickness, thumbSize])20
when (size) {21
case Some(val value) -> nonnegative(value, "invalid slider dimension");22
case None -> {}23
}24
hitInsets?.totals()25
}26
public fun copy(configure: SliderStyleBuilder.() -> Unit = {}): SliderStyle {27
val builder = SliderStyleBuilder(this)28
builder.configure()29
return builder.snapshot()30
}31
}33
public fun sliderStyle(configure: SliderStyleBuilder.() -> Unit = {}): SliderStyle =34
SliderStyle().copy(configure)36
public class SliderStyleBuilder internal constructor(initial: SliderStyle) {37
public var length: Double? = initial.length38
public var thickness: Double? = initial.thickness39
public var thumbSize: Double? = initial.thumbSize40
public var hitInsets: Insets? = initial.hitInsets41
public var track: StyleOverride = initial.track42
public var range: StyleOverride = initial.range43
public var thumb: StyleOverride = initial.thumb44
public var states: InteractionStyles = initial.states45
public var transition: StyleValue<AnimationSpec?> = initial.transition46
public fun track(configure: StyleOverrideBuilder.() -> Unit) {47
track = track.copy(configure)48
}49
public fun range(configure: StyleOverrideBuilder.() -> Unit) {50
range = range.copy(configure)51
}52
public fun thumb(configure: StyleOverrideBuilder.() -> Unit) {53
thumb = thumb.copy(configure)54
}55
public fun states(configure: InteractionStylesBuilder.() -> Unit) {56
states = states.copy(configure)57
}58
public fun transition(value: AnimationSpec?) {59
transition = StyleValue.Set(value)60
}61
internal fun snapshot(): SliderStyle =62
SliderStyle(63
length,64
thickness,65
thumbSize,66
hitInsets,67
track,68
range,69
thumb,70
states,71
transition72
)73
}75
internal fun sliderPartStyle(color: Color, local: StyleOverride): Style =76
local.resolve(77
style {78
this.background = Some(Paint(color))79
this.corners = Corners.all(1000.0)80
}81
)83
internal fun sliderThumbOptions(84
theme: Theme,85
local: SliderStyle,86
visual: InteractionVisual87
): SurfaceOptions {88
val density = theme.tokens.typography.body.fontSize / 14.089
val amount =90
if (visual.focusVisible)91
1.092
else93
lowerBound(visual.hoverProgress ?: 0.0, visual.pressProgress ?: 0.0)94
val base =95
styleOverride {96
this.background(97
Some(98
Paint(99
if (theme.preferences.highContrast)100
theme.tokens.palette.background.background101
else102
Color.White103
)104
)105
)106
this.border(107
Some(108
Border.all(109
density,110
if (visual.invalid)111
theme.tokens.validation.borderColor ?: theme.tokens.validation.color112
else113
theme.tokens.palette.ring114
)115
)116
)117
this.corners(Corners.all(1000.0))118
}.then(local.thumb)119
return surfaceOptions {120
this.style = local.states.apply(base, visual)121
this.padding = Some(Insets())122
this.focus =123
Some(124
OutlineStyle(125
componentTint(theme, theme.tokens.palette.ring, 0.5 * amount),126
componentFocusWidth(theme, 3.0 * density),127
0.0128
)129
)130
}131
}