feat(menubar): 拆分紧凑双页面板并按页采样

This commit is contained in:
2026-11-08 10:42:55 +08:00
parent ac8b4a7e6a
commit 41dcc497b5
36 changed files with 465 additions and 288 deletions
+11 -10
View File
@@ -2,18 +2,19 @@ import Foundation
import CoreGraphics
nonisolated enum PanelLayout {
static let baseCardHeight: CGFloat = 280
static func columns(width: CGFloat) -> Int { width >= 1160 ? 3 : width >= 900 ? 2 : 1 }
static let baseCardHeight: CGFloat = 204
static func headerHeight(width: CGFloat) -> CGFloat { width >= 840 ? 32 : 64 }
static func columns(width: CGFloat) -> Int { width >= 680 ? 2 : 1 }
static func cardWidth(size: CGSize) -> CGFloat {
let count = columns(width: size.width)
return max(0, (size.width - 20 - CGFloat(count - 1) * 8) / CGFloat(count))
}
/// Heights are assigned by physical row, including the battery/memory pair at two columns.
/// Physical order: CPU/battery, GPU/storage, memory/network.
static func rowHeights(columns: Int, coreRows: Int, fanCount: Int) -> [CGFloat] {
let cpu = baseCardHeight + CGFloat(max(0, coreRows - 2)) * 26
let cpu: CGFloat = 220 + CGFloat(max(0, coreRows - 2)) * 26
let gpu = baseCardHeight + CGFloat(max(0, (fanCount + 1) / 2 - 1)) * 26
let heights = [cpu, gpu, baseCardHeight, baseCardHeight, baseCardHeight, baseCardHeight]
let count = max(1, min(3, columns))
let heights = [cpu, baseCardHeight, gpu, baseCardHeight, 260, 260]
let count = max(1, min(2, columns))
return stride(from: 0, to: heights.count, by: count).map {
heights[$0..<min($0 + count, heights.count)].max() ?? baseCardHeight
}
@@ -22,13 +23,13 @@ nonisolated enum PanelLayout {
rows.reduce(0, +) + CGFloat(max(0, rows.count - 1)) * 8
}
static func needsResourceScroll(size: CGSize, rows: [CGFloat]) -> Bool {
// Outer padding, toolbar budget, two gaps, and the minimum process area.
resourceHeight(rows: rows) > size.height - 20 - 40 - 16 - 170
// Outer padding, common toolbar/footer, and two gaps. Process page is separate.
resourceHeight(rows: rows) > size.height - 20 - headerHeight(width: size.width) - 18 - 16
}
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))))
CGSize(width: max(1, min(960, visible.width - 32 - max(0, chrome.width))),
height: max(1, min(800, visible.height - 32 - max(0, chrome.height))))
}
static func centeredFrame(_ frame: CGRect, visible: CGRect) -> CGRect {
var result = constrainedFrame(frame, visible: visible)