Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Apps/GlassStudio/Kit/Views/HomeAndListsViews.swift8// Module : GlassStudio9// 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 SPGlassKit4344/// Entry screen: what the Studio is, the categories, a few components and the themes.45struct HomeView: View {46 @Bindable var model: StudioModel4748 private let columns = [GridItem(.adaptive(minimum: 150), spacing: 12)]4950 var body: some View {51 ScrollView {52 VStack(alignment: .leading, spacing: 28) {53 VStack(alignment: .leading, spacing: 6) {54 Text(verbatim: "SP Glass Studio").font(.largeTitle.weight(.semibold))55 Text(L("Fifty native SwiftUI components for Liquid Glass. Preview them, adjust them, build themes and export code that compiles."))56 .foregroundStyle(.secondary)57 Text(L("Everything here works offline. The Studio collects no data."))58 .font(.footnote).foregroundStyle(.secondary)59 }6061 section(L("Categories")) {62 LazyVGrid(columns: columns, alignment: .leading, spacing: 12) {63 ForEach(GlassComponentCategory.allCases, id: \.self) { category in64 Button {65 model.filter = CatalogFilter()66 model.filter.category = category67 model.selectedComponentID = nil68 model.section = .catalog69 } label: {70 VStack(alignment: .leading, spacing: 8) {71 Image(systemName: category.symbol).font(.title3).accessibilityHidden(true)72 Text(category.title).font(.body.weight(.medium))73 Text(L("%lld components").replacingOccurrences(of: "%lld", with: "\(model.catalog.descriptors(in: category).count)"))74 .font(.caption).foregroundStyle(.secondary)75 }76 .frame(maxWidth: .infinity, alignment: .leading)77 .padding(14)78 .background(.quaternary.opacity(0.5), in: RoundedRectangle(cornerRadius: 14, style: .continuous))79 }80 .buttonStyle(.plain)81 .accessibilityIdentifier("category-\(category.rawValue)")82 }83 }84 }8586 section(L("Start with")) {87 VStack(spacing: 0) {88 ForEach(["glass-button", "glass-tab-bar", "glass-toast", "glass-chart", "glass-prompt-bar"].compactMap(model.catalog.descriptor)) { descriptor in89 Button { model.open(descriptor.id) } label: {90 ComponentRow(descriptor: descriptor, isFavorite: model.favorites.contains(descriptor.id))91 .padding(.vertical, 10)92 .contentShape(Rectangle())93 }94 .buttonStyle(.plain)95 Divider()96 }97 }98 }99100 section(L("Themes")) {101 ScrollView(.horizontal) {102 HStack(spacing: 12) {103 ForEach(GlassTheme.builtIn) { theme in104 Button {105 model.preview.themeID = theme.id106 model.section = .themes107 } label: {108 ThemeSwatch(theme: theme, isSelected: model.preview.themeID == theme.id)109 }110 .buttonStyle(.plain)111 }112 }113 .padding(.vertical, 2)114 }115 }116 }117 .padding()118 .frame(maxWidth: 900, alignment: .leading)119 .frame(maxWidth: .infinity)120 }121 .navigationTitle(Text(L("Home")))122 .accessibilityIdentifier("home")123 }124125 private func section(_ title: String, @ViewBuilder content: () -> some View) -> some View {126 VStack(alignment: .leading, spacing: 12) {127 Text(title).font(.title3.weight(.semibold)).accessibilityAddTraits(.isHeader)128 content()129 }130 }131}132133/// A compact card showing a theme's colours in the current appearance.134struct ThemeSwatch: View {135 let theme: GlassTheme136 let isSelected: Bool137 @Environment(\.colorScheme) private var colorScheme138139 var body: some View {140 let resolved = GlassThemeResolver.resolve(theme, colorScheme: colorScheme)141 VStack(alignment: .leading, spacing: 8) {142 HStack(spacing: 0) {143 ForEach([GlassColorToken.primary, .secondary, .accent, .surface, .textPrimary], id: \.self) { token in144 resolved.color(token)145 }146 }147 .frame(width: 132, height: 44)148 .clipShape(RoundedRectangle(cornerRadius: 8, style: .continuous))149 .overlay(RoundedRectangle(cornerRadius: 8, style: .continuous).strokeBorder(.separator))150 .accessibilityHidden(true)151 HStack(spacing: 4) {152 Text(verbatim: theme.name).font(.callout.weight(.medium)).lineLimit(1)153 if isSelected { Image(systemName: "checkmark.circle.fill").font(.caption).accessibilityLabel(Text(L("Selected"))) }154 }155 }156 .frame(width: 132, alignment: .leading)157 .padding(10)158 .background(isSelected ? AnyShapeStyle(.tint.opacity(0.12)) : AnyShapeStyle(.quaternary.opacity(0.4)), in: RoundedRectangle(cornerRadius: 14, style: .continuous))159 .accessibilityElement(children: .combine)160 .accessibilityAddTraits(isSelected ? .isSelected : [])161 }162}163164struct FavoritesView: View {165 @Bindable var model: StudioModel166167 var body: some View {168 List {169 if model.favoriteDescriptors.isEmpty {170 ContentUnavailableView(L("No favourite yet"), systemImage: "star", description: Text(L("Open a component and tap the star to keep it here.")))171 }172 ForEach(model.favoriteDescriptors) { descriptor in173 Button { model.open(descriptor.id) } label: {174 ComponentRow(descriptor: descriptor, isFavorite: true).contentShape(Rectangle())175 }176 .buttonStyle(.plain)177 .swipeActions {178 Button(L("Remove"), systemImage: "star.slash", role: .destructive) { model.favorites.toggle(descriptor.id) }179 }180 }181 .onMove { model.favorites.move(fromOffsets: $0, toOffset: $1) }182 }183 .navigationTitle(Text(L("Favourites")))184 .accessibilityIdentifier("favorites")185 }186}187188struct SettingsView: View {189 @Bindable var model: StudioModel190 @AppStorage("studio.language") private var language = ""191 @State private var confirmsReset = false192193 var body: some View {194 Form {195 Section(L("Language")) {196 Picker(L("Interface language"), selection: $language) {197 Text(L("System")).tag("")198 Text(verbatim: "English").tag("en")199 Text(verbatim: "Français").tag("fr")200 }201 }202 Section {203 Picker(L("Preview appearance"), selection: $model.preview.appearance) {204 Text(L("System")).tag(GlassAppearance.system)205 Text(L("Light")).tag(GlassAppearance.light)206 Text(L("Dark")).tag(GlassAppearance.dark)207 }208 Toggle(L("Simulate Reduce Transparency"), isOn: $model.preview.simulateReduceTransparency)209 Toggle(L("Simulate Reduce Motion"), isOn: $model.preview.simulateReduceMotion)210 } header: {211 Text(L("Previews"))212 } footer: {213 Text(L("Simulations change previews only. To test the real settings, use the Accessibility settings of the device."))214 }215 Section(L("Data")) {216 LabeledContent(L("Custom themes"), value: "\(model.themes.customThemes.count)")217 LabeledContent(L("Favourites"), value: "\(model.favorites.componentIDs.count)")218 Button(L("Reset the playground"), role: .destructive) { confirmsReset = true }219 }220 Section {221 LabeledContent(L("GlassKit version"), value: GlassKitInfo.version)222 LabeledContent(L("Components"), value: "\(model.catalog.descriptors.count)")223 LabeledContent(L("Licence"), value: GlassKitInfo.license)224 if let url = URL(string: GlassKitInfo.websiteURL) { Link(L("Website"), destination: url) }225 if let url = URL(string: GlassKitInfo.repositoryURL) { Link(L("Source code"), destination: url) }226 } header: {227 Text(L("About"))228 } footer: {229 Text(L("SP GlassKit is an independent project and is not affiliated with Apple Inc. The Studio stores your themes on this device only, makes no network request on its own and collects nothing."))230 }231 }232 .formStyle(.grouped)233 .navigationTitle(Text(L("Settings")))234 .confirmationDialog(L("Reset the playground?"), isPresented: $confirmsReset, titleVisibility: .visible) {235 Button(L("Reset"), role: .destructive) { model.resetPlayground(to: .form) }236 Button(L("Cancel"), role: .cancel) {}237 } message: {238 Text(L("The current composition is replaced by the form template."))239 }240 .accessibilityIdentifier("settings")241 }242}243