Scoop API

scoop:scoop.ui.component:0.1.0

src/accessibility.scoop

Selected production source · src/accessibility.scoop

1package scoop.ui.component
3import scoop.collections.HashSet
4import scoop.window.accessibility.*
5import scoop.ui.SemanticsReference
7internal fun semanticIds(id: SemanticNodeId?): Array<SemanticNodeId> =
8 when (id) {
9 case Some(val value) -> [value];
10 case None -> []
11 }
13internal fun semanticCaption(content: PanelContent?): String? =
14 when (content) {
15 case Some(val value) -> candidateCaption(value);
16 case None -> None
17 }
19internal fun mergeSemanticIds(first: Array<SemanticNodeId>, second: Array<SemanticNodeId>): Array<
20 SemanticNodeId
21> {
22 val result = ArrayList<SemanticNodeId>()
23 val seen = HashSet<SemanticNodeId>()
24 for (id in first)
25 if (seen.add(id))
26 result.add(id)
27 for (id in second)
28 if (seen.add(id))
29 result.add(id)
30 return result.toArray()
33internal fun semanticControls(
34 relations: SemanticRelations,
35 id: SemanticNodeId?
36): SemanticRelations {
37 val target = id ?: return relations
38 val values = ArrayList<SemanticNodeId>()
39 for (existing in relations.controls) {
40 if (existing == target)
41 return relations
42 values.add(existing)
43 }
44 values.add(target)
45 return relations.copy { controls = values.toArray() }
48/** Naming and relationships never override the control's actual behavior or state. */
49public struct ComponentSemantics(
50 val name: String? = None,
51 val description: String? = None,
52 val automationId: String? = None,
53 val error: String? = None,
54 val relations: SemanticRelations = SemanticRelations(),
55 val hidden: Boolean = false,
56 val ignored: Boolean = false,
57 val busy: Boolean = false,
58 val live: SemanticLive = SemanticLive.Off,
59 val reference: SemanticsReference? = None
62internal fun ComponentSemantics.properties(
63 value: String? = None,
64 enabled: Boolean = true,
65 readOnly: Boolean = false,
66 checked: SemanticChecked? = None,
67 description: String? = None,
68 error: String? = None,
69 required: Boolean = false,
70 invalid: Boolean = false,
71 selected: Boolean? = None,
72 expanded: Boolean? = None,
73 range: SemanticValueRange? = None,
74 modal: Boolean = false
75): SemanticProperties =
76 SemanticProperties(
77 name = this.name,
78 description =
79 when (val overrideValue = this.description) {
80 case Some(_) -> overrideValue
81 case None -> description
82 },
83 automationId = this.automationId,
84 value = value,
85 enabled = enabled,
86 readOnly = readOnly,
87 checked = checked,
88 hidden = this.hidden,
89 error =
90 when (val overrideValue = this.error) {
91 case Some(_) -> overrideValue
92 case None -> error
93 },
94 ignored = this.ignored,
95 required = required,
96 invalid = invalid,
97 busy = this.busy,
98 live = this.live,
99 selected = selected,
100 expanded = expanded,
101 range = range,
102 modal = modal
103 )