feat(panel): 调整资源卡片读数布局并保留趋势平移

逐核显示 CPU 占用,在 GPU 标题展示核数并补充分项读数。无电池设备显示整机功率。

存储与网络将曲线排在详情下方,CPU、GPU、内存和电池保留整卡趋势。数值直接刷新,曲线随采样平滑平移。顶栏展示版本号,底栏调整开机时间和刷新间隔。
This commit is contained in:
2026-11-15 22:03:46 +08:00
parent c886c4227d
commit 6300db3d15
27 changed files with 427 additions and 250 deletions
+30 -13
View File
@@ -1,6 +1,11 @@
import SwiftUI
/// One fixed-size native host owns foreground, background trend and hover presentation.
enum CardChartPlacement {
case background
case belowDetails
}
/// One native host owns the text, chart and hover presentation.
struct ResourceCard<Chart: View, Content: View>: View {
let title: LocalizedStringKey
let symbol: String
@@ -9,6 +14,7 @@ struct ResourceCard<Chart: View, Content: View>: View {
var secondaryValue: String? = nil
var valueColor: Color? = nil
var secondaryValueColor: Color? = nil
var titleBadge: String? = nil
var status: String? = nil
var statusWarning = false
var warningText: Text? = nil
@@ -16,6 +22,7 @@ struct ResourceCard<Chart: View, Content: View>: View {
var detailColor: Color? = nil
var detailHelp: String? = nil
var headerAccessory: AnyView? = nil
var chartPlacement: CardChartPlacement = .belowDetails
@ViewBuilder var chart: () -> Chart
@ViewBuilder var content: () -> Content
@Environment(\.colorScheme) private var colorScheme
@@ -24,15 +31,17 @@ struct ResourceCard<Chart: View, Content: View>: View {
private var cardBody: some View {
GeometryReader { bounds in
ZStack(alignment: .bottomLeading) {
chart()
.frame(width: bounds.size.width, height: bounds.size.height)
VStack(alignment: .leading, spacing: 0) {
foreground
Spacer(minLength: 0)
VStack(alignment: .leading, spacing: ResourceCardMetrics.gap) {
foreground
.padding(.horizontal, ResourceCardMetrics.padding)
.padding(.top, ResourceCardMetrics.padding)
if chartPlacement == .belowDetails {
chart().frame(maxWidth: .infinity, maxHeight: .infinity).clipped()
}
.padding(ResourceCardMetrics.padding)
.frame(width: bounds.size.width, height: bounds.size.height, alignment: .topLeading)
}
.frame(width: bounds.size.width, height: bounds.size.height, alignment: .topLeading)
.background {
if chartPlacement == .background { chart() }
}
.background(Color("PanelCard"))
.clipShape(.rect(cornerRadius: ResourceCardMetrics.radius))
@@ -48,7 +57,7 @@ struct ResourceCard<Chart: View, Content: View>: View {
if let tooltip {
let plot = proxy[tooltip.plot]
ChartTooltipLayer(point: CGPoint(x: plot.minX + tooltip.point.x, y: plot.minY + tooltip.point.y),
minimumY: max(ResourceCardMetrics.tooltipMinimumY, plot.minY)) {
minimumY: ResourceCardMetrics.tooltipMinimumY) {
tooltip.content.fixedSize(horizontal: false, vertical: true)
}
.frame(width: proxy.size.width, height: proxy.size.height)
@@ -84,9 +93,17 @@ struct ResourceCard<Chart: View, Content: View>: View {
Image(systemName: symbol).foregroundStyle(statusWarning ? .red : color)
}
.font(.system(size: 11, weight: .semibold)).fixedSize()
if let titleBadge {
Text(verbatim: titleBadge)
.font(.system(size: 9, weight: .semibold)).monospacedDigit()
.foregroundStyle(.secondary)
.padding(.horizontal, 5).frame(height: 14)
.background(.primary.opacity(0.08), in: Capsule())
.fixedSize()
}
Spacer(minLength: 4)
if let status {
Text(verbatim: status)
MetricText(value: status)
.font(.system(size: 10, weight: .medium))
.foregroundStyle(statusWarning ? .red : .secondary)
.help(warningText ?? Text(verbatim: status))
@@ -126,10 +143,10 @@ private struct MetricHeadline: View {
Image(systemName: direction == "↓" ? "arrow.down" : "arrow.up")
.font(.system(size: 12, weight: .medium)).foregroundStyle(color)
}
Text(verbatim: parts.first.map(String.init) ?? value)
MetricText(value: parts.first.map(String.init) ?? value)
.font(.system(size: compact ? 16 : 28, weight: .semibold))
if parts.count > 1 {
Text(verbatim: String(parts[1]))
MetricText(value: String(parts[1]))
.font(.system(size: compact ? 10 : 12, weight: .medium))
.foregroundStyle(Color.primary.opacity(0.8))
}