scoop:scoop.ui.component:0.1.0
src/disclosure/layout.scoop
Selected production source · src/disclosure/layout.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.ui.*6
internal class DisclosureLayoutProps(7
val presence: Presence?,8
val open: Boolean,9
val transition: PresenceOptions,10
val hasTrigger: Boolean,11
val spacing: Double12
)14
/** The presentation owner stays outside the content's input and animation gate. */15
internal class DisclosureLayout(16
private val props: Props<DisclosureLayoutProps>,17
scope: ComponentScope18
): Element<Boolean>(scope) {19
public override fun update(): UiInvalidation {20
props.value.presence?.update(props.value.open, Some(props.value.transition))21
return UiInvalidation.Layout22
}23
public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<24
Boolean25
> {26
val input = props.value27
val child =28
Constraints(minWidth = constraints.maxWidth ?: 0.0, maxWidth = constraints.maxWidth)29
val header = context.measureChild(0L, child)30
val body = context.measureChild(1L, child)31
val progress = disclosureProgress(input.presence, input.open)32
val gap =33
if (input.hasTrigger)34
input.spacing * progress35
else36
0.037
val width = lowerBound(header.size.width, body.size.width)38
val height = header.size.height + gap + body.size.height39
val size = constraints.constrain(Size(width, height))40
val clipped = size.width < width || size.height < height41
if (size.width > 0.0 && size.height > 0.0) {42
if (input.hasTrigger)43
context.placeChild(0L, Point(0.0, 0.0))44
if (body.size.height > 0.0)45
context.placeChild(1L, Point(0.0, header.size.height + gap))46
}47
return LayoutResult(48
LayoutMetrics(size, header.alphabeticBaseline, header.ideographicBaseline),49
clipped50
)51
}52
public override fun scene(context: SceneContext, clipped: Boolean) {53
if (clipped)54
context.clipRect(Rect(0.0, 0.0, context.size.width, context.size.height))55
context.children()56
}57
}