Scoop API

scoop:scoop.ui.style.macos:0.1.0

src/theme.scoop

Selected production source · src/theme.scoop

1package scoop.ui.style.macos
3import scoop.graphics.*
4import scoop.graphics.text.*
5import scoop.surface.AnimationSpec
6import scoop.surface.Easing
7import scoop.time.Duration
8import scoop.ui.style.*
10/** Sequoia Aqua controls; palette changes never opt into Liquid Glass or native chrome. */
11public fun macosTheme(
12 mode: ThemeMode = ThemeMode.Light,
13 palette: ThemePalette? = None,
14 configure: ShapeThemeBuilder.() -> Unit = {}
15): ShapeTheme {
16 val colors = palette ?: macosPalette(mode)
17 val families = [".AppleSystemUIFont", "Helvetica Neue", "sans-serif"]
18 val fonts = themeTypography(
19 body = textStyle {
20 this.families = families
21 this.fontSize = 13.0
22 this.lineHeight = Some(16.0 / 13.0)
23 this.color = colors.background.foreground
24 },
25 caption = textStyle {
26 this.families = families
27 this.fontSize = 11.0
28 this.lineHeight = Some(14.0 / 11.0)
29 this.color = colors.muted.foreground
30 },
31 action = textStyle {
32 this.families = families
33 this.fontSize = 13.0
34 this.lineHeight = Some(16.0 / 13.0)
35 this.color = colors.background.foreground
36 this.weight = 400
37 }
38 )
39 val effects = themeEffects {
40 this.raised = [
41 BoxShadow(
42 Point(0.0, 1.0), 0.5, 0.5,
43 colors.shadow.withAlpha(colors.shadow.alpha * 0.5)
44 )
45 ]
46 this.floating = [
47 BoxShadow(Point(0.0, 6.0), 10.0, 10.0, colors.shadow),
48 BoxShadow(
49 Point(0.0, 0.0), 1.0, 1.0,
50 colors.shadow.withAlpha(colors.shadow.alpha * 0.5)
51 )
52 ]
53 }
54 val tokens = themeTokens(
55 palette = colors,
56 typography = fonts,
57 spacing = ThemeSpacing(4.0, 8.0, 12.0),
58 corners = ThemeCorners(3.0, 5.0, 8.0),
59 validation = OutlineStyle(
60 colors.destructive.background.withAlpha(0.72),
61 2.0, 2.0, Some(colors.destructive.background)
62 )
63 ) {
64 this.mode = mode
65 motion {
66 this.selection = Some(
67 AnimationSpec
68 .Tween(
69 Duration.milliseconds(100L),
70 Easing.cubicBezier(0.42, 0.0, 0.58, 1.0)
71 )
72 )
73 }
74 this.effects = effects
75 }
76 // Window, content and control backgrounds are separate Aqua semantic roles.
77 val control = colors.secondary.background
78 val disabledFill = control.withAlpha(control.alpha * 0.5)
79 val normal = StateColors(
80 control,
81 control,
82 mixThemeColor(control, colors.background.foreground, 0.12),
83 disabledFill
84 )
85 val accent = StateColors(
86 colors.primary.background,
87 colors.primary.background,
88 mixThemeColor(colors.primary.background, Color.Black, 0.16),
89 disabledFill
90 )
91 val edges = StateColors(
92 colors.input,
93 colors.input,
94 mixThemeColor(colors.input, colors.background.foreground, 0.12),
95 colors.input.withAlpha(colors.input.alpha * 0.5)
96 )
97 val text = StateColors(
98 colors.background.foreground, colors.background.foreground,
99 colors.background.foreground, colors.disabledText
100 )
101 val onAccent = StateColors(
102 colors.primary.foreground, colors.primary.foreground,
103 colors.primary.foreground, colors.disabledText
104 )
105 // Equal width/outset keeps the focus ring against the control, without an empty moat.
106 val focus = OutlineStyle(colors.ring, 3.0, 3.0)
107 val metrics = SurfaceMetrics(
108 Size(68.0, 22.0), Size(22.0, 22.0), Insets(10.0, 2.0, 10.0, 2.0),
109 Insets.all(0.5), CornerRadii.all(5.0), focus.outset
110 )
111 val plain = surfacePart(
112 metrics = metrics, fill = normal, border = edges, foreground = text, focus = focus
113 ) { this.shadows = effects.raised }
114 val action = surfacePart(
115 metrics = metrics,
116 fill = accent,
117 border = StateColors(
118 accent.normal, accent.hovered, accent.pressed, edges.disabled
119 ),
120 foreground = onAccent,
121 focus = focus
122 ) { this.shadows = effects.raised }
123 val elevated = surfacePart(
124 metrics = SurfaceMetrics(
125 Size(96.0, 64.0), Size(0.0, 0.0), Insets.all(12.0),
126 Insets.all(0.5), CornerRadii.all(8.0), focus.outset
127 ),
128 fill = StateColors.solid(colors.popover.background),
129 border = StateColors.solid(colors.border),
130 foreground = text,
131 focus = focus
132 ) { this.shadows = effects.floating }
133 val marker = markerAppearance(
134 empty = normal,
135 selected = accent,
136 border = edges,
137 selectedBorder = StateColors(
138 accent.normal, accent.hovered, accent.pressed, edges.disabled
139 ),
140 mark = onAccent,
141 focus = focus
142 )
143 val track = StateColors.solid(colors.muted.background)
144 val thumb = StateColors(
145 colors.background.foreground.withAlpha(colors.background.foreground.alpha * 0.55),
146 colors.background.foreground.withAlpha(colors.background.foreground.alpha * 0.70),
147 colors.background.foreground.withAlpha(colors.background.foreground.alpha * 0.85),
148 colors.disabledText
149 )
150 return shapeTheme(
151 tokens = tokens,
152 surfaces = surfaceParts(
153 plain = plain,
154 action = action,
155 outlinedAction = plain,
156 elevated = elevated
157 ),
158 checkbox = checkboxPart(
159 metrics = CheckboxMetrics(
160 Size(14.0, 14.0), Size(14.0, 14.0), Insets.all(0.5),
161 CornerRadii.all(3.0), 3.0, 1.5, focus.outset
162 ),
163 appearance = marker
164 ),
165 radio = radioPart(
166 metrics = RadioMetrics(
167 Size(14.0, 14.0), Size(14.0, 14.0), 0.5, 4.5, focus.outset
168 ),
169 appearance = marker
170 ),
171 scrollbar = scrollbarPart(
172 metrics = ScrollbarMetrics(15.0, 24.0, 0.0, 3.0, 6.0, None),
173 track = track,
174 thumb = thumb,
175 button = StateColors.solid(Color.Transparent),
176 arrow = text
177 ),
178 configure = configure
179 )