scoop:scoop.ui.component:0.1.0
src/builders/flex.scoop
Selected production source · src/builders/flex.scoop
1
package scoop.ui.component3
import scoop.ui.*5
public class FlexItemBuilder internal constructor() {6
public var basis: FlexBasis = FlexBasis.Content7
public var grow: Double = 0.08
public var shrink: Double = 1.09
public var min: Double = 0.010
public var max: Double? = None11
public var align: CrossAlignment? = None12
internal fun snapshot(): FlexItemOptions = FlexItemOptions(basis, grow, shrink, min, max, align)13
}15
public fun flexItem(content: View, configure: FlexItemBuilder.() -> Unit = {}): FlexItem {16
val builder = FlexItemBuilder()17
builder.configure()18
return FlexItem(content, builder.snapshot())19
}21
public class FlexBuilder internal constructor(): LinearBuilder() {22
public var axis: FlexAxis = FlexAxis.Horizontal23
private var arrangement: ((Constraints) -> FlexLayout)? = None24
private val rules = ArrayList<FlexItemRule>()26
/** Resolves geometry from the incoming constraints before applying padding. */27
public fun layoutFor(resolve: (Constraints) -> FlexLayout) {28
arrangement = Some(resolve)29
}31
/** Appends one stable child with allocation chosen at measurement. */32
public fun itemFor(content: View, resolve: (Constraints) -> FlexItemOptions?) {33
rules.add(FlexItemRule(childCount, resolve))34
add(content)35
}37
internal fun flexProps(): FlexProps = FlexProps(axis, snapshot(), arrangement, rules.toArray())38
}40
public fun flex(configure: FlexBuilder.() -> Unit = {}): View = makeFlex(configure)42
internal fun makeFlex(configure: FlexBuilder.() -> Unit): View {43
val builder = FlexBuilder()44
builder.configure()45
return component(46
builder.flexProps(),47
{ props, mount -> Flex(props, scope = mount) },48
builder.key49
)50
}