SPB Git

Repository Public MIT

GlassLocationButtonExample.swift 3.9 KB 107 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Examples/Gallery/Maps/GlassLocationButtonExample.swift8// Module           : Examples9// 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 SPGlassKit4344public struct GlassLocationButtonExample: GlassExample {45    public static let componentID = "glass-location-button"46    /// The example plays the host's role with a simulated state: no permission is requested, no position is read.47    @State private var state = GlassLocationState.idle48    @State private var message = "Sample data · simulated states, no location access"4950    public init() {}5152    public var body: some View {53        VStack(spacing: 16) {54            SampleMapBackdrop()55                .overlay(alignment: .bottomTrailing) {56                    GlassLocationButton(state: state, hint: hint) { advance() }57                        .padding()58                }59            Picker("Simulated state", selection: $state) {60                ForEach(GlassLocationState.allCases, id: \.self) { state in61                    Text(GlassLocationPresentation(state).label).tag(state)62                }63            }64            .padding(.horizontal)65            HStack(spacing: 12) {66                ForEach(GlassLocationState.allCases, id: \.self) { state in67                    GlassLocationButton(state: state, size: .small) {}68                }69            }70            Text(message)71                .font(.caption)72                .foregroundStyle(.secondary)73                .padding(.horizontal)74        }75        .padding(.bottom)76    }7778    private var hint: String? {79        switch state {80        case .denied: "Location access was refused. Activating the button would open Settings in a real application."81        case .unavailable: "Location services are off on this device."82        default: nil83        }84    }8586    /// What a host might do on a tap, simulated.87    private func advance() {88        switch state {89        case .idle:90            state = .locating91            message = "The host would start location updates here."92        case .locating:93            state = .following94            message = "A position arrived: the map follows it."95        case .following:96            state = .idle97            message = "Following stopped."98        case .denied:99            message = "The host would open Settings here."100        case .unavailable:101            break102        }103    }104}105106#Preview("GlassLocationButton") { GlassLocationButtonExample().glassTheme(.emerald) }107
Files main
Menu

Theme