scoop:scoop.ui.style.macos:0.1.0
platform/darwin/system.scoop
Selected production source · platform/darwin/system.scoop
1
package scoop.ui.style.macos3
import scoop.graphics.Color4
import scoop.ui.style.*6
/** Reads the current AppKit semantic colors in the requested appearance, on the main thread. */7
public fun macosSystemPalette(mode: ThemeMode = ThemeMode.Light): ThemePalette {8
@Unsafe9
{10
val values = systemColors(mode == ThemeMode.Dark)11
if (values.status == -1)12
throw IllegalStateException(Some("macOS system colors require the main thread"))13
if (values.status != 1)14
throw IllegalStateException(Some("cannot resolve macOS system colors as sRGB"))15
val foreground = values.label.color()16
val background = ColorPair(values.background.color(), foreground)17
val primary = ColorPair(values.accent.color(), values.selectedText.color())18
val selection = ColorPair(values.selection.color(), values.selectedText.color())19
val border = values.separator.color()20
val ring = values.focus.color()21
return ThemePalette(22
background,23
ColorPair(values.contentBackground.color(), foreground),24
ColorPair(values.contentBackground.color(), foreground),25
primary,26
ColorPair(values.control.color(), values.controlText.color()),27
ColorPair(values.unemphasizedSelection.color(), values.secondaryLabel.color()),28
selection,29
ColorPair(values.red.color(), values.selectedText.color()),30
border,31
border,32
ring,33
ChartPalette(34
values.blue.color(),35
values.teal.color(),36
values.green.color(),37
values.orange.color(),38
values.purple.color()39
),40
SidebarPalette(background, primary, selection, border, ring),41
values.disabled.color(),42
values.shadow.color().withAlpha(43
if (mode == ThemeMode.Dark)44
0.445
else46
0.147
)48
)49
}50
}52
@CLayout53
private struct SystemColor(54
val red: Double,55
val green: Double,56
val blue: Double,57
val alpha: Double58
) {59
fun color(): Color = Color(red, green, blue, alpha)60
}62
@CLayout63
private struct SystemColors(64
val status: Int,65
val background: SystemColor,66
val label: SystemColor,67
val contentBackground: SystemColor,68
val control: SystemColor,69
val controlText: SystemColor,70
val secondaryLabel: SystemColor,71
val accent: SystemColor,72
val selectedText: SystemColor,73
val selection: SystemColor,74
val unemphasizedSelection: SystemColor,75
val separator: SystemColor,76
val focus: SystemColor,77
val disabled: SystemColor,78
val red: SystemColor,79
val blue: SystemColor,80
val green: SystemColor,81
val orange: SystemColor,82
val purple: SystemColor,83
val teal: SystemColor,84
val shadow: SystemColor85
)87
@Extern(name = "scoop_ui_macos_system_colors")88
private fun systemColors(dark: Boolean): SystemColors