scoop:scoop.ui.component:0.1.0
src/table/cell.scoop
Selected production source · src/table/cell.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.ui.*5
import scoop.window.accessibility.*7
internal class TableCellLayout(8
val padding: Double,9
val alignment: AxisAlignment,10
val natural: Boolean,11
val semantics: TableCellSemantics12
)14
/** Natural header/end content aligns within the shared column, not within a stretched label. */15
internal class TableCellInk(16
private val props: Props<TableCellLayout>,17
scope: ComponentScope18
): Element<Unit>(scope) {19
private var semantics: SemanticsHandle? = None20
public override fun update(): UiInvalidation {21
val input = props.value.semantics22
when (semantics) {23
case Some(val old) -> if (old.role != input.role) {24
old.close();25
semantics = None26
}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 = true36
handle.bindReference(input.reference)37
handle.update(input.properties, relations = input.relations)38
}39
case None -> {}40
}41
return UiInvalidation.Layout42
}43
public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<44
Unit45
> {46
val input = props.value47
val inset = input.padding * 2.048
val maximum = insetMaximum(constraints.maxWidth, inset)49
val height = insetMaximum(constraints.maxHeight, inset)50
val natural = input.natural || input.alignment != AxisAlignment.Start51
var child =52
context.measureChild(53
0L,54
Constraints(55
maxWidth =56
if (natural)57
None58
else59
maximum,60
maxHeight = height61
)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.layoutDirection79
)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
}93
}