Scoop API

scoop:scoop.ui.component:0.1.0

src/table/cell.scoop

Selected production source · src/table/cell.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.ui.*
5import scoop.window.accessibility.*
7internal class TableCellLayout(
8 val padding: Double,
9 val alignment: AxisAlignment,
10 val natural: Boolean,
11 val semantics: TableCellSemantics
14/** Natural header/end content aligns within the shared column, not within a stretched label. */
15internal class TableCellInk(
16 private val props: Props<TableCellLayout>,
17 scope: ComponentScope
18): Element<Unit>(scope) {
19 private var semantics: SemanticsHandle? = None
20 public override fun update(): UiInvalidation {
21 val input = props.value.semantics
22 when (semantics) {
23 case Some(val old) -> if (old.role != input.role) {
24 old.close();
25 semantics = None
26 }
27 case None -> {}
28 }
29 if (!panelPresent(semantics)) {
30 semantics = createComponentSemantics(scope, input.role)
31 scope.routeSemanticsChildren(semantics)
32 }
33 when (semantics) {
34 case Some(val handle) -> {
35 handle.mergeLabels = true
36 handle.bindReference(input.reference)
37 handle.update(input.properties, relations = input.relations)
38 }
39 case None -> {}
40 }
41 return UiInvalidation.Layout
42 }
43 public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<
44 Unit
45 > {
46 val input = props.value
47 val inset = input.padding * 2.0
48 val maximum = insetMaximum(constraints.maxWidth, inset)
49 val height = insetMaximum(constraints.maxHeight, inset)
50 val natural = input.natural || input.alignment != AxisAlignment.Start
51 var child =
52 context.measureChild(
53 0L,
54 Constraints(
55 maxWidth =
56 if (natural)
57 None
58 else
59 maximum,
60 maxHeight = height
61 )
62 )
63 if (natural && child.size.width > (maximum ?: child.size.width))
64 child = context.measureChild(0L, Constraints(maxWidth = maximum, maxHeight = height))
65 val size = constraints.constrain(Size(child.size.width + inset, child.size.height + inset))
66 val bounds =
67 Rect(
68 input.padding,
69 input.padding,
70 lowerBound(size.width - inset, 0.0),
71 lowerBound(size.height - inset, 0.0)
72 )
73 val origin =
74 alignedOrigin(
75 bounds,
76 child.size,
77 Alignment(input.alignment, AxisAlignment.Center),
78 context.layoutDirection
79 )
80 context.placeChild(0L, origin)
81 return LayoutResult(offsetMetrics(child, size, origin.y), Unit)
82 }
83 public override fun scene(context: SceneContext, value: Unit) {
84 when (semantics) {
85 case Some(val handle) -> context.semantics(
86 handle,
87 Rect(0.0, 0.0, context.size.width, context.size.height)
88 )
89 case None -> {}
90 }
91 context.children()
92 }