fix(ui): 缩小卡片并还原设计稿紧凑排布
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Keep two balanced rows when possible; add rows to preserve readable core values.
|
||||
/// One row per core kind; every equal-width meter represents one real core.
|
||||
struct CPUCoreGrid: View {
|
||||
let values: [Double]
|
||||
let kinds: [Int: CPUCoreTopology.Kind]
|
||||
@@ -14,8 +14,18 @@ struct CPUCoreGrid: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func label(_ kind: CPUCoreTopology.Kind) -> Text {
|
||||
switch kind {
|
||||
private func label(_ kind: CPUCoreTopology.Kind, compact: Bool = false) -> Text {
|
||||
if compact {
|
||||
switch kind {
|
||||
case .efficiency: return Text("cpu.kind.efficiencyShort", tableName: "CPUDetails")
|
||||
case .middle: return Text("cpu.kind.performanceShort", tableName: "CPUDetails")
|
||||
case .performance:
|
||||
return kinds.values.contains(.middle)
|
||||
? Text("cpu.kind.superShort", tableName: "CPUDetails")
|
||||
: Text("cpu.kind.performanceShort", tableName: "CPUDetails")
|
||||
}
|
||||
}
|
||||
return switch kind {
|
||||
case .efficiency: Text("cpu.kind.efficiency", tableName: "CPUDetails")
|
||||
case .middle: Text("cpu.kind.performance", tableName: "CPUDetails")
|
||||
case .performance:
|
||||
@@ -30,80 +40,73 @@ struct CPUCoreGrid: View {
|
||||
return order.map { kind in (0..<max(0, count)).filter { kinds[$0] == kind } }.filter { !$0.isEmpty }
|
||||
}
|
||||
|
||||
static let labelWidth: CGFloat = 44
|
||||
|
||||
static func groupWidths(groups: [[Int]], width: CGFloat) -> [CGFloat] {
|
||||
let weights = groups.map { CGFloat(($0.count + 1) / 2) }
|
||||
let total = max(1, weights.reduce(0, +))
|
||||
let available = max(0, width - CGFloat(max(0, groups.count - 1)) * 13)
|
||||
return weights.map { available * $0 / total }
|
||||
let available = width.isFinite ? max(0, width - labelWidth - 6) : 0
|
||||
return Array(repeating: available, count: groups.count)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
let groups = Self.groups(count: values.count, kinds: kinds)
|
||||
GeometryReader { geometry in
|
||||
let widths = Self.groupWidths(groups: groups, width: geometry.size.width)
|
||||
HStack(alignment: .top, spacing: 6) {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
ForEach(groups.indices, id: \.self) { group in
|
||||
if group > 0 {
|
||||
Rectangle().fill(.primary.opacity(0.08)).frame(width: 1)
|
||||
}
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
HStack(spacing: 3) {
|
||||
Circle().fill(color(kinds[groups[group][0]])).frame(width: 5, height: 5)
|
||||
if let kind = kinds[groups[group][0]] { label(kind) }
|
||||
HStack(alignment: .top, spacing: 6) {
|
||||
HStack(spacing: 2) {
|
||||
Circle().fill(color(kinds[groups[group][0]])).frame(width: 3, height: 3)
|
||||
if let kind = kinds[groups[group][0]] { label(kind, compact: true) }
|
||||
else { Text("cpu.core") }
|
||||
Text(verbatim: "\(groups[group].count)").foregroundStyle(.secondary)
|
||||
}
|
||||
.font(.system(size: 9, weight: .medium))
|
||||
.lineLimit(1).minimumScaleFactor(0.6)
|
||||
.font(.system(size: 8, weight: .medium))
|
||||
.lineLimit(1).minimumScaleFactor(0.65)
|
||||
.frame(width: Self.labelWidth, height: CPUCoreGridLayout.rowHeight, alignment: .leading)
|
||||
CPUCoreGridLayout {
|
||||
ForEach(groups[group], id: \.self) { index in
|
||||
core(index: index)
|
||||
}
|
||||
ForEach(groups[group], id: \.self) { index in core(index: index) }
|
||||
}
|
||||
}.frame(width: widths[group], alignment: .topLeading)
|
||||
.frame(width: widths[group])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(height: 15 + CGFloat(maxRows(groups: groups)) * 22 + CGFloat(max(0, maxRows(groups: groups) - 1)) * 4)
|
||||
.padding(.vertical, 1)
|
||||
.frame(height: gridHeight(groups: groups))
|
||||
}
|
||||
|
||||
// Match the content width so row reservation agrees with placement.
|
||||
var availableWidth: CGFloat = 380
|
||||
var availableWidth: CGFloat = 185
|
||||
|
||||
private func maxRows(groups: [[Int]]) -> Int {
|
||||
private func gridHeight(groups: [[Int]]) -> CGFloat {
|
||||
let widths = Self.groupWidths(groups: groups, width: availableWidth)
|
||||
return zip(groups, widths).map { CPUCoreGridLayout.rowCounts(count: $0.0.count, width: $0.1).count }.max() ?? 0
|
||||
let rows = zip(groups, widths).map { CPUCoreGridLayout.rowCounts(count: $0.0.count, width: $0.1).count }.reduce(0, +)
|
||||
return CGFloat(rows) * CPUCoreGridLayout.rowHeight + CGFloat(max(0, rows - 1)) * CPUCoreGridLayout.rowSpacing
|
||||
}
|
||||
|
||||
private func core(index: Int) -> some View {
|
||||
let kind = kinds[index]
|
||||
let value = values[index].isFinite ? min(1, max(0, values[index])) : 0
|
||||
return VStack(spacing: 3) {
|
||||
Text(verbatim: "\(Int((value * 100).rounded()))")
|
||||
.font(.system(size: 8, weight: .medium)).monospacedDigit().lineLimit(1)
|
||||
MetricProgressBar(value: value, color: color(kind)).frame(height: 3)
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.help(Text("\(kind.map { label($0) } ?? Text("cpu.core")) · \(index + 1): \(MetricFormat.percent(value))"))
|
||||
.accessibilityElement(children: .ignore)
|
||||
.accessibilityLabel(kind.map { label($0) } ?? Text("cpu.core"))
|
||||
.accessibilityValue("\(index + 1): \(MetricFormat.percent(value))")
|
||||
let measured = values[index].isFinite ? values[index] : nil
|
||||
return MetricProgressBar(value: measured ?? 0, color: color(kind), cornerRadius: 2)
|
||||
.frame(height: 8)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.help(Text("\(kind.map { label($0) } ?? Text("cpu.core")) · \(index + 1): \(MetricFormat.percent(measured))"))
|
||||
.accessibilityElement(children: .ignore)
|
||||
.accessibilityLabel(kind.map { label($0) } ?? Text("cpu.core"))
|
||||
.accessibilityValue("\(index + 1): \(MetricFormat.percent(measured))")
|
||||
}
|
||||
}
|
||||
|
||||
struct CPUCoreGridLayout: Layout {
|
||||
static let columnSpacing: CGFloat = 6
|
||||
static let columnSpacing: CGFloat = 3
|
||||
static let rowSpacing: CGFloat = 4
|
||||
static let rowHeight: CGFloat = 22
|
||||
static let minimumTwoRowCellWidth: CGFloat = 16
|
||||
static let rowHeight: CGFloat = 10
|
||||
static let minimumCellWidth: CGFloat = 8
|
||||
|
||||
static func rowCounts(count: Int, width: CGFloat) -> [Int] {
|
||||
guard count > 0 else { return [] }
|
||||
guard count > 1 else { return [1] }
|
||||
let usableWidth = width.isFinite ? max(0, width) : 0
|
||||
let capacity = max(1, Int(min(CGFloat(count), (usableWidth + columnSpacing) / (minimumTwoRowCellWidth + columnSpacing))))
|
||||
let rows = max(2, (count + capacity - 1) / capacity)
|
||||
let capacity = max(1, Int(min(CGFloat(count), (usableWidth + columnSpacing) / (minimumCellWidth + columnSpacing))))
|
||||
let rows = max(1, (count + capacity - 1) / capacity)
|
||||
let quotient = count / rows, remainder = count % rows
|
||||
return (0..<rows).map { quotient + ($0 < remainder ? 1 : 0) }
|
||||
}
|
||||
@@ -117,8 +120,8 @@ struct CPUCoreGridLayout: Layout {
|
||||
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
|
||||
let rows = Self.rowCounts(count: subviews.count, width: bounds.width)
|
||||
guard let columns = rows.max(), columns > 0 else { return }
|
||||
let spacing = min(Self.columnSpacing, max(0, (bounds.width / CGFloat(columns) - 18) / 2))
|
||||
let cellWidth = max(0, (bounds.width - CGFloat(columns - 1) * spacing) / CGFloat(columns))
|
||||
let spacing = min(Self.columnSpacing, max(0, (bounds.width / CGFloat(columns) - Self.minimumCellWidth) / 2))
|
||||
let cellWidth = min(Self.minimumCellWidth, max(0, (bounds.width - CGFloat(columns - 1) * spacing) / CGFloat(columns)))
|
||||
var index = 0
|
||||
for (row, count) in rows.enumerated() {
|
||||
for column in 0..<count {
|
||||
|
||||
@@ -2,21 +2,32 @@ 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"]
|
||||
private let labels: [LocalizedStringKey] = ["memory.appShort", "memory.wiredShort", "memory.compressedShort"]
|
||||
private var colors: [Color] { [Color("MemoryApplication"), Color("MemoryWired"), Color("MemoryCompressed"), Color("MemoryAvailable")] }
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
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])
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack(spacing: 3) {
|
||||
ForEach(0..<3) { index in
|
||||
if index > 0 { Text("·").foregroundStyle(.secondary) }
|
||||
HStack(spacing: 2) {
|
||||
Text(labels[index])
|
||||
MetricText(value: String(format: "%.1f", Double(values[index]) / 1_073_741_824))
|
||||
}
|
||||
.help(Text(MetricFormat.memory(values[index])))
|
||||
}
|
||||
Text(verbatim: "GiB")
|
||||
}
|
||||
.font(.system(size: 8)).foregroundStyle(.secondary)
|
||||
.lineLimit(1).minimumScaleFactor(0.75)
|
||||
CapacityBar(values: values.map { Double($0) }, colors: colors, total: Double(memory.total), height: 4)
|
||||
HStack(spacing: 4) {
|
||||
Text("memory.available").foregroundStyle(.secondary)
|
||||
MetricText(value: MetricFormat.memory(memory.available))
|
||||
}.font(.system(size: 9)).lineLimit(1)
|
||||
}
|
||||
.accessibilityElement(children: .contain)
|
||||
.accessibilityLabel(Text("memory.distribution"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ struct MemoryHeaderInfo {
|
||||
}
|
||||
|
||||
var title: String { pressure.key.map(localized) ?? "--" }
|
||||
var badgeTitle: String { pressure.key == nil ? "--" : localized("memory.pressurePrefix") + title }
|
||||
var color: Color { pressure.color }
|
||||
var help: String {
|
||||
"\(localized("memory.pressure")): \(title)\n"
|
||||
|
||||
@@ -15,21 +15,21 @@ extension MenuPanelView {
|
||||
).id(selectedInterface)
|
||||
}
|
||||
) {
|
||||
HStack(spacing: 12) {
|
||||
networkTotal(
|
||||
"network.received", value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.received }),
|
||||
symbol: "arrow.down", color: Color("MetricMemory"))
|
||||
networkTotal(
|
||||
"network.sent", value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.sent }),
|
||||
symbol: "arrow.up", color: Color("SeriesUpload"))
|
||||
}
|
||||
VStack(spacing: 4) {
|
||||
HStack(spacing: 3) {
|
||||
Text("network.totalShort").foregroundStyle(.secondary)
|
||||
Image(systemName: "arrow.down").foregroundStyle(Color("MetricMemory"))
|
||||
MetricText(value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.received }))
|
||||
Text("·").foregroundStyle(.secondary)
|
||||
Image(systemName: "arrow.up").foregroundStyle(Color("SeriesUpload"))
|
||||
MetricText(value: network.isEmpty ? "--" : MetricFormat.bytes(network.reduce(0) { $0 + $1.sent }))
|
||||
}.font(.system(size: 8)).lineLimit(1).minimumScaleFactor(0.75)
|
||||
VStack(spacing: 3) {
|
||||
networkAddress("network.public", address: publicIPAddress)
|
||||
networkAddress(
|
||||
"network.local",
|
||||
address: addressInterface?.addresses.first(where: { !$0.contains(":") }) ?? addressInterface?.addresses.first)
|
||||
}
|
||||
.font(PanelStyle.label)
|
||||
.font(.system(size: 9))
|
||||
.accessibilityElement(children: .contain)
|
||||
.accessibilityLabel(Text("network.addresses"))
|
||||
}
|
||||
@@ -44,7 +44,7 @@ extension MenuPanelView {
|
||||
ForEach(snapshot.network ?? [], id: \.identity) { item in
|
||||
Text(verbatim: item.name).tag(item.identity)
|
||||
}
|
||||
}.labelsHidden().controlSize(.mini).frame(maxWidth: 100)
|
||||
}.labelsHidden().controlSize(.mini).fixedSize().frame(maxWidth: 70)
|
||||
}
|
||||
.help(Text(networkStatusLabel))
|
||||
.accessibilityElement(children: .contain)
|
||||
@@ -54,7 +54,7 @@ extension MenuPanelView {
|
||||
func networkAddress(_ title: LocalizedStringKey, address: String?) -> some View {
|
||||
HStack(spacing: 3) {
|
||||
Text(title).foregroundStyle(.secondary)
|
||||
Text(verbatim: address ?? "--").font(PanelStyle.value).monospacedDigit().textSelection(.enabled)
|
||||
Text(verbatim: address ?? "--").font(.system(size: 9, weight: .medium)).monospacedDigit().textSelection(.enabled)
|
||||
.help(Text(verbatim: address ?? "--"))
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
if let address {
|
||||
@@ -62,21 +62,12 @@ extension MenuPanelView {
|
||||
NSPasteboard.general.clearContents()
|
||||
NSPasteboard.general.setString(address, forType: .string)
|
||||
} label: {
|
||||
Image(systemName: "doc.on.doc")
|
||||
Image(systemName: "doc.on.doc").frame(width: 14, height: 14)
|
||||
}
|
||||
.buttonStyle(.plain).accessibilityLabel(Text("panel.copy"))
|
||||
}
|
||||
}.frame(maxWidth: .infinity, alignment: .leading).lineLimit(1)
|
||||
}
|
||||
func networkTotal(_ title: LocalizedStringKey, value: String, symbol: String, color: Color) -> some View {
|
||||
CardField(title: title) {
|
||||
HStack(spacing: 3) {
|
||||
Image(systemName: symbol).foregroundStyle(color)
|
||||
MetricText(value: value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var networkStatusLabel: LocalizedStringKey {
|
||||
switch snapshot.networkPath {
|
||||
case .available: "network.pathAvailable"
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ struct MenuPanelView: View {
|
||||
let coreCount = max(CPUCoreTopology.cores.count, ProcessInfo.processInfo.processorCount, snapshot.cpu?.cores.count ?? 0)
|
||||
let groups = CPUCoreGrid.groups(count: coreCount, kinds: CPUCoreTopology.cores)
|
||||
let widths = CPUCoreGrid.groupWidths(groups: groups, width: cardContentWidth)
|
||||
let coreRows = zip(groups, widths).map { CPUCoreGridLayout.rowCounts(count: $0.0.count, width: $0.1).count }.max() ?? 0
|
||||
let coreRows = zip(groups, widths).map { CPUCoreGridLayout.rowCounts(count: $0.0.count, width: $0.1).count }.reduce(0, +)
|
||||
let fanCount = reservedFanCount > 0 ? max(reservedFanCount, snapshot.fans?.count ?? 0) : snapshot.fans?.count
|
||||
return PanelLayout.cardHeights(coreRows: coreRows, fanCount: fanCount)
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@ nonisolated enum PanelCard: Int, CaseIterable {
|
||||
|
||||
nonisolated enum PanelLayout {
|
||||
static let footerHeight: CGFloat = 26
|
||||
static let maximumWidth: CGFloat = 960
|
||||
static let maximumWidth: CGFloat = ResourceCardMetrics.preferredWidth * 3 + 32
|
||||
static let maximumHeight: CGFloat = 800
|
||||
static func headerHeight(width: CGFloat) -> CGFloat { width >= 560 ? 32 : 64 }
|
||||
static func columns(width: CGFloat) -> Int { width >= 900 ? 3 : width >= 560 ? 2 : 1 }
|
||||
static func columns(width: CGFloat) -> Int { width >= 620 ? 3 : width >= 430 ? 2 : 1 }
|
||||
static func cardWidth(size: CGSize) -> CGFloat {
|
||||
let count = columns(width: size.width)
|
||||
return max(0, (size.width - 20 - CGFloat(count - 1) * 8) / CGFloat(count))
|
||||
return max(0, (size.width - 20 - CGFloat(count - 1) * 6) / CGFloat(count))
|
||||
}
|
||||
|
||||
/// Keep reading order stable across three-, two- and single-column grids.
|
||||
@@ -29,8 +29,8 @@ nonisolated enum PanelLayout {
|
||||
static func cardHeights(coreRows: Int, fanCount: Int?) -> [PanelCard: CGFloat] {
|
||||
let base = ResourceCardMetrics.minimumHeight
|
||||
let fanRows = fanCount.map { (max(0, $0) + 1) / 2 } ?? 1
|
||||
return [.cpu: base + CGFloat(max(0, coreRows - 2)) * 26,
|
||||
.gpu: base + CGFloat(max(0, fanRows - 1)) * 20,
|
||||
return [.cpu: base + CGFloat(max(0, coreRows - 2)) * 14,
|
||||
.gpu: base + CGFloat(max(0, fanRows - 1)) * 14,
|
||||
.memory: base, .battery: base, .storage: base, .network: base]
|
||||
}
|
||||
|
||||
@@ -42,12 +42,12 @@ nonisolated enum PanelLayout {
|
||||
|
||||
static func resourceHeight(columns: Int, heights: [PanelCard: CGFloat]) -> CGFloat {
|
||||
let rows = rowHeights(columns: columns, heights: heights)
|
||||
return rows.reduce(0, +) + CGFloat(max(0, rows.count - 1)) * 8
|
||||
return rows.reduce(0, +) + CGFloat(max(0, rows.count - 1)) * 6
|
||||
}
|
||||
|
||||
static func preferredHeight(width: CGFloat, heights: [PanelCard: CGFloat]) -> CGFloat {
|
||||
min(maximumHeight, resourceHeight(columns: columns(width: width), heights: heights)
|
||||
+ 20 + headerHeight(width: width) + footerHeight + 16)
|
||||
+ 20 + headerHeight(width: width) + footerHeight + 12)
|
||||
}
|
||||
|
||||
static var defaultHeight: CGFloat {
|
||||
@@ -56,7 +56,7 @@ nonisolated enum PanelLayout {
|
||||
|
||||
static func needsResourceScroll(size: CGSize, heights: [PanelCard: CGFloat]) -> Bool {
|
||||
resourceHeight(columns: columns(width: size.width), heights: heights)
|
||||
> size.height - 20 - headerHeight(width: size.width) - footerHeight - 16
|
||||
> size.height - 20 - headerHeight(width: size.width) - footerHeight - 12
|
||||
}
|
||||
|
||||
static func contentSize(visible: CGRect, chrome: CGSize = .zero, preferredHeight: CGFloat? = nil) -> CGSize {
|
||||
|
||||
@@ -40,7 +40,7 @@ import AppKit
|
||||
controller.show()
|
||||
if let value = ProcessInfo.processInfo.environment["KYMO_AUDIT_SIZE"] {
|
||||
let parts = value.split(separator: "x").compactMap { Double($0) }
|
||||
if parts.count == 2, parts.allSatisfy({ $0.isFinite }), parts[0] >= 480, parts[1] >= 360 {
|
||||
if parts.count == 2, parts.allSatisfy({ $0.isFinite }), parts[0] >= 360, parts[1] >= 360 {
|
||||
controller.panel.setContentSize(CGSize(width: min(parts[0], controller.panel.frame.width),
|
||||
height: min(parts[1], controller.panel.frame.height)))
|
||||
}
|
||||
|
||||
@@ -3,39 +3,28 @@ import SwiftUI
|
||||
struct StorageDetailsView: View {
|
||||
let disk: DiskMetrics?
|
||||
let health: DiskHealthMetrics?
|
||||
let showVolumes: () -> Void
|
||||
let io: DiskIOMetrics?
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
HStack(spacing: 8) {
|
||||
VStack(spacing: 4) {
|
||||
field("memory.available", value: MetricFormat.bytes(disk?.available))
|
||||
field("disk.powerOnHours", value: health?.powerOnHours.map { "\($0) h" } ?? "--")
|
||||
}
|
||||
Divider().frame(height: 32)
|
||||
VStack(spacing: 4) {
|
||||
field("disk.remainingLife", value: MetricFormat.percent(health?.remainingLife))
|
||||
Button(action: showVolumes) {
|
||||
HStack(spacing: 3) {
|
||||
Text("disk.localVolumes")
|
||||
Spacer(minLength: 3)
|
||||
Image(systemName: "chevron.right").font(.system(size: 8))
|
||||
}.contentShape(.rect)
|
||||
}
|
||||
.buttonStyle(.plain).help(Text("disk.viewDetails"))
|
||||
.frame(height: 14)
|
||||
}
|
||||
}.font(PanelStyle.label).lineLimit(1)
|
||||
field("memory.available", value: MetricFormat.bytes(disk?.available))
|
||||
HStack(spacing: 6) {
|
||||
field("disk.read", value: MetricFormat.rate(io?.read))
|
||||
field("disk.write", value: MetricFormat.rate(io?.written))
|
||||
}
|
||||
HStack(spacing: 4) {
|
||||
field("disk.lifeShort", value: MetricFormat.percent(health?.remainingLife))
|
||||
Text("·").foregroundStyle(.secondary)
|
||||
field("disk.powerOnShort", value: health?.powerOnHours.map { "\($0) h" } ?? "--")
|
||||
}.font(.system(size: 8))
|
||||
}
|
||||
.font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.75)
|
||||
}
|
||||
|
||||
private func field(_ title: LocalizedStringKey, value: String) -> some View {
|
||||
HStack(spacing: 3) {
|
||||
Text(title).foregroundStyle(.secondary).help(Text(title))
|
||||
Spacer(minLength: 3)
|
||||
MetricText(value: value).font(PanelStyle.value)
|
||||
MetricText(value: value)
|
||||
}
|
||||
.frame(height: 14)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,75 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"cpu.kind.efficiencyShort": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "E-cores"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "能效核"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "能效核"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"cpu.kind.performanceShort": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "P-cores"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "性能核"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "效能核"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"cpu.kind.superShort": {
|
||||
"extractionState": "manual",
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "S-cores"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "超大核"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "超大核"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"version": "1.0"
|
||||
|
||||
@@ -1,6 +1,248 @@
|
||||
{
|
||||
"sourceLanguage" : "en",
|
||||
"strings" : {
|
||||
"disk.lifeShort" : {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Life"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "剩余寿命"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "剩餘壽命"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"disk.powerOnShort" : {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "On-time"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "通电"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "通電"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"battery.healthShort" : {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Health"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "健康"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "健康"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"battery.cyclesShort" : {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Cycles"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "循环"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "循環"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"battery.timeShort" : {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Time"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "续航"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "續航"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"battery.powerShort" : {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Power"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "功率"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "功率"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"memory.appShort" : {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "App"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "应用"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "應用"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"memory.wiredShort" : {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Wired"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "联动"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "連動"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"memory.compressedShort" : {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Compressed"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "压缩"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "壓縮"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"memory.pressurePrefix" : {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Pressure "
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "压力"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "壓力"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"network.totalShort" : {
|
||||
"localizations": {
|
||||
"en": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "Total"
|
||||
}
|
||||
},
|
||||
"zh-Hans": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "累计"
|
||||
}
|
||||
},
|
||||
"zh-Hant": {
|
||||
"stringUnit": {
|
||||
"state": "translated",
|
||||
"value": "累計"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"battery.notApplicableShort" : {
|
||||
"localizations" : {
|
||||
"en" : {
|
||||
|
||||
@@ -192,7 +192,7 @@ struct NativePanelCurve: NSViewRepresentable {
|
||||
private final class SeriesLayer {
|
||||
let root = CALayer(), area = CAShapeLayer(), line = CAShapeLayer(), points = CAShapeLayer()
|
||||
init() {
|
||||
line.fillColor = nil; line.lineWidth = 1.8; line.lineCap = .round; line.lineJoin = .round
|
||||
line.fillColor = nil; line.lineWidth = 1.4; line.lineCap = .round; line.lineJoin = .round
|
||||
root.addSublayer(area); root.addSublayer(line); root.addSublayer(points)
|
||||
}
|
||||
func resize(_ bounds: CGRect) {
|
||||
|
||||
@@ -80,14 +80,14 @@ struct PanelTrendChart: View {
|
||||
}
|
||||
}
|
||||
private func tooltip(index: Int) -> some View {
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
Text(dates[index], format: .dateTime.hour().minute().second()).foregroundStyle(.secondary)
|
||||
tooltipRow(firstLabel, values: first, tint: color, index: index)
|
||||
if !second.isEmpty { tooltipRow(secondLabel, values: second, tint: secondColor, format: secondValueFormat, index: index) }
|
||||
if !third.isEmpty { tooltipRow(thirdLabel, values: third, tint: thirdColor, index: index) }
|
||||
if !fourth.isEmpty { tooltipRow(fourthLabel, values: fourth, tint: fourthColor, index: index) }
|
||||
}
|
||||
.font(.system(size: 10)).padding(8)
|
||||
.font(.system(size: 9)).padding(6)
|
||||
.background { TooltipBackground() }
|
||||
.overlay(RoundedRectangle(cornerRadius: 7).strokeBorder(.primary.opacity(0.2)))
|
||||
}
|
||||
|
||||
@@ -5,15 +5,11 @@ struct FanSpeedIndicator: View {
|
||||
let rpm: Double?
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 5) {
|
||||
Image(systemName: "fanblades.fill")
|
||||
.foregroundStyle(.secondary)
|
||||
.frame(width: 14, height: 14).accessibilityHidden(true)
|
||||
HStack(spacing: 4) {
|
||||
title.foregroundStyle(.secondary)
|
||||
Spacer(minLength: 2)
|
||||
MetricText(value: rpm.map { "\(Int($0.rounded())) RPM" } ?? "-- RPM")
|
||||
.monospacedDigit().fontWeight(.medium)
|
||||
}
|
||||
.font(.system(size: 10)).lineLimit(1).minimumScaleFactor(0.7)
|
||||
.font(.system(size: 9)).lineLimit(1).minimumScaleFactor(0.7)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,19 @@ import SwiftUI
|
||||
struct MetricProgressBar: View {
|
||||
let value: Double
|
||||
let color: Color
|
||||
var cornerRadius: CGFloat? = nil
|
||||
|
||||
private var fraction: Double { value.isFinite ? min(1, max(0, value)) : 0 }
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { proxy in
|
||||
let shape = RoundedRectangle(cornerRadius: cornerRadius ?? proxy.size.height / 2, style: .continuous)
|
||||
ZStack(alignment: .leading) {
|
||||
Capsule().fill(color.opacity(0.15))
|
||||
Capsule().fill(color).frame(width: proxy.size.width * fraction)
|
||||
shape.fill(color.opacity(0.15))
|
||||
shape.fill(color).frame(width: proxy.size.width * fraction)
|
||||
}
|
||||
.frame(width: proxy.size.width, height: proxy.size.height)
|
||||
.clipShape(Capsule())
|
||||
.clipShape(shape)
|
||||
.transaction { $0.animation = nil; $0.disablesAnimations = true }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ enum PanelStyle {
|
||||
static let value = Font.system(size: 10, weight: .medium)
|
||||
static let legend = Font.system(size: 9)
|
||||
static let padding: CGFloat = 10
|
||||
static let gap: CGFloat = 8
|
||||
static let gap: CGFloat = 6
|
||||
static let titleHeight: CGFloat = 20
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ struct CapacityBar: View {
|
||||
let values: [Double]
|
||||
let colors: [Color]
|
||||
let total: Double
|
||||
var height: CGFloat = 8
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { bounds in
|
||||
@@ -49,7 +50,7 @@ struct CapacityBar: View {
|
||||
}
|
||||
.clipShape(Capsule())
|
||||
}
|
||||
.frame(height: 8)
|
||||
.frame(height: height)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ struct ResourceCard<Chart: View, Content: View>: View {
|
||||
.frame(width: bounds.size.width, height: ResourceCardMetrics.plotHeight)
|
||||
VStack(alignment: .leading, spacing: ResourceCardMetrics.gap) {
|
||||
header
|
||||
HStack(alignment: .firstTextBaseline, spacing: 12) {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 6) {
|
||||
MetricHeadline(value: value, compact: secondaryValue != nil, color: valueColor ?? .primary)
|
||||
if let secondaryValue {
|
||||
MetricHeadline(value: secondaryValue, compact: true, color: secondaryValueColor ?? .primary)
|
||||
@@ -40,18 +40,18 @@ struct ResourceCard<Chart: View, Content: View>: View {
|
||||
content()
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
.font(PanelStyle.label)
|
||||
.font(.system(size: 9))
|
||||
.padding(ResourceCardMetrics.padding)
|
||||
.padding(.bottom, ResourceCardMetrics.plotHeight - ResourceCardMetrics.padding)
|
||||
.frame(width: bounds.size.width, height: bounds.size.height, alignment: .topLeading)
|
||||
}
|
||||
.background(Color("PanelCard"))
|
||||
.clipShape(.rect(cornerRadius: ResourceCardMetrics.radius))
|
||||
.overlay(RoundedRectangle(cornerRadius: ResourceCardMetrics.radius).strokeBorder(.primary.opacity(0.07)))
|
||||
.overlay(RoundedRectangle(cornerRadius: ResourceCardMetrics.radius).strokeBorder(.primary.opacity(colorScheme == .dark ? 0.06 : 0.025)))
|
||||
.background {
|
||||
RoundedRectangle(cornerRadius: ResourceCardMetrics.radius)
|
||||
.fill(Color("PanelCard"))
|
||||
.shadow(color: .black.opacity(colorScheme == .dark ? 0.16 : 0.06), radius: 6, x: 0, y: 2)
|
||||
.shadow(color: .black.opacity(colorScheme == .dark ? 0.12 : 0.05), radius: 4, x: 0, y: 1)
|
||||
}
|
||||
}
|
||||
.overlayPreferenceValue(ChartTooltipPreference.self) { tooltip in
|
||||
@@ -77,19 +77,19 @@ struct ResourceCard<Chart: View, Content: View>: View {
|
||||
} icon: {
|
||||
Image(systemName: symbol).foregroundStyle(statusWarning ? .red : color)
|
||||
}
|
||||
.font(.system(size: 14, weight: .semibold)).fixedSize()
|
||||
.font(.system(size: 11, weight: .semibold)).fixedSize()
|
||||
Spacer(minLength: 4)
|
||||
if let status {
|
||||
Text(verbatim: status)
|
||||
.font(.system(size: 11, weight: .medium))
|
||||
.font(.system(size: 9, weight: .medium))
|
||||
.foregroundStyle(statusWarning ? .red : .secondary)
|
||||
.help(warningText ?? Text(verbatim: status))
|
||||
.accessibilityLabel(warningText.map { Text("\(status) \($0)") } ?? Text(verbatim: status))
|
||||
}
|
||||
if let detail {
|
||||
Text(verbatim: detail)
|
||||
.font(.system(size: 10, weight: .medium)).foregroundStyle(detailColor ?? .secondary)
|
||||
.padding(.horizontal, 6).frame(height: 18)
|
||||
.font(.system(size: 8, weight: .medium)).foregroundStyle(detailColor ?? .secondary)
|
||||
.padding(.horizontal, 5).frame(height: 14)
|
||||
.background((detailColor ?? .primary).opacity(0.10), in: Capsule())
|
||||
.lineLimit(1)
|
||||
.help(Text(verbatim: detailHelp ?? detail))
|
||||
@@ -115,20 +115,20 @@ private struct MetricHeadline: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 3) {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 2) {
|
||||
if let direction {
|
||||
Image(systemName: direction == "↓" ? "arrow.down" : "arrow.up")
|
||||
.font(.system(size: 16, weight: .medium))
|
||||
.font(.system(size: 12, weight: .medium)).foregroundStyle(color)
|
||||
}
|
||||
Text(verbatim: parts.first.map(String.init) ?? value)
|
||||
.font(.system(size: compact ? 23 : 36, weight: .semibold))
|
||||
.font(.system(size: compact ? 16 : 28, weight: .semibold))
|
||||
if parts.count > 1 {
|
||||
Text(verbatim: String(parts[1]))
|
||||
.font(.system(size: compact ? 11 : 14, weight: .medium))
|
||||
.foregroundStyle(Color.secondary)
|
||||
.font(.system(size: compact ? 9 : 12, weight: .medium))
|
||||
.foregroundStyle(Color.primary.opacity(0.8))
|
||||
}
|
||||
}
|
||||
.monospacedDigit().foregroundStyle(color)
|
||||
.monospacedDigit().foregroundStyle(.primary)
|
||||
.lineLimit(1).minimumScaleFactor(0.75)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.help(Text(verbatim: value))
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import CoreGraphics
|
||||
|
||||
/// Shared geometry for resource foregrounds, background plots and panel budgets.
|
||||
/// Compact native geometry: card width and height are 2/3 of the first implementation.
|
||||
nonisolated enum ResourceCardMetrics {
|
||||
static let minimumHeight: CGFloat = 264
|
||||
static let padding: CGFloat = 16
|
||||
static let radius: CGFloat = 20
|
||||
static let plotHeight: CGFloat = 72
|
||||
static let titleHeight: CGFloat = 20
|
||||
static let headlineHeight: CGFloat = 44
|
||||
static let gap: CGFloat = 6
|
||||
static let tooltipMinimumY: CGFloat = 96
|
||||
static let preferredWidth: CGFloat = 308 * 2 / 3
|
||||
static let minimumHeight: CGFloat = 176
|
||||
static let padding: CGFloat = 10
|
||||
static let radius: CGFloat = 16
|
||||
static let plotHeight: CGFloat = 48
|
||||
static let titleHeight: CGFloat = 14
|
||||
static let headlineHeight: CGFloat = 34
|
||||
static let gap: CGFloat = 4
|
||||
static let tooltipMinimumY: CGFloat = 68
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user