diff --git a/Sources/LyrebirdShoeGazeUI/PedalCategory.swift b/Sources/LyrebirdShoeGazeUI/PedalCategory.swift index 8656076..4d970ca 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalCategory.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalCategory.swift @@ -9,7 +9,7 @@ import SwiftUI /// A presentation grouping for pedals in the palette — used to colour-code the picker cards and to /// drive the "filter by type" menu. Purely a UI concern: the mapping from a pedal's `displayName` /// to its category lives here, keyed by name like ``PedalPaletteView``'s preferred order. -enum PedalCategory: String, CaseIterable, Identifiable { +public enum PedalCategory: String, CaseIterable, Identifiable, Sendable { case gain = "Gain" case dynamics = "Dynamics" case filter = "EQ & Filter" @@ -19,7 +19,7 @@ enum PedalCategory: String, CaseIterable, Identifiable { case reverb = "Reverb" case texture = "Texture" - var id: String { rawValue } + public var id: String { rawValue } /// Accent colour used to tint the palette card and the filter chip. var color: Color { diff --git a/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift b/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift index aa5d875..5aecd7c 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift @@ -83,9 +83,25 @@ public struct PedalPaletteView: View { private let onAdd: (String) -> Void private let onRouting: (RoutingAction) -> Void private let axis: Axis + private let showsFilterMenu: Bool - /// Active type filter; `nil` shows all pedals. - @State private var filter: PedalCategory? + /// Active type filter when the palette owns it; `nil` shows all pedals. Ignored when an + /// `externalFilter` binding is supplied (the host hoists the filter into its own header). + @State private var internalFilter: PedalCategory? + private let externalFilter: Binding? + + /// The live filter, from the host binding if provided, else the palette's own state. + private var activeFilter: PedalCategory? { + externalFilter?.wrappedValue ?? internalFilter + } + + private func setFilter(_ category: PedalCategory?) { + if let externalFilter: Binding = externalFilter { + externalFilter.wrappedValue = category + } else { + internalFilter = category + } + } // MARK: - Init @@ -95,15 +111,23 @@ public struct PedalPaletteView: View { /// - axis: `.vertical` (default) lays the catalog out as a full-width column for a sidebar; /// `.horizontal` lays it out as a fixed-width-card row for a horizontal scroller. The host /// wraps the view in a `ScrollView` of the matching axis. + /// - filter: Optional external binding for the type filter, so a host (e.g. a sheet) can put + /// the filter control in its own fixed header. When `nil` the palette manages its own filter. + /// - showsFilterMenu: Whether to draw the built-in filter menu inline. Pass `false` when the + /// host renders its own filter control. Defaults to `true`. /// - onAdd: Invoked with a pedal's `displayName` when its row is tapped (append to main chain). /// Rows are also `.draggable` carrying `"add:"` for drop-onto-lane targeting. /// - onRouting: Invoked when a routing row is tapped. Defaults to a no-op. public init( axis: Axis = .vertical, + filter: Binding? = nil, + showsFilterMenu: Bool = true, onAdd: @escaping (String) -> Void, onRouting: @escaping (RoutingAction) -> Void = { _ in } ) { self.axis = axis + self.externalFilter = filter + self.showsFilterMenu = showsFilterMenu self.onAdd = onAdd self.onRouting = onRouting } @@ -120,7 +144,7 @@ public struct PedalPaletteView: View { /// Pedal names after applying the active type filter. private var visiblePedalNames: [String] { - guard let filter: PedalCategory = filter else { return orderedPedalNames } + guard let filter: PedalCategory = activeFilter else { return orderedPedalNames } return orderedPedalNames.filter { PedalCategory.category(for: $0) == filter } } @@ -151,7 +175,7 @@ public struct PedalPaletteView: View { HStack { sectionTitle("PEDALS") Spacer(minLength: 0) - filterMenu + if showsFilterMenu { filterMenu } } ForEach(visiblePedalNames, id: \.self) { name in pedalRow(name) @@ -215,18 +239,18 @@ public struct PedalPaletteView: View { /// "Filter by type" menu — defaults to **All** (no filtering). private var filterMenu: some View { Menu { - Button("All Types") { filter = nil } + Button("All Types") { setFilter(nil) } Divider() ForEach(PedalCategory.allCases) { category in - Button(category.rawValue) { filter = category } + Button(category.rawValue) { setFilter(category) } } } label: { HStack(spacing: 3) { Image(systemName: "line.3.horizontal.decrease.circle") - Text(filter?.rawValue ?? "All").lineLimit(1) + Text(activeFilter?.rawValue ?? "All").lineLimit(1) } .font(.system(size: PedalPaletteView.titleFontSize)) - .foregroundStyle((filter?.color ?? Color.white).opacity(0.9)) + .foregroundStyle((activeFilter?.color ?? Color.white).opacity(0.9)) } #if os(macOS) .menuStyle(.borderlessButton) diff --git a/Sources/LyrebirdShoeGazeUI/ShoeGazeBuilderView.swift b/Sources/LyrebirdShoeGazeUI/ShoeGazeBuilderView.swift index 767f091..5a365c2 100644 --- a/Sources/LyrebirdShoeGazeUI/ShoeGazeBuilderView.swift +++ b/Sources/LyrebirdShoeGazeUI/ShoeGazeBuilderView.swift @@ -52,6 +52,8 @@ public struct ShoeGazeBuilderView: View { /// Narrow scope shown in the compact (iPad) header, tucked left of the transport buttons. private static let compactHeaderScopeWidth: CGFloat = 340 private static let compactHeaderScopeHeight: CGFloat = 76 + /// Stable height (fraction of the screen) for the Add-Pedal sheet — a single, non-resizable detent. + private static let paletteSheetHeightFraction: CGFloat = 0.82 private static let columnSpacing: CGFloat = 14 private static let backgroundRed: Double = 0.08 private static let backgroundGreen: Double = 0.07 @@ -171,6 +173,9 @@ public struct ShoeGazeBuilderView: View { @State private var showPaletteSheet: Bool = false @State private var showSettingsSheet: Bool = false + /// Type filter for the compact Add-Pedal sheet, hoisted so it sits in the sheet's fixed header. + @State private var pedalFilter: PedalCategory? + #if !os(macOS) /// iOS recording-folder picker presentation flag. (macOS uses the Record menu.) @State private var showRecordingFolderImporter: Bool = false @@ -371,7 +376,6 @@ public struct ShoeGazeBuilderView: View { Color.clear .sheet(isPresented: $showPaletteSheet) { paletteSheet - .presentationDetents([.medium, .large]) } } @@ -609,29 +613,57 @@ public struct ShoeGazeBuilderView: View { /// The Add-a-pedal palette + routing options, presented as a compact sheet. private var paletteSheet: some View { - NavigationStack { - PedalPaletteView( - axis: .vertical, - onAdd: { type in addPedal(type: type); showPaletteSheet = false }, - onRouting: { action in performRouting(action); showPaletteSheet = false } - ) + // A fixed header (title, type filter, Done) over a scrolling list. Not a NavigationStack — + // its transparent bar let the list scroll under the title. The palette does not self-wrap in + // a ScrollView (the host must), so it is wrapped here. + VStack(spacing: 0) { + HStack(spacing: ShoeGazeBuilderView.rowSpacing) { + Text("Add Pedal") + .font(.headline) + .foregroundStyle(Color.white) + Spacer() + pedalFilterMenu + Button("Done") { showPaletteSheet = false } + .fontWeight(.semibold) + } .padding() - .navigationTitle("Add Pedal") - #if os(iOS) - .navigationBarTitleDisplayMode(.inline) - .toolbarBackground(.visible, for: .navigationBar) - #endif - .toolbar { - ToolbarItem(placement: .confirmationAction) { - Button("Done") { showPaletteSheet = false } - } + + Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity)) + + ScrollView { + PedalPaletteView( + axis: .vertical, + filter: $pedalFilter, + showsFilterMenu: false, + onAdd: { type in addPedal(type: type); showPaletteSheet = false }, + onRouting: { action in performRouting(action); showPaletteSheet = false } + ) + .padding() } } + .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top) .preferredColorScheme(.dark) - // Drag inside the list scrolls it instead of resizing the sheet detent. + // One fixed detent (no resize-drag) and drags scroll the list instead of the sheet. + .presentationDetents([.fraction(ShoeGazeBuilderView.paletteSheetHeightFraction)]) .presentationContentInteraction(.scrolls) } + /// The type-filter menu shown in the Add-Pedal sheet header, bound to `pedalFilter`. + private var pedalFilterMenu: some View { + Menu { + Button("All Types") { pedalFilter = nil } + Divider() + ForEach(PedalCategory.allCases) { category in + Button(category.rawValue) { pedalFilter = category } + } + } label: { + HStack(spacing: 3) { + Image(systemName: "line.3.horizontal.decrease.circle") + Text(pedalFilter?.rawValue ?? "All").lineLimit(1) + } + } + } + /// Engine configuration (sample rate, input/output channel counts, input source), presented as /// a compact sheet — the set-and-forget composition controls. private var settingsSheet: some View {