import SwiftUI struct MemoryDetailsView: View { let memory: MemoryMetrics @Environment(\.accessibilityReduceMotion) private var reduceMotion private var colors: [Color] { [Color("MetricMemory"), Color("MetricNetwork"), Color("MetricDisk"), .secondary.opacity(0.25)] } 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("panel.total").foregroundStyle(.secondary) AnimatedMetricText(value: MetricFormat.percent(memory.usage)).foregroundStyle(Color("MetricMemory")) } 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) 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) } }.font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.7) Divider() HStack(alignment: .top, spacing: 8) { VStack(alignment: .leading, spacing: 4) { Text("memory.pressure").foregroundStyle(.secondary) pressure }.frame(maxWidth: .infinity, alignment: .leading) VStack(alignment: .leading, spacing: 4) { Text("memory.cached").foregroundStyle(.secondary) AnimatedMetricText(value: MetricFormat.memory(memory.cached)) }.frame(maxWidth: .infinity, alignment: .leading) .help(Text("memory.cachedHelp")) VStack(alignment: .leading, spacing: 4) { Text("memory.swap").foregroundStyle(.secondary) AnimatedMetricText(value: MetricFormat.memory(memory.swapUsed)) }.frame(maxWidth: .infinity, alignment: .leading) }.font(.system(size: 10)).lineLimit(1).minimumScaleFactor(0.7) }.padding(.top, 4) } @ViewBuilder private var pressure: some View { switch memory.pressure { case 1: Label("pressure.normal", systemImage: "circle.fill").foregroundStyle(Color("MetricCPU")) case 2: Label("pressure.warning", systemImage: "circle.fill").foregroundStyle(.orange) case 4: Label("pressure.critical", systemImage: "circle.fill").foregroundStyle(.red) default: Text(verbatim: "--").foregroundStyle(.secondary) } } }