fix(ui): 裁剪极小值进度条避免溢出圆角轨道
This commit is contained in:
@@ -114,10 +114,7 @@ struct MenuPanelView: View {
|
||||
ForEach(Array(cpu.cores.enumerated()), id: \.offset) { index, value in
|
||||
HStack(spacing: 3) {
|
||||
Text(verbatim: "\(index + 1)").font(.system(size: 9)).frame(width: 12)
|
||||
GeometryReader { proxy in
|
||||
Capsule().fill(Color("MetricCPU").opacity(0.15))
|
||||
Capsule().fill(Color("MetricCPU")).frame(width: proxy.size.width * value)
|
||||
}.frame(height: 7)
|
||||
MetricProgressBar(value: value, color: Color("MetricCPU")).frame(height: 7)
|
||||
}.help("\(index + 1): \(MetricFormat.percent(value))")
|
||||
.accessibilityLabel(Text("cpu.core")).accessibilityValue("\(index + 1): \(MetricFormat.percent(value))")
|
||||
}
|
||||
|
||||
@@ -44,10 +44,8 @@ struct ProcessTableView: View {
|
||||
TableColumn("panel.path") { row in Text(verbatim: row.path ?? "--").lineLimit(1).truncationMode(.middle).foregroundStyle(.secondary) }.width(min: 150, ideal: 400)
|
||||
TableColumn("CPU %") { row in
|
||||
HStack(spacing: 6) {
|
||||
GeometryReader { proxy in
|
||||
Capsule().fill(Color("MetricCPU").opacity(0.15))
|
||||
if let cpu = row.cpu { Capsule().fill(Color("MetricCPU")).frame(width: proxy.size.width * min(1, max(0, cpu / Double(max(1, logicalCPUCount))))) }
|
||||
}.frame(width: 45, height: 6).accessibilityHidden(true)
|
||||
MetricProgressBar(value: (row.cpu ?? 0) / Double(max(1, logicalCPUCount)), color: Color("MetricCPU"))
|
||||
.frame(width: 45, height: 6).accessibilityHidden(true)
|
||||
Text(verbatim: row.cpu.map { String(format: "%.1f", $0 * 100) } ?? "--").frame(maxWidth: .infinity, alignment: .trailing)
|
||||
}
|
||||
}.width(105)
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Clips both layers to the track, including fills narrower than the track height.
|
||||
struct MetricProgressBar: View {
|
||||
let value: Double
|
||||
let color: Color
|
||||
|
||||
private var fraction: Double { value.isFinite ? min(1, max(0, value)) : 0 }
|
||||
|
||||
var body: some View {
|
||||
GeometryReader { proxy in
|
||||
ZStack(alignment: .leading) {
|
||||
Capsule().fill(color.opacity(0.15))
|
||||
if fraction > 0 {
|
||||
Capsule().fill(color).frame(width: proxy.size.width * fraction)
|
||||
}
|
||||
}
|
||||
.frame(width: proxy.size.width, height: proxy.size.height)
|
||||
.clipShape(Capsule())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user