scoop:scoop.ui.component:0.1.0
src/theme.scoop
Selected production source · src/theme.scoop
1
package scoop.ui.component3
import scoop.ui.style.*4
import scoop.ui.InteractionState5
import scoop.ui.ComponentScope7
/** Captures the ambient source, while explicit sources remain replaceable Props. */8
internal class ThemeAccess(private val scope: ComponentScope) {9
private var ambient: ThemeSource? = None10
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) -> value20
case None -> when (ambient) {21
case Some(val value) -> value22
case None -> {23
val value = currentThemeSource()24
ambient = Some(value)25
value26
}27
}28
}29
return source.read(scope)30
}31
}33
internal fun InteractionState.asVisual(34
enabled: Boolean,35
invalid: Boolean = false36
): InteractionVisual = InteractionVisual(enabled, hovered, pressed, focusVisible, invalid = invalid)38
internal fun sameTheme(previous: Theme?, current: Theme): Boolean =39
when (previous) {40
case Some(val value) -> value === current41
case None -> false42
}