SPB Git

Repository Public MIT

GlassCompassExample.swift 2.9 KB 78 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Examples/Gallery/Maps/GlassCompassExample.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 GlassCompassExample: GlassExample {45    public static let componentID = "glass-compass"46    @State private var heading = 315.047    @State private var resetCount = 04849    public init() {}5051    public var body: some View {52        VStack(spacing: 16) {53            SampleMapBackdrop(heading: heading)54                .overlay(alignment: .topTrailing) {55                    VStack(spacing: 12) {56                        GlassCompass(heading: heading, size: .large) {57                            heading = 058                            resetCount += 159                        }60                        GlassCompass(heading: heading) { heading = 0 }61                        GlassCompass(heading: heading, size: .small) { heading = 0 }62                        GlassCompass(heading: nil) {}63                    }64                    .padding()65                }66            Slider(value: $heading, in: 0...359, step: 1) { Text("Heading") }67                .padding(.horizontal)68            Text("Heading \(Int(heading))° · reset to north \(resetCount) times · the last compass has no heading")69                .font(.caption)70                .foregroundStyle(.secondary)71                .padding(.horizontal)72        }73        .padding(.bottom)74    }75}7677#Preview("GlassCompass") { GlassCompassExample().glassTheme(.crystal) }78
Files main
Menu

Theme