// StereoWidthBadge.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import SwiftUI /// A small pill badge indicating whether a chain point is mono (width 1) or stereo (width 2). /// /// Pass `PedalBoard.width` (or any channel count). Width `2` shows a cyan "STEREO" pill; /// anything else shows a dim "MONO" pill. Width is structural (it changes only when pedals /// are added or removed), so the badge does not need to observe live parameter state — the /// surrounding board view rebuilds when the chain changes. /// /// ## Usage /// /// ```swift /// StereoWidthBadge(width: board.width) /// ``` public struct StereoWidthBadge: View { // MARK: - Layout constants private static let fontSize: CGFloat = 9 private static let paddingH: CGFloat = 7 private static let paddingV: CGFloat = 3 private static let cornerRadius: CGFloat = 4 private static let stereoWidth: Int = 2 private static let monoFillOpacity: Double = 0.14 private static let stereoFillOpacity: Double = 0.85 private static let monoTextOpacity: Double = 0.45 private static let borderOpacity: Double = 0.30 private static let borderLineWidth: CGFloat = 0.5 // MARK: - Properties private let width: Int // MARK: - Init /// Creates a width badge. /// /// - Parameter width: Channel count at this chain point (`PedalBoard.width`). `2` renders /// the stereo badge; any other value renders the mono badge. public init(width: Int) { self.width = width } // MARK: - Body public var body: some View { let isStereo: Bool = (width == StereoWidthBadge.stereoWidth) Text(isStereo ? "STEREO" : "MONO") .font(.system(size: StereoWidthBadge.fontSize, weight: .bold, design: .monospaced)) .foregroundStyle(isStereo ? Color.black : Color.white.opacity(StereoWidthBadge.monoTextOpacity)) .padding(.horizontal, StereoWidthBadge.paddingH) .padding(.vertical, StereoWidthBadge.paddingV) .background( RoundedRectangle(cornerRadius: StereoWidthBadge.cornerRadius) .fill( isStereo ? Color.cyan.opacity(StereoWidthBadge.stereoFillOpacity) : Color.white.opacity(StereoWidthBadge.monoFillOpacity) ) .overlay( RoundedRectangle(cornerRadius: StereoWidthBadge.cornerRadius) .stroke( Color.white.opacity(StereoWidthBadge.borderOpacity), lineWidth: StereoWidthBadge.borderLineWidth ) ) ) } }