SPB Git

Repository Public MIT

GlassSegmentedControlExample.swift 3.3 KB 84 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Examples/Gallery/Selection/GlassSegmentedControlExample.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 GlassSegmentedControlExample: GlassExample {45    public static let componentID = "glass-segmented-control"4647    enum Mode: String, CaseIterable, Hashable {48        case list, grid, map4950        var title: String { rawValue.capitalized }51    }5253    @State private var mode = Mode.list54    @State private var period = "Week"55    @State private var long = "Everything that happened"56    @State private var weekday = "Mon"5758    public init() {}5960    public var body: some View {61        ScrollView {62            VStack(alignment: .leading, spacing: 24) {63                GlassSegmentedControl("View", selection: $mode, options: Mode.allCases, title: \.title)64                Text("Showing: \(mode.title)").font(.callout).foregroundStyle(.secondary)6566                GlassSegmentedControl("Period", selection: $period, options: ["Day", "Week", "Month", "Year"]) { $0 }6768                Text("Titles too long for the width fall back to a menu").font(.headline)69                GlassSegmentedControl("Scope", selection: $long, options: ["Everything that happened", "Only what I was mentioned in", "Nothing at all, thank you"]) { $0 }7071                Text("More than five options: a menu").font(.headline)72                GlassSegmentedControl("Day", selection: $weekday, options: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]) { $0 }7374                GlassSegmentedControl("Locked", selection: .constant("On"), options: ["Off", "On"]) { $0 }75                    .disabled(true)76            }77            .frame(maxWidth: .infinity, alignment: .leading)78            .padding()79        }80    }81}8283#Preview("GlassSegmentedControl") { GlassSegmentedControlExample() }84
Files main
Menu

Theme