scoop:scoop.ui.style.macos:0.1.0
src/theme.scoop
Selected production source · src/theme.scoop
1
package scoop.ui.style.macos3
import scoop.graphics.*4
import scoop.graphics.text.*5
import scoop.surface.AnimationSpec6
import scoop.surface.Easing7
import scoop.time.Duration8
import scoop.ui.style.*10
/** Sequoia Aqua controls; palette changes never opt into Liquid Glass or native chrome. */11
public 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 = families21
this.fontSize = 13.022
this.lineHeight = Some(16.0 / 13.0)23
this.color = colors.background.foreground24
},25
caption = textStyle {26
this.families = families27
this.fontSize = 11.028
this.lineHeight = Some(14.0 / 11.0)29
this.color = colors.muted.foreground30
},31
action = textStyle {32
this.families = families33
this.fontSize = 13.034
this.lineHeight = Some(16.0 / 13.0)35
this.color = colors.background.foreground36
this.weight = 40037
}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 = mode65
motion {66
this.selection = Some(67
AnimationSpec68
.Tween(69
Duration.milliseconds(100L),70
Easing.cubicBezier(0.42, 0.0, 0.58, 1.0)71
)72
)73
}74
this.effects = effects75
}76
// Window, content and control backgrounds are separate Aqua semantic roles.77
val control = colors.secondary.background78
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
disabledFill84
)85
val accent = StateColors(86
colors.primary.background,87
colors.primary.background,88
mixThemeColor(colors.primary.background, Color.Black, 0.16),89
disabledFill90
)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.disabledText100
)101
val onAccent = StateColors(102
colors.primary.foreground, colors.primary.foreground,103
colors.primary.foreground, colors.disabledText104
)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.outset110
)111
val plain = surfacePart(112
metrics = metrics, fill = normal, border = edges, foreground = text, focus = focus113
) { 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.disabled119
),120
foreground = onAccent,121
focus = focus122
) { 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.outset127
),128
fill = StateColors.solid(colors.popover.background),129
border = StateColors.solid(colors.border),130
foreground = text,131
focus = focus132
) { 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.disabled139
),140
mark = onAccent,141
focus = focus142
)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.disabledText149
)150
return shapeTheme(151
tokens = tokens,152
surfaces = surfaceParts(153
plain = plain,154
action = action,155
outlinedAction = plain,156
elevated = elevated157
),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.outset162
),163
appearance = marker164
),165
radio = radioPart(166
metrics = RadioMetrics(167
Size(14.0, 14.0), Size(14.0, 14.0), 0.5, 4.5, focus.outset168
),169
appearance = marker170
),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 = text177
),178
configure = configure179
)180
}