feat(ui): 实现全卡堆叠趋势与单页资源进程布局
This commit is contained in:
@@ -9,7 +9,7 @@ nonisolated enum PanelLayout {
|
||||
static let footerHeight: CGFloat = 26
|
||||
static let maximumWidth: CGFloat = ResourceCardMetrics.preferredWidth * 3 + 32
|
||||
static let maximumHeight: CGFloat = 800
|
||||
static func headerHeight(width: CGFloat) -> CGFloat { width >= 560 ? 32 : 64 }
|
||||
static func headerHeight(width: CGFloat) -> CGFloat { 32 }
|
||||
static func columns(width: CGFloat) -> Int { width >= 620 ? 3 : width >= 430 ? 2 : 1 }
|
||||
static func cardWidth(size: CGSize) -> CGFloat {
|
||||
let count = columns(width: size.width)
|
||||
@@ -25,19 +25,21 @@ nonisolated enum PanelLayout {
|
||||
}
|
||||
}
|
||||
|
||||
/// Foreground details and the edge-to-edge background trend have separate budgets.
|
||||
/// Structural foreground height determines the full-height background chart.
|
||||
static func cardHeights(coreRows: Int, fanCount: Int?) -> [PanelCard: CGFloat] {
|
||||
let base = ResourceCardMetrics.minimumHeight
|
||||
let fanRows = fanCount.map { (max(0, $0) + 1) / 2 } ?? 1
|
||||
return [.cpu: base + CGFloat(max(0, coreRows - 2)) * 14,
|
||||
return [.cpu: base + CGFloat(max(0, coreRows - 1)) * 34,
|
||||
.gpu: base + CGFloat(max(0, fanRows - 1)) * 14,
|
||||
.memory: base, .battery: base, .storage: base, .network: base]
|
||||
}
|
||||
|
||||
static func rowHeights(columns: Int, heights: [PanelCard: CGFloat]) -> [CGFloat] {
|
||||
cardRows(columns: columns).map { cards in
|
||||
cards.map { heights[$0] ?? 0 }.max() ?? 0
|
||||
}
|
||||
Array(repeating: processHeight(heights: heights), count: cardRows(columns: columns).count)
|
||||
}
|
||||
|
||||
static func processHeight(heights: [PanelCard: CGFloat]) -> CGFloat {
|
||||
heights.values.max() ?? ResourceCardMetrics.minimumHeight
|
||||
}
|
||||
|
||||
static func resourceHeight(columns: Int, heights: [PanelCard: CGFloat]) -> CGFloat {
|
||||
@@ -45,17 +47,21 @@ nonisolated enum PanelLayout {
|
||||
return rows.reduce(0, +) + CGFloat(max(0, rows.count - 1)) * 6
|
||||
}
|
||||
|
||||
static func dashboardHeight(columns: Int, heights: [PanelCard: CGFloat]) -> CGFloat {
|
||||
resourceHeight(columns: columns, heights: heights) + 6 + processHeight(heights: heights)
|
||||
}
|
||||
|
||||
static func preferredHeight(width: CGFloat, heights: [PanelCard: CGFloat]) -> CGFloat {
|
||||
min(maximumHeight, resourceHeight(columns: columns(width: width), heights: heights)
|
||||
min(maximumHeight, dashboardHeight(columns: columns(width: width), heights: heights)
|
||||
+ 20 + headerHeight(width: width) + footerHeight + 12)
|
||||
}
|
||||
|
||||
static var defaultHeight: CGFloat {
|
||||
preferredHeight(width: maximumWidth, heights: cardHeights(coreRows: 2, fanCount: nil))
|
||||
preferredHeight(width: maximumWidth, heights: cardHeights(coreRows: 1, fanCount: nil))
|
||||
}
|
||||
|
||||
static func needsResourceScroll(size: CGSize, heights: [PanelCard: CGFloat]) -> Bool {
|
||||
resourceHeight(columns: columns(width: size.width), heights: heights)
|
||||
static func needsDashboardScroll(size: CGSize, heights: [PanelCard: CGFloat]) -> Bool {
|
||||
dashboardHeight(columns: columns(width: size.width), heights: heights)
|
||||
> size.height - 20 - headerHeight(width: size.width) - footerHeight - 12
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user