hudini/Sources/HUDini/HUDView.swift

52 lines
1.5 KiB
Swift
Raw Normal View History

import SwiftUI
struct HUDView: View {
let volume: Float
let isMuted: Bool
private let totalBars = 16
private let cornerRadius: CGFloat = 18
var filledBars: Int {
if isMuted { return 0 }
return Int(round(Double(volume) * Double(totalBars)))
}
var speakerIcon: String {
if isMuted { return "speaker.slash.fill" }
if volume == 0 { return "speaker.fill" }
if volume < 0.33 { return "speaker.wave.1.fill" }
if volume < 0.66 { return "speaker.wave.2.fill" }
return "speaker.wave.3.fill"
}
var body: some View {
VStack(spacing: 16) {
Image(systemName: speakerIcon)
.font(.system(size: 48, weight: .medium))
.foregroundColor(.white)
.frame(height: 60)
HStack(spacing: 4) {
ForEach(0..<totalBars, id: \.self) { index in
RoundedRectangle(cornerRadius: 2)
.fill(index < filledBars ? Color.white : Color.white.opacity(0.2))
.frame(height: 24)
}
}
.padding(.horizontal, 20)
}
.frame(width: 200, height: 200)
.background(
RoundedRectangle(cornerRadius: cornerRadius)
.fill(.ultraThinMaterial)
.environment(\.colorScheme, .dark)
)
.background(
RoundedRectangle(cornerRadius: cornerRadius)
.fill(Color.black.opacity(0.55))
)
}
}