scoop:scoop.ui.component:0.1.0
src/candidate/semantics.scoop
Selected production source · src/candidate/semantics.scoop
1
package scoop.ui.component3
import scoop.graphics.text.*4
import scoop.ui.ViewKey5
import scoop.window.accessibility.*7
internal fun candidateInputSemantics(8
options: ComponentSemantics,9
collection: SemanticNodeId?,10
active: ViewKey?11
): ComponentSemantics {12
val target = collection ?: return options13
val controls = ArrayList<SemanticNodeId>()14
var present = false15
for (id in options.relations.controls) {16
controls.add(id)17
if (id == target)18
present = true19
}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 -> None32
}33
}34
}35
}37
internal 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. */47
internal fun candidateCaption(content: PanelContent): String? =48
when (content) {49
case Label(val input) -> when (val name = input.semantics.name) {50
case Some(_) -> name51
case None -> Some(52
when (input.text) {53
case Plain(val text, _) -> text54
case Styled(val text) -> text.toPlainText()55
}56
)57
}58
case Custom(_) -> None59
}