SPB Git

Repository Public MIT

glass-compass.md 2.6 KB 68 lines markdown

1# GlassCompass23| | |4|---|---|5| Identifier | `glass-compass` |6| Module | `SPGlassMaps` |7| Kind | `custom-glass` — a round interactive `glassSurface` |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Maps/GlassCompassExample.swift` |1011## Minimal usage1213```swift14GlassCompass(heading: mapHeading) { mapHeading = 0 }15```1617## Variants1819| Variant | Use |20|---|---|21| `heading: Double` | The needle points north for a map rotated by that heading. |22| `heading: nil` | Heading unavailable: outlined, dimmed needle; the button is disabled. |23| `size:` | `.small`, `.regular`, `.large`. |2425## Parameters2627| Parameter | Type | Default | Meaning |28|---|---|---|---|29| `heading` | `Double?` | — | Direction the top of the map points to, degrees clockwise from north. Any finite value; it is normalised to 0…359. NaN and infinities count as unavailable. |30| `size` | `GlassControlSize` | `.regular` | Size of the control. |31| `onResetNorth` | `@MainActor () -> Void` | — | Called on activation; the host rotates its map back to north. |3233## States3435- **Heading known**: filled north arrow in the theme's `destructive` colour (the conventional red needle), rotated by the opposite of the heading.36- **Unavailable**: outlined arrow in the secondary text colour, not rotated, button disabled.37- **Pressed / focused**: the interactive glass reacts to touch and pointer.3839The needle rotates along the shortest arc: from 350° to 10° it turns 20°, not 340° (`GlassHeading.needleRotation`).4041## Advanced example4243```swift44struct MapChrome: View {45    @Bindable var engine: TileEngine          // a GlassMapEngine4647    var body: some View {48        GlassCompass(heading: engine.heading, size: .large) {49            withAnimation(.smooth) { engine.resetNorth() }50        }51        .opacity(engine.heading == 0 ? 0.6 : 1)   // de-emphasise when already north-up52    }53}54```5556## Accessibility5758- Label "Reset to north"; value "Heading 270 degrees" or "Heading unavailable". The tooltip on macOS is the same text.59- Availability is conveyed by the shape of the symbol (filled or outlined), the disabled state and the value — not by colour alone.60- With Reduce Motion the needle is set to its new angle without a rotation animation.61- The target is at least 44 points on iOS and iPadOS.6263## Limits6465- The compass shows an injected heading: it does not read the device compass or any sensor.66- The needle is an SF Symbol; there are no cardinal letters or degree ticks.67- Every change of `heading` starts a short animation; an engine that reports the heading on every frame of a gesture should round it or throttle it.68
Files main
Menu

Theme