Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Sources/SPGlassEffects/GlassFocusRing.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 SPGlassThemes4546extension View {47 /// Outlines a custom control with the theme's focus colour while it has keyboard focus or an error.48 public func glassFieldOutline(isFocused: Bool, hasError: Bool = false, in shape: some InsettableShape) -> some View {49 modifier(GlassFieldOutlineModifier(isFocused: isFocused, hasError: hasError, shape: shape))50 }5152 /// Makes the tappable area at least the platform minimum (44 points on iOS, 24 on macOS) without changing layout size on macOS.53 public func glassMinimumHitTarget() -> some View {54 modifier(GlassHitTargetModifier())55 }56}5758private struct GlassFieldOutlineModifier<S: InsettableShape>: ViewModifier {59 @GlassThemed private var theme60 let isFocused: Bool61 let hasError: Bool62 let shape: S6364 func body(content: Content) -> some View {65 content.overlay(66 shape.strokeBorder(color, lineWidth: hasError || isFocused ? 2 : 1)67 )68 }6970 private var color: Color {71 if hasError { return theme.color(.destructive) }72 return isFocused ? theme.color(.focusRing) : theme.color(.separator)73 }74}7576private struct GlassHitTargetModifier: ViewModifier {77 @GlassThemed private var theme7879 func body(content: Content) -> some View {80 let minimum = theme.metrics.minimumHitTarget81 content82 .frame(minWidth: minimum, minHeight: minimum)83 .contentShape(Rectangle())84 }85}86