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 SwiftUI42import SPGlassCore43import SPGlassTokens44import SPGlassThemes4546/// Where the tint of a custom glass surface comes from.47public enum GlassTint: Equatable, Sendable {48 /// The tint chosen by the theme (`GlassMaterialTokens.tint`), possibly none.49 case theme50 /// Never tinted, whatever the theme says.51 case none52 /// A colour role of the theme.53 case token(GlassColorToken)54 /// An explicit colour.55 case color(Color)56}5758/// The parameters of Liquid Glass that the public API lets a caller control: variant, tint and interactivity.59///60/// Blur, refraction and opacity are decided by the system and are deliberately absent.61public struct GlassSurfaceStyle: Equatable, Sendable {62 /// `nil` uses the variant chosen by the theme.63 public var variant: GlassVariant?64 public var tint: GlassTint65 /// Lets the surface react to touch and pointer. Reserve it for surfaces that are themselves controls.66 public var isInteractive: Bool6768 public init(variant: GlassVariant? = nil, tint: GlassTint = .theme, isInteractive: Bool = false) {69 self.variant = variant70 self.tint = tint71 self.isInteractive = isInteractive72 }7374 /// The theme's variant and tint, not interactive.75 public static let regular = GlassSurfaceStyle()76 /// The clear variant, for small controls over media. Needs a dimmed or simple backdrop to stay legible.77 public static let clear = GlassSurfaceStyle(variant: .clear, tint: .none)78 /// The theme's variant and tint, reacting to touch and pointer.79 public static let interactive = GlassSurfaceStyle(isInteractive: true)8081 public func tinted(_ tint: GlassTint) -> GlassSurfaceStyle {82 var copy = self83 copy.tint = tint84 return copy85 }8687 public func interactive(_ isInteractive: Bool = true) -> GlassSurfaceStyle {88 var copy = self89 copy.isInteractive = isInteractive90 return copy91 }9293 /// The tint colour for a resolved theme.94 public func resolvedTint(in theme: ResolvedGlassTheme) -> Color? {95 switch tint {96 case .theme: theme.glassTint97 case .none: nil98 case .token(let token): theme.color(token)99 case .color(let color): color100 }101 }102103 /// The system `Glass` value for a resolved theme.104 public func glass(in theme: ResolvedGlassTheme) -> Glass {105 let base: Glass = (variant ?? theme.glass.variant) == .clear ? .clear : .regular106 return base.tint(resolvedTint(in: theme)).interactive(isInteractive)107 }108}109110/// How a custom surface is drawn once accessibility settings are taken into account.111public enum GlassRendering: Equatable, Sendable {112 /// Real Liquid Glass through `glassEffect`.113 case liquidGlass114 /// An opaque themed surface with a separator outline, used when Reduce Transparency is on.115 case opaque116117 public static func resolve(reduceTransparency: Bool) -> GlassRendering {118 reduceTransparency ? .opaque : .liquidGlass119 }120}121