72 lines
3.7 KiB
Swift
72 lines
3.7 KiB
Swift
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)
|
|
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)
|
|
Divider().frame(height: 30)
|
|
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"))
|
|
Divider().frame(height: 30)
|
|
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)
|
|
}
|
|
}
|
|
}
|