scoop:scoop.ui.component:0.1.0
platform/desktop/native/chrome/layout.scoop
Selected production source · platform/desktop/native/chrome/layout.scoop
1
package scoop.ui.component3
import scoop.graphics.*4
import scoop.ui.*5
import scoop.window.*7
internal fun measureWindowChrome(8
context: MeasureContext,9
constraints: Constraints,10
input: WindowChromeInput11
): LayoutResult<Unit> {12
val value = input.value13
var left = 0.014
var right = 0.015
var bottom = 0.016
var top =17
when (value.titleBar) {18
case Some(_) -> value.titleBarHeight;19
case None -> 0.020
}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.030
)31
bottom =32
lowerBound(33
metrics.metrics.logicalSize.height -34
layout.origin.y -35
layout.size.height,36
0.037
)38
top = lowerBound(top, layout.origin.y)39
}40
case None -> {}41
}42
}43
case None -> {}44
}45
val horizontal = left + right46
val vertical = top + bottom47
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 -> None55
},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 -> None60
}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 = left67
var titleRight = right68
when (input.metrics) {69
case Some(val metrics) -> for (button in metrics.systemButtons) {70
val rect = button.bounds71
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
else75
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)88
}