Repository Public
1// SP Lecture Studio2// File: Apps/LectureStudio/Shared/Support/DesignSystem.swift3// Description: Shared visual language: palette, spacing, button styles, small reusable views and formatting helpers.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import SwiftUI8import LectureCore910enum DS {11 static let accent = Color("AccentColor")12 static let recording = Color(red: 0.90, green: 0.16, blue: 0.18)13 static let paused = Color(red: 0.95, green: 0.62, blue: 0.10)14 static let ok = Color(red: 0.13, green: 0.62, blue: 0.33)15 static let stage = Color(red: 0.09, green: 0.09, blue: 0.11)16 static let corner: CGFloat = 1017 static let pad: CGFloat = 121819 #if os(macOS)20 static let panel = Color(nsColor: .windowBackgroundColor)21 static let card = Color(nsColor: .controlBackgroundColor)22 static let separator = Color(nsColor: .separatorColor)23 #else24 static let panel = Color(uiColor: .systemGroupedBackground)25 static let card = Color(uiColor: .secondarySystemGroupedBackground)26 static let separator = Color(uiColor: .separator)27 #endif2829 static func bytes(_ n: Int64) -> String { ByteCountFormatter.string(fromByteCount: n, countStyle: .file) }30 static func date(_ d: Date) -> String { d.formatted(date: .abbreviated, time: .omitted) }31 static func duration(_ t: MediaTime) -> String { MediaTime.clock(t) }32}3334extension Color {35 init(_ c: RGBAColor) { self.init(.sRGB, red: c.r, green: c.g, blue: c.b, opacity: c.a) }36}3738extension Image {39 init(cg: CGImage) { self.init(decorative: cg, scale: 1) }40}4142/// Round icon button used in toolbars and the record bar. Minimum 36 pt target (44 pt on touch devices).43struct IconButtonStyle: ButtonStyle {44 var active = false45 var tint: Color = .primary46 func makeBody(configuration: Configuration) -> some View {47 configuration.label48 .font(.system(size: 16, weight: .medium))49 .frame(minWidth: touchTarget, minHeight: touchTarget)50 .foregroundStyle(active ? Color.white : tint)51 .background(active ? AnyShapeStyle(DS.accent) : AnyShapeStyle(Color.primary.opacity(configuration.isPressed ? 0.16 : 0.07)), in: RoundedRectangle(cornerRadius: 8, style: .continuous))52 .contentShape(Rectangle())53 }54 private var touchTarget: CGFloat {55 #if os(macOS)56 3257 #else58 4459 #endif60 }61}6263struct PillLabel: View {64 var text: LocalizedStringKey65 var color: Color66 var systemImage: String?67 var body: some View {68 HStack(spacing: 5) {69 if let systemImage { Image(systemName: systemImage).font(.caption.weight(.bold)) }70 Text(text).font(.caption.weight(.semibold)).lineLimit(1).fixedSize()71 }72 .padding(.horizontal, 9).padding(.vertical, 4)73 .foregroundStyle(.white)74 .background(color, in: Capsule())75 }76}7778struct Card<Content: View>: View {79 @ViewBuilder var content: Content80 var body: some View {81 content.padding(DS.pad).frame(maxWidth: .infinity, alignment: .leading)82 .background(DS.card, in: RoundedRectangle(cornerRadius: DS.corner, style: .continuous))83 }84}8586struct SectionTitle: View {87 var text: LocalizedStringKey88 init(_ text: LocalizedStringKey) { self.text = text }89 var body: some View { Text(text).font(.caption.weight(.semibold)).foregroundStyle(.secondary).textCase(.uppercase) }90}9192/// Input level meter (dBFS mapped to 0…1 between -60 and 0 dB, with a peak tick).93struct LevelMeter: View {94 var levelDB: Double95 var peak: Float96 var body: some View {97 GeometryReader { geo in98 let f = CGFloat(min(1, max(0, (levelDB + 60) / 60)))99 let p = CGFloat(min(1, max(0, (Double(peak > 0 ? 20 * log10(peak) : -120) + 60) / 60)))100 ZStack(alignment: .leading) {101 Capsule().fill(Color.primary.opacity(0.12))102 Capsule().fill(LinearGradient(colors: [DS.ok, DS.ok, DS.paused, DS.recording], startPoint: .leading, endPoint: .trailing))103 .frame(width: max(2, geo.size.width * f))104 .animation(.linear(duration: 0.08), value: f)105 Rectangle().fill(Color.primary.opacity(0.7)).frame(width: 2).offset(x: max(0, geo.size.width * p - 2))106 }107 }108 .frame(height: 6)109 .accessibilityElement()110 .accessibilityLabel(Text("Niveau du microphone"))111 .accessibilityValue(Text(verbatim: "\(Int(levelDB)) dB"))112 }113}114115/// Fixed-height information banner (fixed height matters: unbounded heights above the stage break layouts on macOS 27).116struct BannerView<Actions: View>: View {117 var systemImage: String118 var tint: Color119 var title: Text120 var detail: Text?121 @ViewBuilder var actions: Actions122 var body: some View {123 HStack(spacing: 10) {124 Image(systemName: systemImage).font(.title3).foregroundStyle(tint)125 VStack(alignment: .leading, spacing: 1) {126 title.font(.subheadline.weight(.semibold)).lineLimit(1)127 if let detail { detail.font(.caption).foregroundStyle(.secondary).lineLimit(2) }128 }129 Spacer(minLength: 8)130 actions131 }132 .padding(.horizontal, 12).frame(minHeight: 52)133 .background(.regularMaterial, in: RoundedRectangle(cornerRadius: DS.corner, style: .continuous))134 .overlay(RoundedRectangle(cornerRadius: DS.corner, style: .continuous).strokeBorder(tint.opacity(0.5)))135 .padding(.horizontal, 10)136 }137}138