refactor(ui): 统一资源卡片规范并收敛面板布局与公共组件
This commit is contained in:
@@ -2,62 +2,34 @@ import SwiftUI
|
||||
|
||||
struct MemoryDetailsView: View {
|
||||
let memory: MemoryMetrics
|
||||
@Environment(\.accessibilityReduceMotion) private var reduceMotion
|
||||
private var colors: [Color] { [Color("MemoryApplication"), Color("MemoryWired"), Color("MemoryCompressed"), Color("MemoryAvailable")] }
|
||||
private var values: [UInt64] { [memory.app, memory.wired, memory.compressed, memory.available] }
|
||||
private let labels: [LocalizedStringKey] = ["memory.app", "memory.wired", "memory.compressed", "memory.available"]
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 9) {
|
||||
Divider()
|
||||
HStack {
|
||||
Text("memory.distribution").fontWeight(.semibold)
|
||||
Spacer()
|
||||
Text("gpu.totalUtilization").foregroundStyle(.secondary)
|
||||
AnimatedMetricText(value: MetricFormat.percent(memory.usage)).foregroundStyle(Color("MemoryApplication"))
|
||||
}
|
||||
GeometryReader { proxy in
|
||||
HStack(spacing: 0) {
|
||||
ForEach(0..<4) { index in
|
||||
Rectangle().fill(colors[index])
|
||||
.frame(width: CGFloat(values[index]) / CGFloat(max(1, memory.total)) * proxy.size.width)
|
||||
}
|
||||
}
|
||||
// Round the combined shape; tiny segments never receive a minimum width.
|
||||
.clipShape(Capsule())
|
||||
.animation(reduceMotion ? nil : .easeInOut(duration: 0.35), value: values)
|
||||
}.frame(height: 8).accessibilityHidden(true)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
CardSeparator()
|
||||
CardSectionHeader(title: "memory.distribution", valueLabel: "gpu.totalUtilization",
|
||||
value: MetricFormat.percent(memory.usage), color: Color("MemoryApplication"))
|
||||
CapacityBar(values: values.map { Double($0) }, colors: colors, total: Double(memory.total))
|
||||
HStack(spacing: 4) {
|
||||
ForEach(0..<4) { index in
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack(spacing: 3) {
|
||||
Circle().fill(colors[index]).frame(width: 4, height: 4)
|
||||
Text(labels[index]).foregroundStyle(.secondary)
|
||||
}
|
||||
AnimatedMetricText(value: MetricFormat.memory(values[index]))
|
||||
.fontWeight(.medium).monospacedDigit()
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
CapacityField(title: labels[index], value: MetricFormat.memory(values[index]), color: colors[index])
|
||||
}
|
||||
}.font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.7)
|
||||
Divider()
|
||||
}
|
||||
CardSeparator()
|
||||
HStack(alignment: .top, spacing: 8) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("memory.pressure").foregroundStyle(.secondary)
|
||||
pressure
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
Divider().frame(height: 30)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("memory.cached").foregroundStyle(.secondary)
|
||||
CardField(title: "memory.pressure") { pressure }
|
||||
Divider().frame(height: 32)
|
||||
CardField(title: "memory.cached") {
|
||||
AnimatedMetricText(value: MetricFormat.memory(memory.cached))
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.help(Text("memory.cachedHelp"))
|
||||
Divider().frame(height: 30)
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text("memory.swap").foregroundStyle(.secondary)
|
||||
}.help(Text("memory.cachedHelp"))
|
||||
Divider().frame(height: 32)
|
||||
CardField(title: "memory.swap") {
|
||||
AnimatedMetricText(value: MetricFormat.memory(memory.swapUsed))
|
||||
}.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}.font(.system(size: 10)).lineLimit(1).minimumScaleFactor(0.7)
|
||||
}.padding(.top, 4)
|
||||
}
|
||||
}.font(PanelStyle.label).lineLimit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private var pressure: some View {
|
||||
|
||||
Reference in New Issue
Block a user