Scoop API

scoop:scoop.ui.component:0.1.0

src/conversation/scroller_layout.scoop

Selected production source · src/conversation/scroller_layout.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.ui.*
6internal class MessageScrollerLayoutInput(
7 val density: Double,
8 val controls: Boolean,
9 val placeholder: Boolean
12internal class MessageScrollerLayout(
13 private val props: Props<MessageScrollerLayoutInput>,
14 scope: ComponentScope
15): Element<Unit>(scope) {
16 public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<
17 Unit
18 > {
19 val viewport = context.measureChild(0L, constraints)
20 context.placeChild(0L, Point(0.0, 0.0))
21 val size = viewport.size
22 val margin = 16.0 * props.value.density
23 val limit =
24 Constraints(
25 maxWidth = Some(lowerBound(size.width - margin * 2.0, 0.0)),
26 maxHeight = Some(lowerBound(size.height - margin * 2.0, 0.0))
27 )
28 if (props.value.controls && size.width > margin * 2.0 && size.height > margin * 2.0) {
29 val child = context.measureChild(1L, limit)
30 context.placeChild(
31 1L,
32 Point(
33 (size.width - child.size.width) / 2.0,
34 size.height - margin - child.size.height
35 )
36 )
37 } else
38 context.skipChild(1L)
39 if (props.value.placeholder && size.width > 0.0 && size.height > 0.0) {
40 val child = context.measureChild(2L, limit)
41 context.placeChild(
42 2L,
43 Point(
44 (size.width - child.size.width) / 2.0,
45 (size.height - child.size.height) / 2.0
46 )
47 )
48 } else
49 context.skipChild(2L)
50 return LayoutResult(viewport, Unit)
51 }
52 public override fun scene(context: SceneContext, measured: Unit) {
53 context.children([0L, 2L, 1L])
54 }