SPB Git

Repository Public MIT

GlassButtonGroup.swift 3.4 KB 90 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : SP GlassKit7// File             : Sources/SPGlassComponents/Buttons/GlassButtonGroup.swift8// Module           : SPGlassComponents9// 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 SwiftUI4243/// Lays related glass buttons out in one glass container.44///45/// ```swift46/// GlassButtonGroup {47///     GlassIconButton(systemImage: "bold", accessibilityLabel: "Bold") { … }48///     GlassIconButton(systemImage: "italic", accessibilityLabel: "Italic") { … }49/// }50/// ```51///52/// Glass cannot sample other glass: buttons that sit side by side must share a `GlassEffectContainer` to be53/// rendered consistently and to blend when they come close. The group provides that container, an even54/// spacing from the theme and a single accessibility container. It adds no surface of its own.55public struct GlassButtonGroup<Content: View>: View {56    @GlassThemed private var theme57    private let axis: Axis58    private let spacing: GlassSpacingStep59    private let label: Text?60    private let content: Content6162    /// - Parameters:63    ///   - axis: direction of the group.64    ///   - spacing: distance between buttons, from the theme's spacing scale.65    ///   - accessibilityLabel: name of the group, read by VoiceOver before its buttons.66    public init(67        axis: Axis = .horizontal,68        spacing: GlassSpacingStep = .xs,69        accessibilityLabel: LocalizedStringKey? = nil,70        @ViewBuilder content: () -> Content71    ) {72        self.axis = axis73        self.spacing = spacing74        self.label = accessibilityLabel.map { Text($0) }75        self.content = content()76    }7778    public var body: some View {79        let distance = theme.spacing[spacing]80        GlassGroup(spacing: distance) {81            switch axis {82            case .horizontal: HStack(spacing: distance) { content }83            case .vertical: VStack(spacing: distance) { content }84            }85        }86        .accessibilityElement(children: .contain)87        .accessibilityLabel(label ?? Text(verbatim: ""))88    }89}90
Files main
Menu

Theme