// ParallelSectionView.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import SwiftUI import LyrebirdUI import LyrebirdShoeGaze /// Renders a ``ParallelSection`` as a horizontal parallel rack. /// /// Layout (left → right): /// 1. ``SplitterView`` — mode selector and branch LED indicators. /// 2. A central `VStack` with two labelled branch rows: /// - **A** row: one ``PedalView`` per pedal in `section.branchA`. /// - **B** row: one ``PedalView`` per pedal in `section.branchB`. /// Empty branches show a placeholder label. /// /// `ParallelSection` does not expose a `Merger`; the merger is owned by `PedalBoard` /// and is not part of the section object. Only the splitter and branch pedal rows are /// rendered here. The view wraps its central panel in a horizontal `ScrollView` so /// wide branch chains do not overflow the window. /// /// ## Usage /// /// ```swift /// ParallelSectionView(section: parallelSection) /// ``` public struct ParallelSectionView: View { // MARK: - Layout constants private static let outerSpacing: CGFloat = 16 private static let branchStackSpacing: CGFloat = 12 private static let pedalSpacing: CGFloat = 16 private static let branchLabelFontSize: CGFloat = 11 private static let branchLabelOpacity: Double = 0.55 private static let emptyBranchOpacity: Double = 0.30 private static let emptyBranchFontSize: CGFloat = 11 private static let scrollPaddingH: CGFloat = 12 private static let scrollPaddingV: CGFloat = 8 private static let branchSeparatorOpacity: Double = 0.15 private static let branchSeparatorHeight: CGFloat = 1 // MARK: - Properties private let section: ParallelSection // MARK: - Init /// Creates a parallel section view for the given ``ParallelSection``. /// /// - Parameter section: The `ParallelSection` to render. Both branch pedal arrays /// and the splitter's enable nodes are read from this instance. public init(section: ParallelSection) { self.section = section } // MARK: - Body public var body: some View { HStack(alignment: .top, spacing: ParallelSectionView.outerSpacing) { SplitterView(splitter: section.splitter) ScrollView(.horizontal, showsIndicators: false) { VStack(alignment: .leading, spacing: ParallelSectionView.branchStackSpacing) { branchRow(label: "A", pedals: section.branchA.pedals) Rectangle() .fill(Color.white.opacity(ParallelSectionView.branchSeparatorOpacity)) .frame(height: ParallelSectionView.branchSeparatorHeight) branchRow(label: "B", pedals: section.branchB.pedals) } .padding(.horizontal, ParallelSectionView.scrollPaddingH) .padding(.vertical, ParallelSectionView.scrollPaddingV) } } } // MARK: - Subviews /// A labelled row of pedal cards for one branch. private func branchRow(label: String, pedals: [Pedal]) -> some View { HStack(alignment: .bottom, spacing: ParallelSectionView.pedalSpacing) { Text(label) .font(.system( size: ParallelSectionView.branchLabelFontSize, weight: .semibold, design: .monospaced )) .foregroundStyle(Color.white.opacity(ParallelSectionView.branchLabelOpacity)) .frame(width: 14, alignment: .leading) if pedals.isEmpty { Text("(empty)") .font(.system(size: ParallelSectionView.emptyBranchFontSize)) .foregroundStyle(Color.white.opacity(ParallelSectionView.emptyBranchOpacity)) } else { ForEach(Array(pedals.enumerated()), id: \.offset) { pair in let pedal: Pedal = pair.element PedalView(pedal: pedal) } } } } }