scoop:scoop.ui.component:0.1.0
src/selection.scoop
Selected production source · src/selection.scoop
1
package scoop.ui.component3
import scoop.graphics.Color4
import scoop.ui.style.*5
import scoop.ui.text.SelectableTextOptions7
internal struct ThemeTextSelection(8
val background: Color,9
val inactiveBackground: Color,10
val text: Color?,11
val inactiveText: Color?12
)14
internal fun themeTextSelection(theme: Theme): ThemeTextSelection {15
val palette = theme.tokens.palette16
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.background26
return ThemeTextSelection(27
if (theme.preferences.reduceTransparency)28
mixThemeColor(background, active.withAlpha(1.0), active.alpha)29
else30
active,31
if (theme.preferences.reduceTransparency)32
mixThemeColor(background, inactive.withAlpha(1.0), inactive.alpha)33
else34
inactive,35
None,36
None37
)38
}40
internal fun selectionTextColor(color: Color?, background: Color?, fallback: Color?): Color? =41
when (color) {42
case Some(_) -> color43
case None -> if (background == None)44
fallback45
else46
None47
}49
internal 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.inactiveText56
)57
}