26 lines
1.3 KiB
Swift
26 lines
1.3 KiB
Swift
import Foundation
|
|
import CoreGraphics
|
|
|
|
nonisolated enum PanelLayout {
|
|
static func resourceRowHeight(size: CGSize) -> CGFloat { min(230, max(220, size.height - 590)) }
|
|
static func batteryWidth(size: CGSize) -> CGFloat { resourceRowHeight(size: size) * 4 / 3 }
|
|
static func firstRowWideCardWidth(size: CGSize) -> CGFloat { (size.width - 36 - batteryWidth(size: size)) / 2 }
|
|
|
|
static func contentSize(visible: CGRect, chrome: CGSize = .zero) -> CGSize {
|
|
CGSize(width: max(1, min(1240, visible.width - 32 - max(0, chrome.width))),
|
|
height: max(1, min(820, visible.height - 32 - max(0, chrome.height))))
|
|
}
|
|
static func centeredFrame(_ frame: CGRect, visible: CGRect) -> CGRect {
|
|
var result = constrainedFrame(frame, visible: visible)
|
|
result.origin.x = visible.midX - result.width / 2
|
|
return result
|
|
}
|
|
|
|
static func constrainedFrame(_ frame: CGRect, visible: CGRect) -> CGRect {
|
|
let safe = visible.insetBy(dx: 16, dy: 16)
|
|
let width = min(frame.width, safe.width), height = min(frame.height, safe.height)
|
|
return CGRect(x: min(max(frame.minX, safe.minX), safe.maxX - width),
|
|
y: min(max(frame.minY, safe.minY), safe.maxY - height), width: width, height: height)
|
|
}
|
|
}
|