Scoop API

scoop:scoop.ui.component:0.1.0

platform/desktop/native/chrome/layout.scoop

Selected production source · platform/desktop/native/chrome/layout.scoop

1package scoop.ui.component
3import scoop.graphics.*
4import scoop.ui.*
5import scoop.window.*
7internal fun measureWindowChrome(
8 context: MeasureContext,
9 constraints: Constraints,
10 input: WindowChromeInput
11): LayoutResult<Unit> {
12 val value = input.value
13 var left = 0.0
14 var right = 0.0
15 var bottom = 0.0
16 var top =
17 when (value.titleBar) {
18 case Some(_) -> value.titleBarHeight;
19 case None -> 0.0
20 }
21 when (input.metrics) {
22 case Some(val metrics) -> if (metrics.frame == WindowFrame.System(WindowContentMode.Extended)) {
23 when (metrics.contentLayout) {
24 case Some(val layout) -> {
25 left = lowerBound(layout.origin.x, 0.0)
26 right =
27 lowerBound(
28 metrics.metrics.logicalSize.width - layout.origin.x - layout.size.width,
29 0.0
30 )
31 bottom =
32 lowerBound(
33 metrics.metrics.logicalSize.height -
34 layout.origin.y -
35 layout.size.height,
36 0.0
37 )
38 top = lowerBound(top, layout.origin.y)
39 }
40 case None -> {}
41 }
42 }
43 case None -> {}
44 }
45 val horizontal = left + right
46 val vertical = top + bottom
47 val body =
48 context.measureChild(
49 1L,
50 Constraints(
51 lowerBound(constraints.minWidth - horizontal, 0.0),
52 when (constraints.maxWidth) {
53 case Some(val width) -> Some(lowerBound(width - horizontal, 0.0))
54 case None -> None
55 },
56 lowerBound(constraints.minHeight - vertical, 0.0),
57 when (constraints.maxHeight) {
58 case Some(val height) -> Some(lowerBound(height - vertical, 0.0))
59 case None -> None
60 }
61 )
62 )
63 val size =
64 constraints.constrain(Size(body.size.width + horizontal, body.size.height + vertical))
65 context.placeChild(1L, Point(left, top))
66 var titleLeft = left
67 var titleRight = right
68 when (input.metrics) {
69 case Some(val metrics) -> for (button in metrics.systemButtons) {
70 val rect = button.bounds
71 if (rect.origin.y < top && rect.origin.y + rect.size.height > 0.0) {
72 if (rect.origin.x + rect.size.width / 2.0 < size.width / 2.0)
73 titleLeft = lowerBound(titleLeft, rect.origin.x + rect.size.width + 8.0)
74 else
75 titleRight = lowerBound(titleRight, size.width - rect.origin.x + 8.0)
76 }
77 }
78 case None -> {}
79 }
80 val titleSize =
81 when (value.titleBar) {
82 case Some(_) -> Size(lowerBound(size.width - titleLeft - titleRight, 0.0), top)
83 case None -> Size(0.0, 0.0)
84 }
85 context.measureChild(0L, Constraints.tight(titleSize))
86 context.placeChild(0L, Point(titleLeft, 0.0))
87 return LayoutResult(offsetMetrics(body, size, top), Unit)