scoop:scoop.ui.style.fluent:0.1.0
src/theme.scoop
Selected production source · src/theme.scoop
1
package scoop.ui.style.fluent3
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
/** Fluent 2 Web colors, typography, flat controls and layered floating surfaces. */11
public fun fluentTheme(12
mode: ThemeMode = ThemeMode.Light,13
palette: ThemePalette? = None,14
configure: ShapeThemeBuilder.() -> Unit = {}15
): ShapeTheme {16
val dark = mode == ThemeMode.Dark17
val colors = palette ?: fluentPalette(mode)18
val custom = when (palette) {19
case Some(_) -> true;20
case None -> false21
}22
val families = [23
"Segoe UI",24
"Segoe UI Web (West European)",25
"Helvetica Neue",26
"Roboto",27
"sans-serif"28
]29
val fonts = themeTypography(30
body = textStyle {31
this.families = families32
this.fontSize = 14.033
this.lineHeight = Some(20.0 / 14.0)34
this.color = colors.background.foreground35
},36
caption = textStyle {37
this.families = families38
this.fontSize = 12.039
this.lineHeight = Some(16.0 / 12.0)40
this.color = colors.muted.foreground41
},42
action = textStyle {43
this.families = families44
this.fontSize = 14.045
this.lineHeight = Some(20.0 / 14.0)46
this.color = colors.background.foreground47
this.weight = 60048
}49
)50
// shadow4/shadow16: paint the key shadow first; CSS blur is twice Gaussian sigma.51
val ambientShadow = if (custom)52
colors.shadow.withAlpha(colors.shadow.alpha * 6.0 / 7.0)53
else54
Color.Black.withAlpha(if (dark) 0.24 else 0.12)55
val effects = themeEffects {56
this.raised = [57
BoxShadow(Point(0.0, 2.0), 2.0, 2.0, colors.shadow),58
BoxShadow(Point(0.0, 0.0), 1.0, 1.0, ambientShadow)59
]60
this.floating = [61
BoxShadow(Point(0.0, 8.0), 8.0, 8.0, colors.shadow),62
BoxShadow(Point(0.0, 0.0), 1.0, 1.0, ambientShadow)63
]64
}65
val tokens = themeTokens(66
palette = colors,67
typography = fonts,68
spacing = ThemeSpacing(4.0, 8.0, 16.0),69
corners = ThemeCorners(2.0, 4.0, 6.0),70
validation = OutlineStyle(71
colors.destructive.background.withAlpha(0.72),72
2.0, 2.0, Some(colors.destructive.background)73
)74
) {75
this.mode = mode76
motion {77
this.hover = tween(100L)78
this.press = tween(100L)79
}80
this.effects = effects81
}82
val disabledFill = if (custom)83
colors.muted.background84
else if (dark) fluentColor(0x141414) else fluentColor(0xf0f0f0)85
val disabledStroke = if (custom)86
colors.border87
else if (dark) fluentColor(0x424242) else fluentColor(0xe0e0e0)88
// Neutral background1 / stroke1 have separate hover, pressed and disabled tokens.89
val normal = StateColors(90
colors.card.background,91
if (custom)92
mixThemeColor(colors.card.background, colors.background.foreground, 0.04)93
else if (dark) fluentColor(0x3d3d3d) else fluentColor(0xf5f5f5),94
if (custom)95
mixThemeColor(colors.card.background, colors.background.foreground, 0.12)96
else if (dark) fluentColor(0x1f1f1f) else fluentColor(0xe0e0e0),97
disabledFill98
)99
val edges = StateColors(100
colors.input,101
if (custom)102
mixThemeColor(colors.input, colors.background.foreground, 0.12)103
else if (dark) fluentColor(0x757575) else fluentColor(0xc7c7c7),104
if (custom)105
mixThemeColor(colors.input, colors.background.foreground, 0.22)106
else if (dark) fluentColor(0x6b6b6b) else fluentColor(0xb3b3b3),107
disabledStroke108
)109
val text = StateColors(110
colors.background.foreground, colors.background.foreground,111
colors.background.foreground, colors.disabledText112
)113
val onAccent = StateColors(114
colors.primary.foreground, colors.primary.foreground,115
colors.primary.foreground, colors.disabledText116
)117
// BrandBackground is deliberately darker than CompoundBrandBackground in Dark mode.118
val accent = StateColors(119
colors.primary.background,120
if (custom)121
mixThemeColor(colors.primary.background, if (dark) Color.White else Color.Black, 0.10)122
else if (dark) fluentColor(0x0f6cbd) else fluentColor(0x115ea3),123
if (custom)124
mixThemeColor(colors.primary.background, Color.Black, 0.28)125
else126
fluentColor(0x0c3b5e),127
disabledFill128
)129
val focus = OutlineStyle(colors.ring, 2.0, 0.0, Some(colors.ring))130
val metrics = SurfaceMetrics(131
Size(96.0, 32.0), Size(32.0, 32.0), Insets(12.0, 5.0, 12.0, 5.0),132
Insets.all(1.0), CornerRadii.all(4.0), 2.0133
)134
val plain = surfacePart(135
metrics = metrics, fill = normal, border = edges, foreground = text, focus = focus136
)137
val action = surfacePart(138
metrics = metrics,139
fill = accent,140
border = StateColors.solid(Color.Transparent),141
foreground = onAccent,142
focus = focus143
)144
val elevated = surfacePart(145
metrics = SurfaceMetrics(146
Size(112.0, 64.0), Size(0.0, 0.0), Insets.all(12.0),147
Insets.all(1.0), CornerRadii.all(4.0), 2.0148
),149
fill = StateColors.solid(colors.popover.background),150
border = StateColors.solid(colors.border),151
foreground = text,152
focus = focus153
) { this.shadows = effects.floating }154
val compound = StateColors(155
if (custom)156
colors.primary.background157
else if (dark) fluentColor(0x479ef5) else fluentColor(0x0f6cbd),158
if (custom) accent.hovered else if (dark) fluentColor(0x62abf5) else fluentColor(0x115ea3),159
if (custom) accent.pressed else if (dark) fluentColor(0x2886de) else fluentColor(0x0f548c),160
disabledStroke161
)162
val markerEdges = StateColors(163
if (custom)164
colors.muted.foreground165
else if (dark) fluentColor(0xadadad) else fluentColor(0x616161),166
if (custom)167
mixThemeColor(colors.muted.foreground, colors.background.foreground, 0.2)168
else if (dark) fluentColor(0xbdbdbd) else fluentColor(0x575757),169
if (custom)170
mixThemeColor(colors.muted.foreground, colors.background.foreground, 0.4)171
else if (dark) fluentColor(0xb3b3b3) else fluentColor(0x4d4d4d),172
disabledStroke173
)174
val compoundMark = StateColors(175
compound.normal,176
compound.hovered,177
compound.pressed,178
colors.disabledText179
)180
val empty = StateColors.solid(Color.Transparent)181
val markerFocus = OutlineStyle(colors.ring, 2.0, 2.0)182
val marker = markerAppearance(183
empty = empty,184
selected = StateColors(185
compound.normal,186
compound.hovered,187
compound.pressed,188
Color.Transparent189
),190
border = markerEdges,191
selectedBorder = compound,192
mark = if (custom)193
onAccent194
else if (dark)195
StateColors(196
fluentColor(0x242424),197
fluentColor(0x242424),198
fluentColor(0x242424),199
colors.disabledText200
)201
else202
onAccent,203
focus = markerFocus204
)205
val outlinedMarker = markerAppearance(206
empty = empty, selected = empty, border = markerEdges,207
selectedBorder = compound, mark = compoundMark, focus = markerFocus208
)209
return shapeTheme(210
tokens = tokens,211
surfaces = surfaceParts(212
plain = plain,213
action = action,214
outlinedAction = plain,215
elevated = elevated216
),217
checkbox = checkboxPart(218
metrics = CheckboxMetrics(219
Size(16.0, 16.0), Size(16.0, 16.0), Insets.all(1.0),220
CornerRadii.all(2.0), 3.0, 1.5, 2.0221
),222
appearance = marker223
) {224
this.mixedAppearance = Some(outlinedMarker)225
this.mixedShape = MixedMarkShape.Square226
},227
radio = radioPart(228
metrics = RadioMetrics(Size(16.0, 16.0), Size(16.0, 16.0), 1.0, 3.0, 2.0),229
appearance = outlinedMarker230
),231
scrollbar = scrollbarPart(232
metrics = ScrollbarMetrics(12.0, 24.0, 0.0, 4.0, 2.0, None),233
track = StateColors.solid(colors.muted.background),234
thumb = StateColors(235
if (custom)236
colors.muted.foreground237
else if (dark) fluentColor(0xadadad) else fluentColor(0x8a8a8a),238
if (custom)239
mixThemeColor(colors.muted.foreground, colors.background.foreground, 0.25)240
else if (dark) fluentColor(0xc7c7c7) else fluentColor(0x707070),241
if (custom)242
mixThemeColor(colors.muted.foreground, colors.background.foreground, 0.5)243
else if (dark) fluentColor(0xd6d6d6) else fluentColor(0x616161),244
disabledStroke245
),246
button = normal,247
arrow = text248
),249
configure = configure250
)251
}253
private fun tween(milliseconds: Long): AnimationSpec? = Some(254
AnimationSpec255
.Tween(256
Duration.milliseconds(milliseconds),257
Easing.cubicBezier(0.33, 0.0, 0.67, 1.0)258
)259
)