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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user