Scoop API

scoop:scoop.ui.component:0.1.0

src/resizable/panel.scoop

Selected production source · src/resizable/panel.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.ui.*
5import scoop.ui.style.*
7internal class ResizablePanelInput(val root: ResizableInput, val index: Long) {
8 val hasHandle: Boolean get() = index + 1L < root.props.panels.size
9 val key: ViewKey get() = root.props.panels[index].key
12internal class ResizablePanelLayout(
13 private val props: Props<ResizablePanelInput>,
14 scope: ComponentScope
15): Element<Unit>(scope) {
16 public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<
17 Unit
18 > {
19 val input = props.value
20 val horizontal = input.root.props.orientation == Orientation.Horizontal
21 val thickness =
22 if (input.hasHandle)
23 input.root.theme.tokens.typography.body.fontSize / 14.0
24 else
25 0.0
26 val main =
27 (
28 if (horizontal)
29 constraints.maxWidth
30 else
31 constraints.maxHeight
32 ) ?:
33 0.0
34 val extent = lowerBound(0.0, main - thickness)
35 val maxCross =
36 if (horizontal)
37 constraints.maxHeight
38 else
39 constraints.maxWidth
40 var naturalCross =
41 if (input.hasHandle)
42 24.0 * thickness
43 else
44 0.0
45 if (extent == 0.0 || maxCross == Some(0.0))
46 context.skipChild(0L)
47 else {
48 val child =
49 context.measureChild(
50 0L,
51 if (horizontal)
52 Constraints(
53 minWidth = extent,
54 maxWidth = Some(extent),
55 minHeight = maxCross ?: 0.0,
56 maxHeight = maxCross
57 )
58 else
59 Constraints(
60 minHeight = extent,
61 maxHeight = Some(extent),
62 minWidth = maxCross ?: 0.0,
63 maxWidth = maxCross
64 )
65 )
66 naturalCross =
67 lowerBound(
68 naturalCross,
69 if (horizontal)
70 child.size.height
71 else
72 child.size.width
73 )
74 }
75 val size = constraints.constrain(resizableSize(main, maxCross ?: naturalCross, horizontal))
76 if (extent > 0.0 && maxCross != Some(0.0))
77 context.placeChild(
78 0L,
79 if (horizontal)
80 Point(logicalX(0.0, extent, size.width, context.layoutDirection), 0.0)
81 else
82 Point(0.0, 0.0)
83 )
84 if (!input.hasHandle || size.width == 0.0 || size.height == 0.0)
85 context.skipChild(1L)
86 else {
87 context.measureChild(
88 1L,
89 Constraints.tight(
90 resizableSize(
91 thickness,
92 if (horizontal)
93 size.height
94 else
95 size.width,
96 horizontal
97 )
98 )
99 )
100 context.placeChild(
101 1L,
102 if (horizontal)
103 Point(logicalX(extent, thickness, size.width, context.layoutDirection), 0.0)
104 else
105 Point(0.0, extent)
106 )
107 }
108 return LayoutResult(LayoutMetrics(size), Unit)
109 }
110 public override fun scene(context: SceneContext, measured: Unit) {
111 context.children()
112 }
115internal class ResizableContent(
116 private val props: Props<StyleOverride>,
117 scope: ComponentScope
118): Element<Unit>(scope) {
119 private var painter: StylePainter? = None
120 public override fun onMount() {
121 painter = Some(scope.resource { StylePainter() })
122 }
123 public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<
124 Unit
125 > {
126 val child = context.measureChild(0L, constraints)
127 context.placeChild(0L, Point(0.0, 0.0))
128 return LayoutResult(child, Unit)
129 }
130 public override fun scene(context: SceneContext, measured: Unit) {
131 painter!!.scene(context, props.value.resolve(style())) {
132 local -> containerScene(local, true)
133 }
134 }