scoop:scoop.ui.component:0.1.0
src/layout/containers.scoop
Selected production source · src/layout/containers.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.ui.*6
public class Row public constructor(7
private val props: Props<LinearProps>,8
scope: ComponentScope9
): Component(scope) {10
public override fun render(): View = flexElement(FlexProps(FlexAxis.Horizontal, props.value))11
}13
public class Column public constructor(14
private val props: Props<LinearProps>,15
scope: ComponentScope16
): Component(scope) {17
public override fun render(): View = flexElement(FlexProps(FlexAxis.Vertical, props.value))18
}20
public fun row(configure: LinearBuilder.() -> Unit = {}): View = makeRow(configure)22
public fun column(configure: LinearBuilder.() -> Unit = {}): View = makeColumn(configure)24
public class StackProps public constructor(25
public val children: Array<View>,26
public val alignment: Alignment = Alignment()27
)29
public class Stack public constructor(30
private val props: Props<StackProps>,31
scope: ComponentScope32
): Component(scope) {33
public override fun render(): View =34
element(35
props.value,36
{ current, mount -> StackInk(current, scope = mount) },37
props.value.children38
)39
}41
public fun stack(configure: StackBuilder.() -> Unit = {}): View = makeStack(configure)43
private class StackInk(private val props: Props<StackProps>, scope: ComponentScope): Element<Unit>(44
scope45
) {46
public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<47
Unit48
> {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).size54
}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
}63
}