// PedalInfoView.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import SwiftUI import LyrebirdUI import LyrebirdShoeGaze /// An info panel for a single pedal: its description and the effect controls with their ranges. /// /// Shows `pedal.summary` and lists the **effect** controls only — `effectKnobs` + `effectSliders` /// + `effectSwitches`, each with its value range or switch positions. The common Mix / Level / /// bypass controls are intentionally omitted (they behave the same on every pedal). Presented /// from the pedal's ⓘ button. public struct PedalInfoView: View { // MARK: - Layout constants private static let sectionSpacing: CGFloat = 16 private static let rowSpacing: CGFloat = 8 private static let labelColumnWidth: CGFloat = 110 private static let summaryOpacity: Double = 0.85 private static let valueOpacity: Double = 0.7 private static let headerOpacity: Double = 0.5 // MARK: - Properties private let pedal: Pedal @Environment(\.dismiss) private var dismiss // MARK: - Init /// Creates an info panel for `pedal`. public init(pedal: Pedal) { self.pedal = pedal } // MARK: - Body public var body: some View { NavigationStack { ScrollView { VStack(alignment: .leading, spacing: PedalInfoView.sectionSpacing) { if !pedal.summary.isEmpty { Text(pedal.summary) .font(.body) .foregroundStyle(.primary.opacity(PedalInfoView.summaryOpacity)) .fixedSize(horizontal: false, vertical: true) } if !controlRows.isEmpty { VStack(alignment: .leading, spacing: PedalInfoView.rowSpacing) { Text("CONTROLS") .font(.caption2.weight(.semibold)) .foregroundStyle(.secondary.opacity(PedalInfoView.headerOpacity)) ForEach(Array(controlRows.enumerated()), id: \.offset) { pair in controlRow(pair.element) } } } } .padding() .frame(maxWidth: .infinity, alignment: .leading) } .navigationTitle(pedal.displayName) #if !os(macOS) .navigationBarTitleDisplayMode(.inline) #endif .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() } } } } } // MARK: - Control rows private func controlRow(_ row: ControlRow) -> some View { HStack(alignment: .firstTextBaseline) { Text(row.label) .font(.callout.weight(.medium)) .frame(width: PedalInfoView.labelColumnWidth, alignment: .leading) Text(row.value) .font(.callout.monospacedDigit()) .foregroundStyle(.secondary.opacity(PedalInfoView.valueOpacity)) Spacer(minLength: 0) } } /// One displayed control: a label and its range / options string. private struct ControlRow { let label: String let value: String } /// Effect controls only (knobs + sliders + switches), in display order. private var controlRows: [ControlRow] { var rows: [ControlRow] = [] for knob: PedalKnob in pedal.effectKnobs { rows.append(ControlRow(label: knob.label, value: PedalInfoView.rangeText(knob.range))) } for slider: PedalSlider in pedal.effectSliders { rows.append(ControlRow(label: slider.label, value: PedalInfoView.rangeText(slider.range))) } for pedalSwitch: PedalSwitch in pedal.effectSwitches { let options: String = pedalSwitch.options.map { $0.title }.joined(separator: " / ") rows.append(ControlRow(label: pedalSwitch.label, value: options)) } return rows } // MARK: - Formatting /// Formats a value range as `"lo – hi"`, using integers when both bounds are whole. private static func rangeText(_ range: ClosedRange) -> String { "\(number(range.lowerBound)) – \(number(range.upperBound))" } private static func number(_ value: Double) -> String { if value == value.rounded() { return String(format: "%.0f", value) } return String(format: "%.3g", value) } }