Scoop API

scoop:scoop.ui.component:0.1.0

src/layout/containers.scoop

Selected production source · src/layout/containers.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.ui.*
6public class Row public constructor(
7 private val props: Props<LinearProps>,
8 scope: ComponentScope
9): Component(scope) {
10 public override fun render(): View = flexElement(FlexProps(FlexAxis.Horizontal, props.value))
13public class Column public constructor(
14 private val props: Props<LinearProps>,
15 scope: ComponentScope
16): Component(scope) {
17 public override fun render(): View = flexElement(FlexProps(FlexAxis.Vertical, props.value))
20public fun row(configure: LinearBuilder.() -> Unit = {}): View = makeRow(configure)
22public fun column(configure: LinearBuilder.() -> Unit = {}): View = makeColumn(configure)
24public class StackProps public constructor(
25 public val children: Array<View>,
26 public val alignment: Alignment = Alignment()
29public class Stack public constructor(
30 private val props: Props<StackProps>,
31 scope: ComponentScope
32): Component(scope) {
33 public override fun render(): View =
34 element(
35 props.value,
36 { current, mount -> StackInk(current, scope = mount) },
37 props.value.children
38 )
41public fun stack(configure: StackBuilder.() -> Unit = {}): View = makeStack(configure)
43private class StackInk(private val props: Props<StackProps>, scope: ComponentScope): Element<Unit>(
44 scope
45) {
46 public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<
47 Unit
48 > {
49 val childConstraints =
50 Constraints(maxWidth = constraints.maxWidth, maxHeight = constraints.maxHeight)
51 val sizes =
52 Array<Size>(context.childCount) {
53 index -> context.measureChild(index, childConstraints).size
54 }
55 val plan = arrangeStack(sizes, constraints, props.value.alignment, context.layoutDirection)
56 for (index in 0L until context.childCount)
57 context.placeChild(index, plan.origins[index])
58 return LayoutResult(LayoutMetrics(plan.size), Unit)
59 }
60 public override fun scene(context: SceneContext, measured: Unit) {
61 context.children()
62 }