44 lines
2.0 KiB
Swift
44 lines
2.0 KiB
Swift
import SwiftUI
|
|
|
|
struct MemoryDetailsView: View {
|
|
let memory: MemoryMetrics
|
|
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: 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
|
|
CapacityField(title: labels[index], value: MetricFormat.memory(values[index]), color: colors[index])
|
|
}
|
|
}
|
|
CardSeparator()
|
|
HStack(alignment: .top, spacing: 8) {
|
|
CardField(title: "memory.pressure") { pressure }
|
|
Divider().frame(height: 32)
|
|
CardField(title: "memory.cached") {
|
|
AnimatedMetricText(value: MetricFormat.memory(memory.cached))
|
|
}.help(Text("memory.cachedHelp"))
|
|
Divider().frame(height: 32)
|
|
CardField(title: "memory.swap") {
|
|
AnimatedMetricText(value: MetricFormat.memory(memory.swapUsed))
|
|
}
|
|
}.font(PanelStyle.label).lineLimit(1)
|
|
}
|
|
}
|
|
|
|
@ViewBuilder private var pressure: some View {
|
|
switch memory.pressure {
|
|
case 1: Text("pressure.normal").foregroundStyle(Color("MetricCPU"))
|
|
case 2: Text("pressure.warning").foregroundStyle(.orange)
|
|
case 4: Text("pressure.critical").foregroundStyle(.red)
|
|
default: Text(verbatim: "--").foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
}
|