Scoop API

scoop:scoop.ui.component:0.1.0

src/theme.scoop

Selected production source · src/theme.scoop

1package scoop.ui.component
3import scoop.ui.style.*
4import scoop.ui.InteractionState
5import scoop.ui.ComponentScope
7/** Captures the ambient source, while explicit sources remain replaceable Props. */
8internal class ThemeAccess(private val scope: ComponentScope) {
9 private var ambient: ThemeSource? = None
10 fun mount(explicit: ThemeSource?) {
11 when (explicit) {
12 case None -> ambient = Some(currentThemeSource());
13 case Some(_) -> {}
14 }
15 }
16 fun read(explicit: ThemeSource?): Theme {
17 val source =
18 when (explicit) {
19 case Some(val value) -> value
20 case None -> when (ambient) {
21 case Some(val value) -> value
22 case None -> {
23 val value = currentThemeSource()
24 ambient = Some(value)
25 value
26 }
27 }
28 }
29 return source.read(scope)
30 }
33internal fun InteractionState.asVisual(
34 enabled: Boolean,
35 invalid: Boolean = false
36): InteractionVisual = InteractionVisual(enabled, hovered, pressed, focusVisible, invalid = invalid)
38internal fun sameTheme(previous: Theme?, current: Theme): Boolean =
39 when (previous) {
40 case Some(val value) -> value === current
41 case None -> false
42 }