Scoop API

scoop:scoop.ui.style.material:0.1.0

src/palette.scoop

Selected production source · src/palette.scoop

1package scoop.ui.style.material
3import scoop.graphics.Color
4import scoop.ui.style.*
6/** Material Web's baseline M3 color roles, independent of the current system palette. */
7internal fun materialPalette(mode: ThemeMode): ThemePalette {
8 val dark = mode == ThemeMode.Dark
9 val surface = materialColor(if (dark) 0x141218 else 0xfef7ff)
10 val onSurface = materialColor(if (dark) 0xe6e0e9 else 0x1d1b20)
11 val low = materialColor(if (dark) 0x1d1b20 else 0xf7f2fa)
12 val container = materialColor(if (dark) 0x211f26 else 0xf3edf7)
13 val variant = materialColor(if (dark) 0x49454f else 0xe7e0ec)
14 val onVariant = materialColor(if (dark) 0xcac4d0 else 0x49454f)
15 val primary = ColorPair(
16 materialColor(if (dark) 0xd0bcff else 0x6750a4),
17 materialColor(if (dark) 0x381e72 else 0xffffff)
18 )
19 val secondary = materialColor(if (dark) 0xccc2dc else 0x625b71)
20 val tonal = ColorPair(
21 materialColor(if (dark) 0x4a4458 else 0xe8def8),
22 materialColor(if (dark) 0xe8def8 else 0x1d192b)
23 )
24 val outline = materialColor(if (dark) 0x938f99 else 0x79747e)
25 val outlineVariant = materialColor(if (dark) 0x49454f else 0xcac4d0)
26 val error = ColorPair(
27 materialColor(if (dark) 0xf2b8b5 else 0xb3261e),
28 materialColor(if (dark) 0x601410 else 0xffffff)
29 )
30 return ThemePalette(
31 background = ColorPair(surface, onSurface),
32 card = ColorPair(low, onSurface),
33 popover = ColorPair(container, onSurface),
34 primary = primary,
35 secondary = tonal,
36 muted = ColorPair(variant, onVariant),
37 accent = tonal,
38 destructive = error,
39 border = outlineVariant,
40 input = outline,
41 ring = secondary,
42 chart = ChartPalette(
43 primary.background, secondary,
44 materialColor(if (dark) 0xefb8c8 else 0x7d5260), error.background, outline
45 ),
46 sidebar = SidebarPalette(
47 ColorPair(low, onSurface),
48 primary,
49 tonal,
50 outlineVariant,
51 secondary
52 ),
53 disabledText = onSurface.withAlpha(0.38),
54 shadow = Color.Black
55 )
58private fun materialColor(value: Int): Color = Color(
59 (value / 65536).toDouble() / 255.0,
60 ((value / 256) % 256).toDouble() / 255.0,
61 (value % 256).toDouble() / 255.0