Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Examples/Gallery/Navigation/GlassToolbarExample.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 GlassToolbarExample: GlassExample {45 public static let componentID = "glass-toolbar"46 @State private var log = ["Nothing yet"]47 @State private var isPinned = false4849 public init() {}5051 private func record(_ entry: String) {52 log.insert(entry, at: 0)53 }5455 private var groups: [GlassToolbarGroup] {56 [57 GlassToolbarGroup(id: "document", placement: .trailing, capacity: 3, actions: [58 GlassToolbarAction(id: "share", title: "Share", systemImage: "square.and.arrow.up", shortcut: KeyboardShortcut("s", modifiers: [.command, .shift]), priority: .high) { record("Shared") },59 GlassToolbarAction(id: "pin", title: isPinned ? "Unpin" : "Pin", systemImage: isPinned ? "pin.fill" : "pin") {60 isPinned.toggle()61 record(isPinned ? "Pinned" : "Unpinned")62 },63 GlassToolbarAction(id: "duplicate", title: "Duplicate", systemImage: "plus.square.on.square", shortcut: KeyboardShortcut("d")) { record("Duplicated") },64 GlassToolbarAction(id: "archive", title: "Archive", systemImage: "archivebox", isEnabled: log.count > 1, priority: .low) { record("Archived") },65 GlassToolbarAction(id: "delete", title: "Delete", systemImage: "trash", role: .destructive, priority: .low) { log = ["Nothing yet"] },66 ]),67 GlassToolbarGroup(id: "export", placement: .secondary, actions: [68 GlassToolbarAction(id: "pdf", title: "Export as PDF", systemImage: "doc.richtext") { record("Exported as PDF") },69 GlassToolbarAction(id: "print", title: "Print", systemImage: "printer", shortcut: KeyboardShortcut("p")) { record("Printed") },70 ]),71 GlassToolbarGroup(id: "format", placement: .bottom, actions: [72 GlassToolbarAction(id: "bold", title: "Bold", systemImage: "bold", shortcut: KeyboardShortcut("b")) { record("Bold") },73 GlassToolbarAction(id: "italic", title: "Italic", systemImage: "italic", shortcut: KeyboardShortcut("i")) { record("Italic") },74 ]),75 ]76 }7778 public var body: some View {79 NavigationStack {80 List(Array(log.enumerated()), id: \.offset) { _, entry in81 Text(verbatim: entry)82 }83 .navigationTitle("Document")84 .glassToolbar(groups)85 }86 }87}8889#Preview("GlassToolbar") { GlassToolbarExample() }90