refactor(ui): 统一资源卡片规范并收敛面板布局与公共组件

This commit is contained in:
2026-11-03 18:59:45 +08:00
parent a14549bb58
commit 1419bbbe09
16 changed files with 801 additions and 586 deletions
+22 -5
View File
@@ -2,12 +2,29 @@ import Foundation
import CoreGraphics
nonisolated enum PanelLayout {
static func resourceRowHeight(size: CGSize, coreRows: Int) -> CGFloat {
let compact = min(239, max(224, size.height - 581))
let thirdRowExpansion: CGFloat = coreRows >= 3 ? 26 : 0
return min(265, compact + thirdRowExpansion)
static let baseCardHeight: CGFloat = 280
static func columns(width: CGFloat) -> Int { width >= 1160 ? 3 : width >= 900 ? 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.
static func rowHeights(columns: Int, coreRows: Int, fanCount: Int) -> [CGFloat] {
let cpu = baseCardHeight + 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))
return stride(from: 0, to: heights.count, by: count).map {
heights[$0..<min($0 + count, heights.count)].max() ?? baseCardHeight
}
}
static func resourceHeight(rows: [CGFloat]) -> CGFloat {
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
}
static func cardWidth(size: CGSize) -> CGFloat { max(0, (size.width - 36) / 3) }
static func contentSize(visible: CGRect, chrome: CGSize = .zero) -> CGSize {
CGSize(width: max(1, min(1240, visible.width - 32 - max(0, chrome.width))),