feat(ui): 实现全卡堆叠趋势与单页资源进程布局
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import SwiftUI
|
||||
|
||||
/// Four square blocks fill from bottom to top; partial blocks retain the actual fraction.
|
||||
struct SegmentedCoreBar: View {
|
||||
let value: Double?
|
||||
let color: Color
|
||||
|
||||
static func portions(_ value: Double?, count: Int = 4) -> [Double] {
|
||||
guard count > 0 else { return [] }
|
||||
let fraction = value.flatMap { $0.isFinite ? min(1, max(0, $0)) : nil } ?? 0
|
||||
return (0..<count).map { min(1, max(0, fraction * Double(count) - Double($0))) }
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
let fills = Self.portions(value)
|
||||
VStack(spacing: 2) {
|
||||
ForEach(Array(fills.indices.reversed()), id: \.self) { index in
|
||||
ZStack(alignment: .bottom) {
|
||||
Rectangle().fill(color.opacity(0.15))
|
||||
Rectangle().fill(color).frame(height: 6 * fills[index])
|
||||
}.frame(width: 6, height: 6).clipped()
|
||||
}
|
||||
}
|
||||
.accessibilityHidden(true)
|
||||
.transaction { $0.animation = nil; $0.disablesAnimations = true }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user