SPB Git

Repository Public MIT

doc-glass-slider.md 3.3 KB 75 lines markdown

1# GlassSlider23| | |4|---|---|5| Identifier | `glass-slider` |6| Module | `SPGlassForms` |7| Kind | `native-wrapper` — the system `Slider`, tinted with the theme's `primary` colour |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Selection/GlassSliderExample.swift` |1011## Minimal usage1213```swift14@State private var volume = 0.51516GlassSlider("Volume", value: $volume)17```1819## Variants2021| Variant | Use |22|---|---|23| `in:` | Bounds. `0...1` by default. |24| `step:` | Distance between two values; without it the slider is continuous. |25| `format:` (a `FormatStyle`) | `.percent`, `.currency(code:)`, `.number.precision(…)`. |26| trailing closure | Any formatting, for measurements for example. |27| `showsValue: false` | Hides the value next to the title. |28| `showsBoundLabels: true` | Formatted minimum and maximum under both ends of the track. |29| `showsTicks: true` | A mark under the track for each step (quarter marks for a continuous slider or more than 20 steps); the marks up to the value take the `primary` colour. |3031## Parameters3233| Parameter | Type | Default | Meaning |34|---|---|---|---|35| `title` | `LocalizedStringKey` | — | Title above the slider; also its accessibility label. |36| `value` | `Binding<Double>` | — | The value. |37| `in` | `ClosedRange<Double>` | `0...1` | Bounds. |38| `step` | `Double?` | `nil` | Step. |39| `format` | `FormatStyle` or `(Double) -> String` | number, up to 2 decimals | Text of a value. |40| `showsValue` | `Bool` | `true` | Value next to the title. |41| `showsBoundLabels` | `Bool` | `false` | Bound labels. |42| `showsTicks` | `Bool` | `false` | Tick marks under the track (1.1). |43| `onEditingChanged` | `@MainActor (Bool) -> Void` | `{ _ in }` | Drag started (`true`) or ended (`false`). |4445## States4647Idle, dragging (`onEditingChanged`), focused and disabled (`.disabled(_:)`) are drawn by the system.4849## Advanced example5051```swift52GlassSlider("Temperature", value: $celsius, in: 16...28, step: 0.5, showsBoundLabels: true,53            onEditingChanged: { if !$0 { thermostat.commit(celsius) } }) { value in54    Measurement(value: value, unit: UnitTemperature.celsius)55        .formatted(.measurement(width: .abbreviated, usage: .asProvided))56}57```5859`GlassSliderMath.snapped(_:in:step:)` gives the value a slider with these bounds and step would hold, for code that sets the value itself.6061## Accessibility6263- The slider is the system's adjustable element: VoiceOver swipes up and down, arrow keys work on macOS and with a keyboard on iPad.64- Its accessibility value is the formatted text ("21.5 °C", "60 %"), not the raw number.65- The value shown next to the title uses monospaced digits, so the layout does not jitter while dragging.66- When title and value do not fit on one line (large text, long title), the value moves under the title.6768## Limits6970- `Double` only; convert other numeric types in the binding.71- The track, the thumb and its glass are drawn by the system.72- Tick marks and bound labels are decoration, hidden from VoiceOver. The marks are lined up with the thumb's travel using an approximation of the system metrics (`GlassSliderMath.tickFractions(in:step:)` gives their positions).73- The size of a VoiceOver adjustment is the step when there is one, otherwise the system's default increment.74- VoiceOver output and keyboard adjustment were not exercised on a running device here.75
Files main
Menu

Theme