Scoop API

scoop:scoop.ui.component:0.1.0

src/semantic_content.scoop

Selected production source · src/semantic_content.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.ui.*
5import scoop.window.accessibility.*
7internal class SemanticContentProps(
8 val role: SemanticRole,
9 val properties: SemanticProperties,
10 val actions: SemanticActions,
11 val relations: SemanticRelations,
12 val mergeLabels: Boolean,
13 val reference: SemanticsReference?
16/** Adds a semantic container to existing content, without adding an input owner. */
17private class SemanticContentInk(
18 private val props: Props<SemanticContentProps>,
19 scope: ComponentScope
20): Element<Unit>(scope) {
21 private var semantics: SemanticsHandle? = None
22 public override fun update(): UiInvalidation {
23 val input = props.value
24 when (semantics) {
25 case Some(val old) -> if (old.role != input.role) {
26 old.close()
27 semantics = None
28 }
29 case None -> {}
30 }
31 if (!panelPresent(semantics)) {
32 semantics = createComponentSemantics(scope, input.role)
33 scope.routeSemanticsChildren(semantics)
34 }
35 when (semantics) {
36 case Some(val handle) -> {
37 handle.mergeLabels = input.mergeLabels
38 handle.bindReference(input.reference)
39 handle.update(input.properties, input.actions, input.relations)
40 }
41 case None -> {}
42 }
43 return UiInvalidation.Scene
44 }
45 public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<
46 Unit
47 > {
48 val child = context.measureChild(0L, constraints)
49 context.placeChild(0L, Point(0.0, 0.0))
50 return LayoutResult(child, Unit)
51 }
52 public override fun scene(context: SceneContext, value: Unit) {
53 when (semantics) {
54 case Some(val handle) -> context.semantics(
55 handle,
56 Rect(0.0, 0.0, context.size.width, context.size.height)
57 )
58 case None -> {}
59 }
60 context.children()
61 }
64internal fun semanticContent(
65 content: View,
66 role: SemanticRole,
67 properties: SemanticProperties,
68 actions: SemanticActions = SemanticActions(),
69 relations: SemanticRelations = SemanticRelations(),
70 mergeLabels: Boolean = true,
71 reference: SemanticsReference? = None,
72 key: ViewKey = ViewKey.Position
73): View =
74 element(
75 SemanticContentProps(role, properties, actions, relations, mergeLabels, reference),
76 { props, mount -> SemanticContentInk(props, scope = mount) },
77 [content],
78 key
79 )