// ============================================================================= // SP BOUCHER | SOFTWARE & RESEARCH // ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING // ============================================================================= // // Project : SP GlassKit // File : Sources/SPGlassForms/Selection/GlassPicker.swift // Module : SPGlassForms // Repository : https://git.spboucher.ai/sp-glasskit // Project Website : https://glass.spboucher.ai // Created : 2026-12-02 // Last Modified : 2026-12-03 // // Author : Simon-Pierre Boucher // Position : Professor of Finance // Institution : Université du Québec en Outaouais (UQO) // Organization : SP Boucher // Website : https://spboucher.ai // Git : https://git.spboucher.ai // // Preferred Contact: contact@spboucher.ai // Development : dev@spboucher.ai // Support : support@spboucher.ai // Security/Admin : admin@spboucher.ai // // Copyright (c) 2026 // Simon-Pierre Boucher // All rights reserved where applicable. This file is governed by the // applicable project license, copyright notices and relevant law. // Existing third-party rights and notices remain unaffected. // // License : MIT // // Do not embed credentials, private keys, access tokens, // certificates or confidential personal information. // // ============================================================================= // END OF SP BOUCHER SOURCE HEADER // ============================================================================= import SwiftUI /// Presentation of a ``GlassPicker``. public enum GlassPickerPresentation: String, CaseIterable, Sendable { /// A pop-up menu. The default on every platform. case menu /// A wheel. iOS and iPadOS only; macOS uses a menu. case wheel /// Every option visible: radio buttons on macOS, an inline list on iOS and iPadOS. case inline /// The presentation actually used on a platform. public func resolved(for platform: GlassPlatform = .current) -> Resolved { switch (self, platform) { case (.menu, _): .menu case (.wheel, .macOS): .menu case (.wheel, _): .wheel case (.inline, .macOS): .radioGroup case (.inline, _): .inline } } /// A system picker style. public enum Resolved: String, CaseIterable, Sendable { case menu, wheel, inline, radioGroup } } /// The system `Picker` over any `Hashable` options. /// /// ```swift /// GlassPicker("Currency", selection: $currency, options: Currency.allCases, title: \.name) /// GlassPicker("Priority", selection: $priority, options: Priority.allCases, presentation: .inline) { priority in /// Label(priority.title, systemImage: priority.symbol) /// } /// ``` /// /// The system draws the control. The presentation adapts to the platform: a wheel exists only on iOS and /// iPadOS, radio buttons only on macOS. public struct GlassPicker: View { @GlassThemed private var theme private let title: Text @Binding private var selection: Option private let options: [Option] private let presentation: GlassPickerPresentation private let optionLabel: (Option) -> OptionLabel /// Creates a picker with a custom label for each option. public init( _ title: LocalizedStringKey, selection: Binding