feat(cpu): 根据核心数量自适应排列进度条

This commit is contained in:
2026-11-03 13:37:01 +08:00
parent 81cde73883
commit 45a6e16bb8
5 changed files with 147 additions and 12 deletions
+1 -12
View File
@@ -12,7 +12,6 @@ struct MenuPanelView: View {
@State private var selectedInterface = ""
@State private var showAddresses = false
@State private var showVolumes = false
@Environment(\.accessibilityReduceMotion) private var reduceMotion
private var snapshot: MetricsSnapshot { metrics.snapshot }
private var samples: [TrendSample] { metrics.history.samples }
@@ -139,17 +138,7 @@ struct MenuPanelView: View {
}
}.font(.system(size: 9)).foregroundStyle(.secondary).frame(maxWidth: .infinity, alignment: .leading)
}
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 6), count: 7), spacing: 5) {
ForEach(Array(cpu.cores.enumerated()), id: \.offset) { index, value in
let kind = CPUCoreTopology.cores[index]
HStack(spacing: 3) {
Text(verbatim: "\(index + 1)").font(.system(size: 9)).frame(width: 12)
MetricProgressBar(value: value, color: coreColor(kind)).frame(height: 7)
.animation(reduceMotion ? nil : .easeInOut(duration: min(0.35, chartInterval * 0.8)), value: value)
}.help((kind.map { coreLabel($0) + Text(verbatim: " · ") } ?? Text("cpu.core")) + Text(verbatim: "\(index + 1): \(MetricFormat.percent(value))"))
.accessibilityLabel(kind.map { coreLabel($0) } ?? Text("cpu.core")).accessibilityValue("\(index + 1): \(MetricFormat.percent(value))")
}
}.padding(.vertical, 3)
CPUCoreGrid(values: cpu.cores, kinds: CPUCoreTopology.cores, interval: chartInterval)
} else { Text("metric.waiting").foregroundStyle(.secondary) }
Spacer(minLength: 0)