Scoop API

scoop:scoop.ui.component:0.1.0

src/candidate/semantics.scoop

Selected production source · src/candidate/semantics.scoop

1package scoop.ui.component
3import scoop.graphics.text.*
4import scoop.ui.ViewKey
5import scoop.window.accessibility.*
7internal fun candidateInputSemantics(
8 options: ComponentSemantics,
9 collection: SemanticNodeId?,
10 active: ViewKey?
11): ComponentSemantics {
12 val target = collection ?: return options
13 val controls = ArrayList<SemanticNodeId>()
14 var present = false
15 for (id in options.relations.controls) {
16 controls.add(id)
17 if (id == target)
18 present = true
19 }
20 if (!present)
21 controls.add(target)
22 return options.copy {
23 relations =
24 options.relations.copy {
25 this.controls = controls.toArray()
26 activeDescendant =
27 when (active) {
28 case Some(val key) -> Some(
29 SemanticDescendant.Item(target, componentSemanticKey(key))
30 )
31 case None -> None
32 }
33 }
34 }
37internal fun componentSemanticKey(key: ViewKey): SemanticItemKey =
38 when (key) {
39 case Number(val value) -> SemanticItemKey.Number(value)
40 case Text(val value) -> SemanticItemKey.Text(value)
41 case Position -> throw IllegalArgumentException(
42 Some("semantic items require explicit keys")
43 )
44 }
46/** Reads declared captions without constructing custom content or borrowing its view. */
47internal fun candidateCaption(content: PanelContent): String? =
48 when (content) {
49 case Label(val input) -> when (val name = input.semantics.name) {
50 case Some(_) -> name
51 case None -> Some(
52 when (input.text) {
53 case Plain(val text, _) -> text
54 case Styled(val text) -> text.toPlainText()
55 }
56 )
57 }
58 case Custom(_) -> None
59 }