SPB Git

Repository Public MIT

glass-panel.md 3.4 KB 72 lines markdown

1# GlassPanel23| | |4|---|---|5| Identifier | `glass-panel` |6| Module | `SPGlassComponents` |7| Kind | `custom-glass` — one `glassSurface`; the controls inside are plain system controls |8| Platforms | iOS 26, iPadOS 26, macOS 26 (resizing and focus scope on macOS only) |9| Example | `Examples/Gallery/Containers/GlassPanelExample.swift` |1011## Minimal usage1213```swift14GlassPanel("Layers") {15    Toggle("Transit", isOn: $showsTransit)16}17```1819## Variants2021| Variant | Use |22|---|---|23| Fixed | No `size`: the panel takes the size of its content. |24| Resizable (macOS) | `size: $panelSize`: a handle in the trailing-bottom corner resizes within `sizeLimits`. |25| Closable | `onClose:` adds a close button; Escape calls it. |2627## Parameters2829| Parameter | Type | Default | Meaning |30|---|---|---|---|31| `title` | `LocalizedStringKey` or `Text` | — | Heading and accessibility label of the panel. |32| `size` | `Binding<CGSize>?` | `nil` | Controlled size on macOS. Ignored on iOS and iPadOS. |33| `sizeLimits` | `GlassPanelSizeLimits` | `.standard` (240 × 160 to 720 × 640) | Bounds applied to `size`. |34| `onClose` | `(@MainActor () -> Void)?` | `nil` | Shows the close button and handles Escape. |35| `content` | `@ViewBuilder` | — | Controls of the panel. |3637`GlassPanelSizeLimits.clamp(_:)` and `resized(from:translation:isRightToLeft:)` are pure and can be reused by the host, for example to restore a saved size.3839## States4041The panel itself has no state. The host decides whether it is shown; `size` is the host's state. While the handle is dragged the size follows the pointer immediately, without animation.4243## Advanced example4445```swift46@State private var size = CGSize(width: 320, height: 240)47let limits = GlassPanelSizeLimits(minimum: CGSize(width: 260, height: 180), maximum: CGSize(width: 520, height: 420))4849GlassPanel("Inspector", size: $size, sizeLimits: limits, onClose: { showsInspector = false }) {50    Picker("Blend", selection: $blend) { ForEach(Blend.allCases) { Text($0.name).tag($0) } }51    Slider(value: $opacity, in: 0...1) { Text("Opacity") }52}53.onChange(of: size) { _, new in settings.inspectorSize = limits.clamp(new) }54```5556## Accessibility5758- The panel is an accessibility container named by its title; the title has the header trait.59- The close button is labelled "Close" (localised) and has the minimum hit target.60- macOS: the panel is a focus scope and a focus section, so Tab and arrow keys move among its controls as a group. Escape calls `onClose` while focus is inside the panel.61- iOS and iPadOS with a hardware keyboard: Escape triggers the close button (`.keyboardShortcut(.cancelAction)`).62- The resize handle is focusable (arrow keys resize by one spacing step), is announced as "Resize panel" with the current size as its value, and supports the VoiceOver adjustable action.63- With Reduce Transparency the surface is opaque (handled by `glassSurface`).6465## Limits6667- The panel does not move itself: place it with `overlay`, `safeAreaInset` or your own drag logic.68- Resizing exists on macOS only; on iPadOS use a sheet with detents or `GlassMapPanel` for an extensible panel.69- Keep the content to controls and short labels; long or dense content belongs in an opaque `GlassCard`.70- Do not put glass buttons (`GlassButton`) inside the panel: glass must not sit inside glass. Use plain or bordered system buttons.71- The behaviour of focus and Escape was compiled but not exercised in a running application by the automated tests.72
Files main
Menu

Theme