fix(ui): 裁剪极小值进度条避免溢出圆角轨道
This commit is contained in:
@@ -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