scoop:scoop.ui.component:0.1.0
src/resizable/panel.scoop
Selected production source · src/resizable/panel.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.ui.*5
import scoop.ui.style.*7
internal class ResizablePanelInput(val root: ResizableInput, val index: Long) {8
val hasHandle: Boolean get() = index + 1L < root.props.panels.size9
val key: ViewKey get() = root.props.panels[index].key10
}12
internal class ResizablePanelLayout(13
private val props: Props<ResizablePanelInput>,14
scope: ComponentScope15
): Element<Unit>(scope) {16
public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<17
Unit18
> {19
val input = props.value20
val horizontal = input.root.props.orientation == Orientation.Horizontal21
val thickness =22
if (input.hasHandle)23
input.root.theme.tokens.typography.body.fontSize / 14.024
else25
0.026
val main =27
(28
if (horizontal)29
constraints.maxWidth30
else31
constraints.maxHeight32
) ?:33
0.034
val extent = lowerBound(0.0, main - thickness)35
val maxCross =36
if (horizontal)37
constraints.maxHeight38
else39
constraints.maxWidth40
var naturalCross =41
if (input.hasHandle)42
24.0 * thickness43
else44
0.045
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 = maxCross57
)58
else59
Constraints(60
minHeight = extent,61
maxHeight = Some(extent),62
minWidth = maxCross ?: 0.0,63
maxWidth = maxCross64
)65
)66
naturalCross =67
lowerBound(68
naturalCross,69
if (horizontal)70
child.size.height71
else72
child.size.width73
)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
else82
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.height94
else95
size.width,96
horizontal97
)98
)99
)100
context.placeChild(101
1L,102
if (horizontal)103
Point(logicalX(extent, thickness, size.width, context.layoutDirection), 0.0)104
else105
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
}113
}115
internal class ResizableContent(116
private val props: Props<StyleOverride>,117
scope: ComponentScope118
): Element<Unit>(scope) {119
private var painter: StylePainter? = None120
public override fun onMount() {121
painter = Some(scope.resource { StylePainter() })122
}123
public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<124
Unit125
> {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
}135
}