Scoop API

scoop:scoop.ui.style:0.1.0

src/theme/values.scoop

Selected production source · src/theme/values.scoop

1package scoop.ui.style
3import scoop.graphics.*
4import scoop.graphics.text.TextStyle
5import scoop.surface.AnimationSpec
7public enum ThemeMode {
8 Light, Dark
9}
11public enum SurfaceKind {
12 Plain, Action, OutlinedAction, Elevated
15public enum SurfaceLayer {
16 Background, Foreground, All
19public enum CheckMark {
20 Off, On, Mixed
23public enum MixedMarkShape {
24 Bar, Square
27public enum Orientation {
28 Horizontal, Vertical
31public enum ScrollbarRegion {
32 Track, Thumb, Decrement, Increment
35/** Physical edges in logical units, shared by geometry and control layout. */
36public 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.0
41) {
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 result
51 }
54public struct Circle(val center: Point, val radius: Double) {
55 public val bounds: Rect
56 get() = Rect(center.x - radius, center.y - radius, radius * 2.0, radius * 2.0)
59public struct StrokeSegment(val start: Point, val bend: Point, val end: Point, val width: Double)
61public struct OutlineStyle(
62 val color: Color,
63 val width: Double,
64 val outset: Double,
65 val borderColor: Color? = None
68public struct OutlineRing(val outline: RoundedOutline, val border: BorderEdge)
70/** Samples are optional; callers own animations and pass this frame's values. */
71public 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 = false
81public struct SurfaceVisual(
82 val kind: SurfaceKind = SurfaceKind.Plain,
83 val interaction: InteractionVisual = InteractionVisual()
86public struct CheckboxVisual(
87 val mark: CheckMark = CheckMark.Off,
88 val interaction: InteractionVisual = InteractionVisual(),
89 val selectionProgress: Double? = None
92public struct RadioVisual(
93 val selected: Boolean = false,
94 val interaction: InteractionVisual = InteractionVisual(),
95 val selectionProgress: Double? = None
98public 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 = true
109public struct StateColors(
110 val normal: Color,
111 val hovered: Color,
112 val pressed: Color,
113 val disabled: Color
114) {
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 else
121 disabled
122 }
123 public companion object {
124 public fun solid(color: Color): StateColors = StateColors(color, color, color, color)
125 }
128public struct ColorPair(val background: Color, val foreground: Color)
130public struct ChartPalette(
131 val one: Color,
132 val two: Color,
133 val three: Color,
134 val four: Color,
135 val five: Color
138public struct SidebarPalette(
139 val background: ColorPair,
140 val primary: ColorPair,
141 val accent: ColorPair,
142 val border: Color,
143 val ring: Color
146public 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: Color
162) {
163 public fun copy(configure: ThemePaletteBuilder.() -> Unit = {}): ThemePalette =
164 configureThemePalette(this, configure)
167public class ThemeTypography internal constructor(
168 public val body: TextStyle,
169 public val caption: TextStyle,
170 public val action: TextStyle,
171 public val input: TextStyle
172) {
173 public fun copy(configure: ThemeTypographyBuilder.() -> Unit = {}): ThemeTypography =
174 configureThemeTypography(this, configure)
177public struct ThemeSpacing(val small: Double, val medium: Double, val large: Double)
179public struct ThemeCorners(val small: Double, val medium: Double, val large: Double)
181public 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)
190public enum MotionPreference {
191 Full, Reduced
194public 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? = None
199) {
200 public fun resolve(spec: AnimationSpec?): AnimationSpec? = if (preference ==
201 MotionPreference.Reduced
202 )
203 None
204 else
205 spec
207 public fun copy(configure: ThemeMotionBuilder.() -> Unit = {}): ThemeMotion =
208 configureThemeMotion(this, configure)
211public enum TextFieldTreatment {
212 Standard, Outlined
215public 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.Standard
226) {
227 public fun copy(configure: ThemeTokensBuilder.() -> Unit = {}): ThemeTokens =
228 configureThemeTokens(this, configure)
231public fun mixThemeColor(from: Color, to: Color, progress: Double): Color {
232 val t = themeUnit(progress)
233 if (t == 0.0) return from
234 if (t == 1.0) return to
235 val fromWeight = from.alpha * (1.0 - t)
236 val toWeight = to.alpha * t
237 val alpha = fromWeight + toWeight
238 if (alpha == 0.0) return Color.Transparent
239 // 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 alpha
245 )