Scoop API

scoop:scoop.ui.component:0.1.0

src/select/root_layout.scoop

Selected production source · src/select/root_layout.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.surface.*
5import scoop.ui.*
6import scoop.window.*
8internal class SelectRootProps(
9 val anchor: LayoutAnchor,
10 val width: Double?,
11 val enabled: Boolean,
12 val open: Boolean,
13 val show: (Boolean) -> Unit,
14 val updated: () -> Unit
17internal class SelectRootLayout(
18 private val props: Props<SelectRootProps>,
19 scope: ComponentScope
20): Element<Unit>(scope) {
21 public override fun onMount() {
22 scope.layoutAnchor(props.value.anchor)
23 scope.input.addDefaultAction {
24 context, event ->
25 if (!props.value.enabled || props.value.open)
26 return@addDefaultAction
27 val key =
28 when (event) {
29 case Keyboard(val value) -> value;
30 else -> return@addDefaultAction
31 }
32 if (!menuKeyAllowed(key))
33 return@addDefaultAction
34 if (
35 key.logicalKey ==
36 LogicalKey.Named(NamedKey.ArrowDown) ||
37 key.logicalKey ==
38 LogicalKey.Named(NamedKey.ArrowUp)
39 ) {
40 context.consume()
41 props.value.show(key.logicalKey == LogicalKey.Named(NamedKey.ArrowUp))
42 }
43 }
44 }
45 public override fun update(): UiInvalidation {
46 props.value.updated()
47 return UiInvalidation.Layout
48 }
49 public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<
50 Unit
51 > {
52 val limits =
53 when (props.value.width) {
54 case Some(val width) -> {
55 val constrained =
56 constraints.constrain(Size(width, constraints.minHeight)).width
57 Constraints(
58 constrained,
59 Some(constrained),
60 constraints.minHeight,
61 constraints.maxHeight
62 )
63 }
64 case None -> constraints
65 }
66 val result = context.measureChild(0L, limits)
67 context.placeChild(0L, Point(0.0, 0.0))
68 context.measureChild(1L, Constraints());
69 context.placeChild(1L, Point(0.0, 0.0))
70 return LayoutResult(result, Unit)
71 }
72 public override fun scene(context: SceneContext, measured: Unit) {
73 context.anchor(props.value.anchor, Rect(0.0, 0.0, context.size.width, context.size.height))
74 context.children()
75 }