Scoop API

scoop:scoop.ui.component:0.1.0

src/choice/layout.scoop

Selected production source · src/choice/layout.scoop

1package scoop.ui.component
3import scoop.graphics.Point
4import scoop.graphics.Rect
5import scoop.ui.*
6import scoop.window.accessibility.*
7import scoop.ui.style.*
8import scoop.ui.style.style as baseStyle
10internal fun choiceLayout(
11 children: Array<View>,
12 keys: Array<ViewKey>,
13 handles: Array<FocusHandle>,
14 axis: FlexAxis,
15 spacing: Double,
16 loop: Boolean,
17 enabled: Boolean,
18 style: StyleOverride,
19 preferred: FocusHandle? = None,
20 navigate: (FocusHandle) -> Unit = {},
21 fitCross: Boolean = true,
22 roving: Boolean = true,
23 semantics: SemanticsHandle? = None,
24 semanticOptions: ComponentSemantics = ComponentSemantics()
25): View {
26 val slots = Array<GroupSlot>(children.size) { _ -> GroupSlot() }
27 val layout =
28 LinearProps(
29 Array<FlexItem>(children.size) {
30 index -> FlexItem(
31 element(
32 slots[index],
33 { current, mount -> GroupSlotInk(current, scope = mount) },
34 [children[index]],
35 keys[index]
36 )
37 )
38 },
39 spacing = spacing,
40 alignment = CrossAlignment.Stretch
41 )
42 val options =
43 NavigationOptions(
44 Array<NavigationItem>(handles.size) { index -> NavigationItem(handles[index]) },
45 if (axis == FlexAxis.Horizontal)
46 NavigationLayout.Horizontal
47 else
48 NavigationLayout.Vertical,
49 loop = loop,
50 roving = roving,
51 preferredTab = preferred,
52 onNavigate = navigate
53 )
54 return styled(
55 element(
56 ChoiceNavigationProps(options, enabled, semantics, semanticOptions),
57 { current, mount -> ChoiceNavigation(current, scope = mount) },
58 [
59 element(
60 GroupLayoutProps(layout, axis, slots, fitCross),
61 { current, mount -> GroupLayout(current, scope = mount) },
62 layout.children
63 )
64 ]
65 )
66 ) { this.style = style.resolve(baseStyle()) }
69private class ChoiceNavigationProps(
70 val navigation: NavigationOptions,
71 val enabled: Boolean,
72 val semantics: SemanticsHandle?,
73 val semanticOptions: ComponentSemantics
76private class ChoiceNavigation(
77 private val props: Props<ChoiceNavigationProps>,
78 scope: ComponentScope
79): Element<Unit>(scope) {
80 private var navigation: KeyNavigation? = None
81 public override fun onMount() {
82 navigation = Some(scope.keyNavigation(props.value.navigation))
83 }
84 public override fun update(): UiInvalidation {
85 scope.input.enabled = props.value.enabled
86 navigation!!.options = props.value.navigation
87 val value = props.value
88 value.semantics?.bindReference(value.semanticOptions.reference)
89 value.semantics?.update(
90 value.semanticOptions.properties(enabled = value.enabled).copy {
91 if (value.semantics?.role == Some(SemanticRole.RadioGroup)) {
92 selectionMode = Some(SemanticSelectionMode.Single)
93 required = true
94 }
95 },
96 relations = value.semanticOptions.relations
97 )
98 return UiInvalidation.Layout
99 }
100 public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<
101 Unit
102 > {
103 val result = context.measureChild(0L, constraints)
104 context.placeChild(0L, Point(0.0, 0.0))
105 return LayoutResult(result, Unit)
106 }
107 public override fun scene(context: SceneContext, measured: Unit) {
108 when (val handle = props.value.semantics) {
109 case Some(val value) -> context.semantics(
110 value,
111 Rect(0.0, 0.0, context.size.width, context.size.height)
112 )
113 case None -> {}
114 }
115 context.children()
116 }