scoop:scoop.ui.style:0.1.0
src/theme/values.scoop
Selected production source · src/theme/values.scoop
1
package scoop.ui.style3
import scoop.graphics.*4
import scoop.graphics.text.TextStyle5
import scoop.surface.AnimationSpec7
public enum ThemeMode {8
Light, Dark9
}11
public enum SurfaceKind {12
Plain, Action, OutlinedAction, Elevated13
}15
public enum SurfaceLayer {16
Background, Foreground, All17
}19
public enum CheckMark {20
Off, On, Mixed21
}23
public enum MixedMarkShape {24
Bar, Square25
}27
public enum Orientation {28
Horizontal, Vertical29
}31
public enum ScrollbarRegion {32
Track, Thumb, Decrement, Increment33
}35
/** Physical edges in logical units, shared by geometry and control layout. */36
public struct Insets(37
val left: Double = 0.0,38
val top: Double = 0.0,39
val right: Double = 0.0,40
val bottom: Double = 0.041
) {42
public companion object {43
public fun all(value: Double): Insets = Insets(value, value, value, value)44
}45
public fun totals(): Size {46
for (value in [left, top, right, bottom])47
themeLength(value)48
val result = Size(left + right, top + bottom)49
themeSize(result)50
return result51
}52
}54
public struct Circle(val center: Point, val radius: Double) {55
public val bounds: Rect56
get() = Rect(center.x - radius, center.y - radius, radius * 2.0, radius * 2.0)57
}59
public struct StrokeSegment(val start: Point, val bend: Point, val end: Point, val width: Double)61
public struct OutlineStyle(62
val color: Color,63
val width: Double,64
val outset: Double,65
val borderColor: Color? = None66
)68
public struct OutlineRing(val outline: RoundedOutline, val border: BorderEdge)70
/** Samples are optional; callers own animations and pass this frame's values. */71
public struct InteractionVisual(72
val enabled: Boolean = true,73
val hovered: Boolean = false,74
val pressed: Boolean = false,75
val focusVisible: Boolean = false,76
val hoverProgress: Double? = None,77
val pressProgress: Double? = None,78
val invalid: Boolean = false79
)81
public struct SurfaceVisual(82
val kind: SurfaceKind = SurfaceKind.Plain,83
val interaction: InteractionVisual = InteractionVisual()84
)86
public struct CheckboxVisual(87
val mark: CheckMark = CheckMark.Off,88
val interaction: InteractionVisual = InteractionVisual(),89
val selectionProgress: Double? = None90
)92
public struct RadioVisual(93
val selected: Boolean = false,94
val interaction: InteractionVisual = InteractionVisual(),95
val selectionProgress: Double? = None96
)98
public struct ScrollbarVisual(99
val orientation: Orientation = Orientation.Vertical,100
val position: Double = 0.0,101
val visibleFraction: Double = 0.25,102
val enabled: Boolean = true,103
val hoveredPart: ScrollbarRegion? = None,104
val pressedPart: ScrollbarRegion? = None,105
val opacity: Double = 1.0,106
val showTrack: Boolean = true107
)109
public struct StateColors(110
val normal: Color,111
val hovered: Color,112
val pressed: Color,113
val disabled: Color114
) {115
public fun resolve(visual: InteractionVisual): Color {116
val hover = themeProgress(visual.hoverProgress, visual.hovered)117
val press = themeProgress(visual.pressProgress, visual.pressed)118
return if (visual.enabled)119
mixThemeColor(mixThemeColor(normal, hovered, hover), pressed, press)120
else121
disabled122
}123
public companion object {124
public fun solid(color: Color): StateColors = StateColors(color, color, color, color)125
}126
}128
public struct ColorPair(val background: Color, val foreground: Color)130
public struct ChartPalette(131
val one: Color,132
val two: Color,133
val three: Color,134
val four: Color,135
val five: Color136
)138
public struct SidebarPalette(139
val background: ColorPair,140
val primary: ColorPair,141
val accent: ColorPair,142
val border: Color,143
val ring: Color144
)146
public class ThemePalette public constructor(147
public val background: ColorPair,148
public val card: ColorPair,149
public val popover: ColorPair,150
public val primary: ColorPair,151
public val secondary: ColorPair,152
public val muted: ColorPair,153
public val accent: ColorPair,154
public val destructive: ColorPair,155
public val border: Color,156
public val input: Color,157
public val ring: Color,158
public val chart: ChartPalette,159
public val sidebar: SidebarPalette,160
public val disabledText: Color,161
public val shadow: Color162
) {163
public fun copy(configure: ThemePaletteBuilder.() -> Unit = {}): ThemePalette =164
configureThemePalette(this, configure)165
}167
public class ThemeTypography internal constructor(168
public val body: TextStyle,169
public val caption: TextStyle,170
public val action: TextStyle,171
public val input: TextStyle172
) {173
public fun copy(configure: ThemeTypographyBuilder.() -> Unit = {}): ThemeTypography =174
configureThemeTypography(this, configure)175
}177
public struct ThemeSpacing(val small: Double, val medium: Double, val large: Double)179
public struct ThemeCorners(val small: Double, val medium: Double, val large: Double)181
public class ThemeEffects internal constructor(182
public val raised: Array<BoxShadow> = [],183
public val floating: Array<BoxShadow> = [],184
public val emphasis: Array<ContentEffect> = []185
) {186
public fun copy(configure: ThemeEffectsBuilder.() -> Unit = {}): ThemeEffects =187
configureThemeEffects(this, configure)188
}190
public enum MotionPreference {191
Full, Reduced192
}194
public class ThemeMotion internal constructor(195
public val preference: MotionPreference = MotionPreference.Full,196
public val hover: AnimationSpec? = None,197
public val press: AnimationSpec? = None,198
public val selection: AnimationSpec? = None199
) {200
public fun resolve(spec: AnimationSpec?): AnimationSpec? = if (preference ==201
MotionPreference.Reduced202
)203
None204
else205
spec207
public fun copy(configure: ThemeMotionBuilder.() -> Unit = {}): ThemeMotion =208
configureThemeMotion(this, configure)209
}211
public enum TextFieldTreatment {212
Standard, Outlined213
}215
public class ThemeTokens internal constructor(216
public val mode: ThemeMode = ThemeMode.Light,217
public val palette: ThemePalette,218
public val typography: ThemeTypography,219
public val spacing: ThemeSpacing,220
public val motion: ThemeMotion = themeMotion(),221
public val corners: ThemeCorners,222
public val validation: OutlineStyle,223
public val effects: ThemeEffects = themeEffects(),224
public val disabledOpacity: Double = 1.0,225
public val textField: TextFieldTreatment = TextFieldTreatment.Standard226
) {227
public fun copy(configure: ThemeTokensBuilder.() -> Unit = {}): ThemeTokens =228
configureThemeTokens(this, configure)229
}231
public fun mixThemeColor(from: Color, to: Color, progress: Double): Color {232
val t = themeUnit(progress)233
if (t == 0.0) return from234
if (t == 1.0) return to235
val fromWeight = from.alpha * (1.0 - t)236
val toWeight = to.alpha * t237
val alpha = fromWeight + toWeight238
if (alpha == 0.0) return Color.Transparent239
// Interpolate premultiplied channels so invisible RGB cannot tint the transition.240
return Color(241
(from.red * fromWeight + to.red * toWeight) / alpha,242
(from.green * fromWeight + to.green * toWeight) / alpha,243
(from.blue * fromWeight + to.blue * toWeight) / alpha,244
alpha245
)246
}