Scoop API

scoop:scoop.ui.component:0.1.0

src/selection.scoop

Selected production source · src/selection.scoop

1package scoop.ui.component
3import scoop.graphics.Color
4import scoop.ui.style.*
5import scoop.ui.text.SelectableTextOptions
7internal struct ThemeTextSelection(
8 val background: Color,
9 val inactiveBackground: Color,
10 val text: Color?,
11 val inactiveText: Color?
14internal fun themeTextSelection(theme: Theme): ThemeTextSelection {
15 val palette = theme.tokens.palette
16 if (theme.preferences.highContrast)
17 return ThemeTextSelection(
18 palette.primary.background,
19 palette.secondary.background,
20 Some(palette.primary.foreground),
21 Some(palette.secondary.foreground)
22 )
23 val active = palette.primary.background.withAlpha(0.30)
24 val inactive = palette.muted.foreground.withAlpha(0.20)
25 val background = palette.background.background
26 return ThemeTextSelection(
27 if (theme.preferences.reduceTransparency)
28 mixThemeColor(background, active.withAlpha(1.0), active.alpha)
29 else
30 active,
31 if (theme.preferences.reduceTransparency)
32 mixThemeColor(background, inactive.withAlpha(1.0), inactive.alpha)
33 else
34 inactive,
35 None,
36 None
37 )
40internal fun selectionTextColor(color: Color?, background: Color?, fallback: Color?): Color? =
41 when (color) {
42 case Some(_) -> color
43 case None -> if (background == None)
44 fallback
45 else
46 None
47 }
49internal fun themeSelectionOptions(theme: Theme): SelectableTextOptions {
50 val colors = themeTextSelection(theme)
51 return SelectableTextOptions(
52 selectionColor = colors.background,
53 inactiveSelectionColor = colors.inactiveBackground,
54 selectionTextColor = colors.text,
55 inactiveSelectionTextColor = colors.inactiveText
56 )