fix(ui): 裁剪极小值进度条避免溢出圆角轨道

This commit is contained in:
2026-11-03 12:58:27 +08:00
parent 8a7303f6b2
commit df96d6853f
5 changed files with 33 additions and 8 deletions
@@ -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())
}
}
}