Scoop API

scoop:scoop.ui.component:0.1.0

src/disclosure/layout.scoop

Selected production source · src/disclosure/layout.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.ui.*
6internal class DisclosureLayoutProps(
7 val presence: Presence?,
8 val open: Boolean,
9 val transition: PresenceOptions,
10 val hasTrigger: Boolean,
11 val spacing: Double
14/** The presentation owner stays outside the content's input and animation gate. */
15internal class DisclosureLayout(
16 private val props: Props<DisclosureLayoutProps>,
17 scope: ComponentScope
18): Element<Boolean>(scope) {
19 public override fun update(): UiInvalidation {
20 props.value.presence?.update(props.value.open, Some(props.value.transition))
21 return UiInvalidation.Layout
22 }
23 public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<
24 Boolean
25 > {
26 val input = props.value
27 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 * progress
35 else
36 0.0
37 val width = lowerBound(header.size.width, body.size.width)
38 val height = header.size.height + gap + body.size.height
39 val size = constraints.constrain(Size(width, height))
40 val clipped = size.width < width || size.height < height
41 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 clipped
50 )
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 }