Repository Public License
1//2// ORIX Audio3// File: ORIXAudio/DesignSystem/Components/ORIXComponents.swift4// Description: Reusable ORIX components: cards, metric tiles, chips, plot frames, level meters, buttons and the share sheet.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8//9import ORIXAudioCore10import SwiftUI11import UIKit1213struct ORIXCard<Content: View>: View {14 var padding: CGFloat = ORIX.Space.l15 @ViewBuilder var content: Content16 var body: some View {17 content18 .padding(padding)19 .frame(maxWidth: .infinity, alignment: .leading)20 .background(ORIX.Palette.surface, in: RoundedRectangle(cornerRadius: ORIX.Radius.card, style: .continuous))21 .overlay(RoundedRectangle(cornerRadius: ORIX.Radius.card, style: .continuous).strokeBorder(ORIX.Palette.hairline, lineWidth: 1))22 }23}2425/// Dark, rounded surface for every plot (waveform, spectrum, spectrogram).26struct PlotFrame<Content: View>: View {27 @ViewBuilder var content: Content28 var body: some View {29 content30 .background(ORIX.Palette.plot)31 .clipShape(RoundedRectangle(cornerRadius: ORIX.Radius.plot, style: .continuous))32 .overlay(RoundedRectangle(cornerRadius: ORIX.Radius.plot, style: .continuous).strokeBorder(Color.white.opacity(0.07), lineWidth: 1))33 }34}3536struct SectionTitle: View {37 let text: LocalizedStringKey38 var symbol: String?39 init(_ text: LocalizedStringKey, symbol: String? = nil) { self.text = text; self.symbol = symbol }40 var body: some View {41 HStack(spacing: 6) {42 if let symbol { Image(systemName: symbol).foregroundStyle(ORIX.Palette.cyan).accessibilityHidden(true) }43 Text(text).font(.subheadline.weight(.semibold)).textCase(.uppercase).tracking(0.8).foregroundStyle(ORIX.Palette.textSecondary)44 Spacer(minLength: 0)45 }46 .accessibilityAddTraits(.isHeader)47 }48}4950struct MetricTile: View {51 let label: LocalizedStringKey52 let value: String53 var unit: String = ""54 var tint: Color = ORIX.Palette.text55 var body: some View {56 VStack(alignment: .leading, spacing: 4) {57 Text(label).font(.caption).foregroundStyle(ORIX.Palette.textSecondary).fixedSize(horizontal: false, vertical: true)58 HStack(alignment: .firstTextBaseline, spacing: 3) {59 Text(value).font(.orixNumeral(.title3, weight: .medium)).foregroundStyle(tint).fixedSize(horizontal: false, vertical: true)60 if !unit.isEmpty { Text(unit).font(.caption2.weight(.medium)).foregroundStyle(ORIX.Palette.textSecondary) }61 }62 }63 .frame(maxWidth: .infinity, alignment: .leading)64 .padding(ORIX.Space.m)65 .background(ORIX.Palette.raised, in: RoundedRectangle(cornerRadius: ORIX.Radius.control, style: .continuous))66 .accessibilityElement(children: .combine)67 }68}6970struct Chip: View {71 let text: String72 var symbol: String?73 var tint: Color = ORIX.Palette.text74 var body: some View {75 HStack(spacing: 4) {76 if let symbol { Image(systemName: symbol).imageScale(.small) }77 Text(text).lineLimit(2).fixedSize(horizontal: false, vertical: true)78 }79 .font(.caption.weight(.semibold))80 .foregroundStyle(tint)81 .padding(.horizontal, 8).padding(.vertical, 4)82 .background(tint.opacity(0.14), in: Capsule())83 }84}8586/// Horizontal level meter with RMS bar, peak tick, peak-hold tick and a clip lamp. Scale: −60…0 dBFS.87struct LevelMeter: View {88 let levels: LiveLevels89 static let floorDB: Float = -609091 private func position(_ dB: Float) -> CGFloat { CGFloat(max(0, min(1, (dB - Self.floorDB) / -Self.floorDB))) }9293 var body: some View {94 HStack(spacing: 8) {95 GeometryReader { geo in96 let w = geo.size.width97 ZStack(alignment: .leading) {98 Capsule().fill(Color.white.opacity(0.08))99 Capsule().fill(LinearGradient(stops: [.init(color: ORIX.Palette.good, location: 0), .init(color: ORIX.Palette.good, location: 0.7),100 .init(color: ORIX.Palette.warning, location: 0.9), .init(color: ORIX.Palette.record, location: 1)],101 startPoint: .leading, endPoint: .trailing))102 .mask(alignment: .leading) { Rectangle().frame(width: w * position(levels.rmsDB)) }103 Rectangle().fill(Color.white.opacity(0.85)).frame(width: 2).offset(x: max(0, w * position(levels.peakDB) - 1))104 Rectangle().fill(ORIX.Palette.warning).frame(width: 2).offset(x: max(0, w * position(levels.peakHoldDB) - 1))105 // −12 and −6 dBFS reference ticks106 ForEach([Float(-12), -6], id: \.self) { tick in Rectangle().fill(Color.white.opacity(0.25)).frame(width: 1).offset(x: w * position(tick)) }107 }108 }109 .frame(height: 10)110 Text(levels.isClipping ? "CLIP" : Formatters.dB(Double(levels.peakHoldDB), unit: "dBFS"))111 .font(.orixReadout).foregroundStyle(levels.isClipping ? ORIX.Palette.record : Color.white.opacity(0.85))112 .lineLimit(1).minimumScaleFactor(0.6).frame(minWidth: 92, alignment: .trailing)113 }114 .frame(minHeight: 44)115 .contentShape(Rectangle())116 .accessibilityElement(children: .ignore)117 .accessibilityLabel(Text("Input level"))118 .accessibilityValue(levels.isClipping ? Text("Clipping") : Text("\(Int(levels.peakHoldDB)) decibels full scale peak"))119 }120}121122struct RecordButton: View {123 let isRecording: Bool124 let action: () -> Void125 @Environment(\.accessibilityReduceMotion) private var reduceMotion126 var body: some View {127 Button(action: action) {128 ZStack {129 Circle().strokeBorder(ORIX.brandGradient, lineWidth: 4).frame(width: 84, height: 84)130 RoundedRectangle(cornerRadius: isRecording ? 8 : 34, style: .continuous)131 .fill(ORIX.Palette.record)132 .frame(width: isRecording ? 32 : 68, height: isRecording ? 32 : 68)133 .animation(reduceMotion ? nil : .spring(duration: 0.3), value: isRecording)134 }135 .contentShape(Circle())136 }137 .buttonStyle(.plain)138 .accessibilityLabel(isRecording ? Text("Stop and save") : Text("Start recording"))139 .accessibilityIdentifier("recordButton")140 }141}142143struct CircleIconButton: View {144 let symbol: String145 let label: LocalizedStringKey146 var size: CGFloat = 52147 var tint: Color = ORIX.Palette.text148 let action: () -> Void149 var body: some View {150 Button(action: action) {151 Image(systemName: symbol).font(.system(size: size * 0.38, weight: .semibold)).foregroundStyle(tint)152 .frame(width: size, height: size)153 .background(ORIX.Palette.raised, in: Circle())154 .overlay(Circle().strokeBorder(ORIX.Palette.hairline, lineWidth: 1))155 }156 .buttonStyle(.plain)157 .accessibilityLabel(Text(label))158 }159}160161struct ProgressRow: View {162 let title: LocalizedStringKey163 let progress: Double164 var onCancel: (() -> Void)?165 var body: some View {166 HStack(spacing: 12) {167 VStack(alignment: .leading, spacing: 6) {168 Text(title).font(.subheadline.weight(.medium))169 ProgressView(value: min(1, max(0, progress))).tint(ORIX.Palette.cyan)170 }171 if let onCancel {172 Button(role: .cancel, action: onCancel) { Image(systemName: "xmark.circle.fill").font(.title2).foregroundStyle(ORIX.Palette.textSecondary) }173 .buttonStyle(.plain).accessibilityLabel(Text("Cancel"))174 }175 }176 }177}178179struct EmptyStateView: View {180 let symbol: String181 let title: LocalizedStringKey182 let message: LocalizedStringKey183 var body: some View {184 VStack(spacing: 10) {185 Image(systemName: symbol).font(.system(size: 40, weight: .light)).foregroundStyle(ORIX.brandGradient).accessibilityHidden(true)186 Text(title).font(.headline)187 Text(message).font(.subheadline).foregroundStyle(ORIX.Palette.textSecondary).multilineTextAlignment(.center)188 }189 .padding(ORIX.Space.xl)190 .frame(maxWidth: .infinity)191 }192}193194/// System share sheet for exported files.195struct ShareSheet: UIViewControllerRepresentable {196 let items: [URL]197 func makeUIViewController(context: Context) -> UIActivityViewController { UIActivityViewController(activityItems: items, applicationActivities: nil) }198 func updateUIViewController(_ controller: UIActivityViewController, context: Context) {}199}200201struct SharePayload: Identifiable {202 let id = UUID()203 let urls: [URL]204}205206extension View {207 /// Presents the share sheet for exported files.208 func shareSheet(_ payload: Binding<SharePayload?>) -> some View {209 sheet(item: payload) { ShareSheet(items: $0.urls).presentationDetents([.medium, .large]) }210 }211212 func orixScreenBackground() -> some View { background(ORIX.Palette.ink.ignoresSafeArea()) }213}214