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 SwiftUI4243extension View {44 /// Outlines a custom control with the theme's focus colour while it has keyboard focus or an error.45 public func glassFieldOutline(isFocused: Bool, hasError: Bool = false, in shape: some InsettableShape) -> some View {46 modifier(GlassFieldOutlineModifier(isFocused: isFocused, hasError: hasError, shape: shape))47 }4849 /// Makes the tappable area at least the platform minimum (44 points on iOS, 24 on macOS) without changing layout size on macOS.50 public func glassMinimumHitTarget() -> some View {51 modifier(GlassHitTargetModifier())52 }53}5455private struct GlassFieldOutlineModifier<S: InsettableShape>: ViewModifier {56 @GlassThemed private var theme57 let isFocused: Bool58 let hasError: Bool59 let shape: S6061 func body(content: Content) -> some View {62 content.overlay(63 shape.strokeBorder(color, lineWidth: hasError || isFocused ? 2 : 1)64 )65 }6667 private var color: Color {68 if hasError { return theme.color(.destructive) }69 return isFocused ? theme.color(.focusRing) : theme.color(.separator)70 }71}7273private struct GlassHitTargetModifier: ViewModifier {74 @GlassThemed private var theme7576 func body(content: Content) -> some View {77 let minimum = theme.metrics.minimumHitTarget78 content79 .frame(minWidth: minimum, minHeight: minimum)80 .contentShape(Rectangle())81 }82}83