SPB Git

Repository Public MIT

GlassHaptics.swift 2.4 KB 66 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Sources/SPGlassCore/GlassHaptics.swift8// Module           : SPGlassCore9// Repository       : https://git.spboucher.ai/sp-glasskit10// Project Website  : https://glass.spboucher.ai11// Created          : 2026-12-0212// Last Modified    : 2026-12-0213//14// Author           : Simon-Pierre Boucher15// Position         : Professor of Finance16// Institution      : Université du Québec en Outaouais (UQO)17// Organization     : SP Boucher18// Website          : https://spboucher.ai19// Git              : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development      : dev@spboucher.ai23// Support          : support@spboucher.ai24// Security/Admin   : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License          : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI4243/// Semantic haptic events. Mapped to `SensoryFeedback` on platforms that support it; ignored elsewhere.44public enum GlassHaptic: String, Codable, CaseIterable, Sendable {45    case selection, impact, success, warning, error4647    public var sensoryFeedback: SensoryFeedback {48        switch self {49        case .selection: .selection50        case .impact: .impact51        case .success: .success52        case .warning: .warning53        case .error: .error54        }55    }56}5758extension View {59    /// Plays `haptic` when `trigger` changes, if `isEnabled` is true. The system ignores it where unsupported.60    public func glassHaptic<Trigger: Equatable>(_ haptic: GlassHaptic, isEnabled: Bool = true, trigger: Trigger) -> some View {61        sensoryFeedback(trigger: trigger) { _, _ in62            isEnabled ? haptic.sensoryFeedback : nil63        }64    }65}66
Files main
Menu

Theme