feat(ui): 统一实现卡片背景趋势与大数值布局
This commit is contained in:
@@ -10,6 +10,15 @@ extension MenuPanelView {
|
||||
}.frame(height: 14)
|
||||
}
|
||||
|
||||
func inlineMetric(_ title: LocalizedStringKey, _ value: String) -> some View {
|
||||
HStack(spacing: 4) {
|
||||
Text(title).foregroundStyle(.secondary)
|
||||
MetricText(value: value).fontWeight(.medium)
|
||||
}
|
||||
.font(.system(size: 11)).lineLimit(1).minimumScaleFactor(0.8)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
func batteryPowerLabel(_ battery: BatteryMetrics) -> LocalizedStringKey {
|
||||
if battery.charging { return "battery.chargePower" }
|
||||
if !battery.externalPower { return "battery.dischargePower" }
|
||||
@@ -24,15 +33,20 @@ extension MenuPanelView {
|
||||
value: MetricFormat.percent(snapshot.cpu?.usage),
|
||||
status: temperature.map { "\(Int($0.rounded()))°C" },
|
||||
statusWarning: highTemperature,
|
||||
warningText: highTemperature ? Text("cpu.temperature.high", tableName: "CPUDetails") : nil
|
||||
warningText: highTemperature ? Text("cpu.temperature.high", tableName: "CPUDetails") : nil,
|
||||
chart: {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date), first: samples.map(\.cpu),
|
||||
second: samples.map(\.cpuUser), third: samples.map(\.cpuSystem),
|
||||
color: Color("MetricCPU"), secondColor: Color("SeriesUser"), thirdColor: Color("SeriesSystem"),
|
||||
firstLabel: "gpu.totalUtilization", secondLabel: "cpu.user", thirdLabel: "cpu.system", expectedInterval: chartInterval,
|
||||
boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
}
|
||||
) {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date), first: samples.map(\.cpu),
|
||||
second: samples.map(\.cpuUser), third: samples.map(\.cpuSystem),
|
||||
color: Color("MetricCPU"), secondColor: Color("SeriesUser"), thirdColor: Color("SeriesSystem"),
|
||||
firstLabel: "gpu.totalUtilization", secondLabel: "cpu.user", thirdLabel: "cpu.system", expectedInterval: chartInterval,
|
||||
boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
CardSeparator()
|
||||
HStack(spacing: 12) {
|
||||
inlineMetric("cpu.user", MetricFormat.percent(snapshot.cpu?.user))
|
||||
inlineMetric("cpu.system", MetricFormat.percent(snapshot.cpu?.system))
|
||||
}.frame(height: 14)
|
||||
if let cpu = snapshot.cpu {
|
||||
CPUCoreGrid(
|
||||
values: cpu.cores, kinds: CPUCoreTopology.cores,
|
||||
@@ -48,17 +62,22 @@ extension MenuPanelView {
|
||||
return ResourceCard(
|
||||
title: "metric.gpu", symbol: "square.grid.2x2", color: Color("MetricGPU"), value: MetricFormat.percent(snapshot.gpuUsage),
|
||||
status: snapshot.gpuTemperature.map { "\(Int($0.rounded()))°C" },
|
||||
detail: snapshot.gpu?.coreCount.map { String(format: AppLocalization.string("gpu.coreCountFormat", locale: locale), $0) }
|
||||
detail: snapshot.gpu?.coreCount.map { String(format: AppLocalization.string("gpu.coreCountFormat", locale: locale), $0) },
|
||||
chart: {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date), first: samples.map(\.gpu),
|
||||
second: samples.map(\.gpuRenderer), third: samples.map(\.gpuTiler),
|
||||
color: Color("MetricGPU"), secondColor: Color("MetricCPU"), thirdColor: Color("SeriesSystem"),
|
||||
firstLabel: "gpu.totalUtilization", secondLabel: "gpu.renderer", thirdLabel: "gpu.tiler",
|
||||
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
}
|
||||
) {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date), first: samples.map(\.gpu),
|
||||
second: samples.map(\.gpuRenderer), third: samples.map(\.gpuTiler),
|
||||
color: Color("MetricGPU"), secondColor: Color("MetricCPU"), thirdColor: Color("SeriesSystem"),
|
||||
firstLabel: "gpu.totalUtilization", secondLabel: "gpu.renderer", thirdLabel: "gpu.tiler",
|
||||
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
HStack(spacing: 12) {
|
||||
inlineMetric("gpu.renderer", MetricFormat.percent(snapshot.gpu?.renderer))
|
||||
inlineMetric("gpu.tiler", MetricFormat.percent(snapshot.gpu?.tiler))
|
||||
}.frame(height: 14)
|
||||
let fans = displayedFans
|
||||
if !fans.isEmpty {
|
||||
CardSeparator()
|
||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 10), count: min(2, fans.count)), spacing: 4) {
|
||||
ForEach(fans) { fan in
|
||||
FanSpeedIndicator(
|
||||
@@ -68,12 +87,9 @@ extension MenuPanelView {
|
||||
.frame(height: 16)
|
||||
}
|
||||
}
|
||||
.modifier(CardInset())
|
||||
} else if snapshot.fans == nil {
|
||||
CardSeparator()
|
||||
Text("metric.waiting").font(PanelStyle.label)
|
||||
.frame(maxWidth: .infinity, alignment: .leading).frame(height: 16)
|
||||
.modifier(CardInset())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,22 +102,22 @@ extension MenuPanelView {
|
||||
String(format: "%.1f / %.0f GiB", Double($0.used) / 1_073_741_824, Double($0.total) / 1_073_741_824)
|
||||
} ?? "--",
|
||||
status: snapshot.memory.map { MetricFormat.percent($0.usage) },
|
||||
detail: header.title, detailColor: header.color, detailHelp: header.help
|
||||
detail: header.title, detailColor: header.color, detailHelp: header.help,
|
||||
chart: {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date),
|
||||
first: samples.map { $0.memory.map { $0 * Double(snapshot.memory?.total ?? 1) } },
|
||||
second: samples.map(\.memoryApp), third: samples.map(\.memoryWired), fourth: samples.map(\.memoryCompressed),
|
||||
color: Color("MemoryApplication"), secondColor: Color("MemoryApplication"),
|
||||
thirdColor: Color("MemoryWired"), fourthColor: Color("MemoryCompressed"), fixedScale: Double(snapshot.memory?.total ?? 1),
|
||||
firstValueFormat: .memory, firstLabel: "gpu.totalUtilization",
|
||||
secondLabel: "memory.app", thirdLabel: "memory.wired", fourthLabel: "memory.compressed",
|
||||
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
}
|
||||
) {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date),
|
||||
first: samples.map { $0.memory.map { $0 * Double(snapshot.memory?.total ?? 1) } },
|
||||
second: samples.map(\.memoryApp), third: samples.map(\.memoryWired), fourth: samples.map(\.memoryCompressed),
|
||||
color: Color("MetricCPU"), secondColor: Color("MemoryApplication"),
|
||||
thirdColor: Color("MemoryWired"), fourthColor: Color("MemoryCompressed"), fixedScale: Double(snapshot.memory?.total ?? 1),
|
||||
scaleLabel: MetricFormat.memory(snapshot.memory?.total), firstValueFormat: .memory, firstLabel: "gpu.totalUtilization",
|
||||
secondLabel: "memory.app", thirdLabel: "memory.wired", fourthLabel: "memory.compressed",
|
||||
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals,
|
||||
showsLegendValues: cardContentWidth >= 340)
|
||||
if let memory = snapshot.memory {
|
||||
MemoryDetailsView(memory: memory)
|
||||
} else {
|
||||
CardSeparator()
|
||||
Text("metric.waiting").foregroundStyle(.secondary)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
@@ -114,15 +130,19 @@ extension MenuPanelView {
|
||||
String(
|
||||
format: "%.0f / %.0f GB", Double($0.total - min($0.total, $0.available)) / 1_000_000_000,
|
||||
Double($0.total) / 1_000_000_000)
|
||||
} ?? "--"
|
||||
} ?? "--",
|
||||
chart: {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date), first: samples.map(\.read), second: samples.map(\.write), color: Color("MetricDisk"),
|
||||
secondColor: Color("MetricNetwork"), fixedScale: nil, firstLabel: "disk.read", secondLabel: "disk.write",
|
||||
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals, visibleSeriesCount: 2
|
||||
)
|
||||
}
|
||||
) {
|
||||
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date), first: samples.map(\.read), second: samples.map(\.write), color: Color("MetricDisk"),
|
||||
secondColor: Color("MetricNetwork"), fixedScale: nil, firstLabel: "disk.read", secondLabel: "disk.write",
|
||||
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals
|
||||
)
|
||||
|
||||
HStack(spacing: 12) {
|
||||
inlineMetric("disk.read", MetricFormat.rate(snapshot.diskIO?.read))
|
||||
inlineMetric("disk.write", MetricFormat.rate(snapshot.diskIO?.written))
|
||||
}.frame(height: 14)
|
||||
StorageDetailsView(disk: snapshot.disk, health: snapshot.diskHealth) {
|
||||
showVolumes.toggle()
|
||||
}
|
||||
@@ -150,24 +170,27 @@ extension MenuPanelView {
|
||||
var batteryCard: some View {
|
||||
ResourceCard(
|
||||
title: "metric.battery", symbol: "battery.100percent", color: Color("MetricBattery"),
|
||||
value: MetricFormat.percent(snapshot.battery?.charge)
|
||||
value: MetricFormat.percent(snapshot.battery?.charge),
|
||||
chart: {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date),
|
||||
first: samples.map(\.battery),
|
||||
second: samples.map(\.batteryPower),
|
||||
color: Color("MetricBattery"),
|
||||
secondColor: Color("SeriesUser"),
|
||||
fixedScale: 1,
|
||||
secondSeriesUsesAutonomousScale: true,
|
||||
secondValueFormat: .watts,
|
||||
firstLabel: "metric.battery",
|
||||
secondLabel: snapshot.battery.map(batteryPowerLabel) ?? "battery.power",
|
||||
expectedInterval: chartInterval,
|
||||
boundaryDates: chartBoundaries,
|
||||
intervals: chartIntervals
|
||||
)
|
||||
}
|
||||
) {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date),
|
||||
first: samples.map(\.battery),
|
||||
second: samples.map(\.batteryPower),
|
||||
color: Color("MetricBattery"),
|
||||
secondColor: Color("SeriesUser"),
|
||||
fixedScale: 1,
|
||||
secondSeriesUsesAutonomousScale: true,
|
||||
secondValueFormat: .watts,
|
||||
firstLabel: "metric.battery",
|
||||
secondLabel: snapshot.battery.map(batteryPowerLabel) ?? "battery.power",
|
||||
expectedInterval: chartInterval,
|
||||
boundaryDates: chartBoundaries,
|
||||
intervals: chartIntervals
|
||||
)
|
||||
CardSeparator()
|
||||
inlineMetric(snapshot.battery.map(batteryPowerLabel) ?? "battery.power", MetricFormat.watts(snapshot.battery?.power))
|
||||
.frame(height: 14)
|
||||
if let battery = snapshot.battery {
|
||||
batteryDetails(battery)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user