Scoop API

scoop:scoop.ui:0.1.0

src/host/fonts.scoop

Selected production source · src/host/fonts.scoop

1package scoop.ui
3import scoop.graphics.text.FontCollection
5/** A root owns only the fallback it creates, including after selecting a borrowed replacement. */
6internal class RootFonts(initial: FontCollection?): Closeable {
7 private val owned =
8 when (initial) {
9 case None -> Some(FontCollection())
10 case Some(_) -> None
11 }
12 var value: FontCollection = initial ?: owned!!
13 val signal = StateSignal()
14 var revision = 0L
15 fun replace(next: FontCollection) {
16 when (currentEvaluation()) {
17 case Some(_) -> throw IllegalStateException(
18 Some("default fonts cannot change during render, measure, scene or draw")
19 )
20 case None -> {}
21 }
22 if (value === next)
23 return
24 value = next
25 revision += 1L
26 signal.changed(UiInvalidation.Layout)
27 }
28 public override fun close() {
29 owned?.close()
30 }