Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Sources/SPGlassEffects/GlassSurfaceStyle.swift8// Module : SPGlassEffects9// 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/// Where the tint of a custom glass surface comes from.44public enum GlassTint: Equatable, Sendable {45 /// The tint chosen by the theme (`GlassMaterialTokens.tint`), possibly none.46 case theme47 /// Never tinted, whatever the theme says.48 case none49 /// A colour role of the theme.50 case token(GlassColorToken)51 /// An explicit colour.52 case color(Color)53}5455/// The parameters of Liquid Glass that the public API lets a caller control: variant, tint and interactivity.56///57/// Blur, refraction and opacity are decided by the system and are deliberately absent.58public struct GlassSurfaceStyle: Equatable, Sendable {59 /// `nil` uses the variant chosen by the theme.60 public var variant: GlassVariant?61 public var tint: GlassTint62 /// Lets the surface react to touch and pointer. Reserve it for surfaces that are themselves controls.63 public var isInteractive: Bool6465 public init(variant: GlassVariant? = nil, tint: GlassTint = .theme, isInteractive: Bool = false) {66 self.variant = variant67 self.tint = tint68 self.isInteractive = isInteractive69 }7071 /// The theme's variant and tint, not interactive.72 public static let regular = GlassSurfaceStyle()73 /// The clear variant, for small controls over media. Needs a dimmed or simple backdrop to stay legible.74 public static let clear = GlassSurfaceStyle(variant: .clear, tint: .none)75 /// The theme's variant and tint, reacting to touch and pointer.76 public static let interactive = GlassSurfaceStyle(isInteractive: true)7778 public func tinted(_ tint: GlassTint) -> GlassSurfaceStyle {79 var copy = self80 copy.tint = tint81 return copy82 }8384 public func interactive(_ isInteractive: Bool = true) -> GlassSurfaceStyle {85 var copy = self86 copy.isInteractive = isInteractive87 return copy88 }8990 /// The tint colour for a resolved theme.91 public func resolvedTint(in theme: ResolvedGlassTheme) -> Color? {92 switch tint {93 case .theme: theme.glassTint94 case .none: nil95 case .token(let token): theme.color(token)96 case .color(let color): color97 }98 }99100 /// The system `Glass` value for a resolved theme.101 public func glass(in theme: ResolvedGlassTheme) -> Glass {102 let base: Glass = (variant ?? theme.glass.variant) == .clear ? .clear : .regular103 return base.tint(resolvedTint(in: theme)).interactive(isInteractive)104 }105}106107/// How a custom surface is drawn once accessibility settings are taken into account.108public enum GlassRendering: Equatable, Sendable {109 /// Real Liquid Glass through `glassEffect`.110 case liquidGlass111 /// An opaque themed surface with a separator outline, used when Reduce Transparency is on.112 case opaque113114 public static func resolve(reduceTransparency: Bool) -> GlassRendering {115 reduceTransparency ? .opaque : .liquidGlass116 }117}118