fix(ui): 缩小卡片并还原设计稿紧凑排布
This commit is contained in:
@@ -3,11 +3,11 @@ import SwiftUI
|
||||
|
||||
extension MenuPanelView {
|
||||
func line(_ key: LocalizedStringKey, _ value: String) -> some View {
|
||||
HStack(alignment: .firstTextBaseline) {
|
||||
Text(key).font(PanelStyle.label).foregroundStyle(.secondary)
|
||||
HStack(alignment: .firstTextBaseline, spacing: 4) {
|
||||
Text(key).font(.system(size: 9)).foregroundStyle(.secondary)
|
||||
Spacer(minLength: 6)
|
||||
MetricText(value: value).font(PanelStyle.value)
|
||||
}.frame(height: 14)
|
||||
MetricText(value: value).font(.system(size: 9, weight: .medium))
|
||||
}.frame(height: 12)
|
||||
}
|
||||
|
||||
func inlineMetric(_ title: LocalizedStringKey, _ value: String) -> some View {
|
||||
@@ -15,8 +15,7 @@ extension MenuPanelView {
|
||||
Text(title).foregroundStyle(.secondary)
|
||||
MetricText(value: value).fontWeight(.medium)
|
||||
}
|
||||
.font(.system(size: 11)).lineLimit(1).minimumScaleFactor(0.8)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.8)
|
||||
}
|
||||
|
||||
func batteryPowerLabel(_ battery: BatteryMetrics) -> LocalizedStringKey {
|
||||
@@ -43,10 +42,10 @@ extension MenuPanelView {
|
||||
boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
}
|
||||
) {
|
||||
HStack(spacing: 12) {
|
||||
HStack(spacing: 5) {
|
||||
inlineMetric("cpu.user", MetricFormat.percent(snapshot.cpu?.user))
|
||||
inlineMetric("cpu.system", MetricFormat.percent(snapshot.cpu?.system))
|
||||
}.frame(height: 14)
|
||||
}.frame(height: 12)
|
||||
if let cpu = snapshot.cpu {
|
||||
CPUCoreGrid(
|
||||
values: cpu.cores, kinds: CPUCoreTopology.cores,
|
||||
@@ -62,7 +61,6 @@ 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) },
|
||||
chart: {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date), first: samples.map(\.gpu),
|
||||
@@ -72,24 +70,28 @@ extension MenuPanelView {
|
||||
expectedInterval: chartInterval, boundaryDates: chartBoundaries, intervals: chartIntervals)
|
||||
}
|
||||
) {
|
||||
HStack(spacing: 12) {
|
||||
HStack(spacing: 5) {
|
||||
if let count = snapshot.gpu?.coreCount {
|
||||
Text(verbatim: String(format: AppLocalization.string("gpu.coreCountFormat", locale: locale), count))
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
inlineMetric("gpu.renderer", MetricFormat.percent(snapshot.gpu?.renderer))
|
||||
inlineMetric("gpu.tiler", MetricFormat.percent(snapshot.gpu?.tiler))
|
||||
}.frame(height: 14)
|
||||
}.font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.75).frame(height: 12)
|
||||
let fans = displayedFans
|
||||
if !fans.isEmpty {
|
||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 10), count: min(2, fans.count)), spacing: 4) {
|
||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 5, alignment: .leading), count: min(2, fans.count)), spacing: 2) {
|
||||
ForEach(fans) { fan in
|
||||
FanSpeedIndicator(
|
||||
title: fans.count == 2
|
||||
? (fan.id == 0 ? Text("gpu.fanLeft") : Text("gpu.fanRight"))
|
||||
: Text("gpu.fanNumber \(fan.id + 1)"), rpm: fan.rpm)
|
||||
.frame(height: 16)
|
||||
.frame(height: 12)
|
||||
}
|
||||
}
|
||||
} else if snapshot.fans == nil {
|
||||
Text("metric.waiting").font(PanelStyle.label)
|
||||
.frame(maxWidth: .infinity, alignment: .leading).frame(height: 16)
|
||||
Text("metric.waiting").font(.system(size: 9))
|
||||
.frame(maxWidth: .infinity, alignment: .leading).frame(height: 12)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,8 +103,8 @@ extension MenuPanelView {
|
||||
value: snapshot.memory.map {
|
||||
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.badgeTitle, detailColor: snapshot.memory?.pressure == 1 ? Color("MetricBattery") : header.color,
|
||||
detailHelp: header.help + "\n" + MetricFormat.percent(snapshot.memory?.usage),
|
||||
chart: {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date),
|
||||
@@ -131,6 +133,9 @@ extension MenuPanelView {
|
||||
format: "%.0f / %.0f GB", Double($0.total - min($0.total, $0.available)) / 1_000_000_000,
|
||||
Double($0.total) / 1_000_000_000)
|
||||
} ?? "--",
|
||||
headerAccessory: AnyView(Button { showVolumes.toggle() } label: {
|
||||
HStack(spacing: 2) { Text("disk.localVolumes"); Image(systemName: "chevron.right").font(.system(size: 7)) }
|
||||
}.font(.system(size: 9)).buttonStyle(.plain).help(Text("disk.viewDetails"))),
|
||||
chart: {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date), first: samples.map(\.read), second: samples.map(\.write), color: Color("MetricDisk"),
|
||||
@@ -139,13 +144,7 @@ extension MenuPanelView {
|
||||
)
|
||||
}
|
||||
) {
|
||||
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()
|
||||
}
|
||||
StorageDetailsView(disk: snapshot.disk, health: snapshot.diskHealth, io: snapshot.diskIO)
|
||||
.popover(isPresented: $showVolumes) {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text("disk.homeVolume")
|
||||
@@ -171,6 +170,7 @@ extension MenuPanelView {
|
||||
ResourceCard(
|
||||
title: "metric.battery", symbol: "battery.100percent", color: Color("MetricBattery"),
|
||||
value: MetricFormat.percent(snapshot.battery?.charge),
|
||||
status: snapshot.battery.map { AppLocalization.string($0.externalPower ? "battery.acPower" : "battery.batterySource", locale: locale) },
|
||||
chart: {
|
||||
PanelTrendChart(
|
||||
dates: samples.map(\.date),
|
||||
@@ -189,49 +189,33 @@ extension MenuPanelView {
|
||||
)
|
||||
}
|
||||
) {
|
||||
inlineMetric(snapshot.battery.map(batteryPowerLabel) ?? "battery.power", MetricFormat.watts(snapshot.battery?.power))
|
||||
.frame(height: 14)
|
||||
inlineMetric("battery.powerShort", MetricFormat.watts(snapshot.battery?.power))
|
||||
.frame(height: 12)
|
||||
if let battery = snapshot.battery {
|
||||
batteryDetails(battery)
|
||||
} else {
|
||||
Text(snapshot.batteryState == .absent ? "panel.noBattery" : "panel.batteryFailed").foregroundStyle(.secondary)
|
||||
.font(PanelStyle.label).frame(maxWidth: .infinity).frame(height: 32)
|
||||
.font(.system(size: 9)).frame(maxWidth: .infinity).frame(height: 32)
|
||||
}
|
||||
}
|
||||
}
|
||||
private func batteryDetails(_ battery: BatteryMetrics) -> some View {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
HStack(alignment: .top, spacing: 10) {
|
||||
VStack(spacing: 4) {
|
||||
line("battery.health", MetricFormat.percent(battery.health))
|
||||
HStack {
|
||||
Text("battery.powerSource").foregroundStyle(.secondary)
|
||||
Spacer(minLength: 4)
|
||||
Text(battery.externalPower ? "battery.acPower" : "battery.batterySource").font(PanelStyle.value)
|
||||
}.frame(height: 14)
|
||||
}
|
||||
Rectangle().fill(.primary.opacity(0.08)).frame(width: 1, height: 32)
|
||||
VStack(spacing: 4) {
|
||||
line("battery.cycles", battery.cycles.map(String.init) ?? "--")
|
||||
HStack {
|
||||
Text("battery.timeEstimate").foregroundStyle(.secondary)
|
||||
Spacer(minLength: 4)
|
||||
if battery.externalPower {
|
||||
Text("battery.notApplicableShort").font(PanelStyle.value)
|
||||
.help(Text("battery.timeNotApplicable"))
|
||||
} else if let minutes = battery.minutesRemaining {
|
||||
MetricText(value: "\(minutes) min").font(PanelStyle.value)
|
||||
} else {
|
||||
Text("battery.timeUnknown").font(PanelStyle.value)
|
||||
}
|
||||
}.frame(height: 14)
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
HStack(spacing: 8) {
|
||||
inlineMetric("battery.healthShort", MetricFormat.percent(battery.health))
|
||||
inlineMetric("battery.cyclesShort", battery.cycles.map(String.init) ?? "--")
|
||||
}
|
||||
HStack(spacing: 4) {
|
||||
Text("battery.timeShort").foregroundStyle(.secondary)
|
||||
if battery.externalPower {
|
||||
Text("battery.notApplicableShort").help(Text("battery.timeNotApplicable"))
|
||||
} else if let minutes = battery.minutesRemaining {
|
||||
MetricText(value: "\(minutes) min")
|
||||
} else {
|
||||
Text("battery.timeUnknown")
|
||||
}
|
||||
}
|
||||
.font(PanelStyle.label)
|
||||
.lineLimit(1)
|
||||
.frame(height: 32)
|
||||
|
||||
}.frame(maxWidth: .infinity, alignment: .topLeading)
|
||||
}
|
||||
.font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.75)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user