Files
Kymo/kymo/UI/Components/MetricProgressBar.swift
T

24 lines
846 B
Swift

import SwiftUI
/// Clips both layers to the track, including fills narrower than the track height.
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) {
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(shape)
.transaction { $0.animation = nil; $0.disablesAnimations = true }
}
}
}