ToggleButtons.swift 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. extension BackendFeatures {
  2. /// Backend methods for toggle buttons.
  3. ///
  4. /// These are used by ``Toggle`` when ``EnvironmentValues/toggleStyle`` is
  5. /// ``ToggleStyle/button``.
  6. @MainActor
  7. public protocol ToggleButtons: Core {
  8. /// Creates a labelled toggle that is either on or off.
  9. ///
  10. /// - Returns: A toggle.
  11. func createToggle() -> Widget
  12. /// Sets the label and change handler of a toggle.
  13. ///
  14. /// - Parameters:
  15. /// - toggle: The toggle to update.
  16. /// - label: The toggle's label.
  17. /// - environment: The current environment.
  18. /// - onChange: The action to perform when the button is toggled on or
  19. /// off. This replaces any existing change handlers.
  20. func updateToggle(
  21. _ toggle: Widget,
  22. label: String,
  23. environment: EnvironmentValues,
  24. onChange: @escaping (Bool) -> Void
  25. )
  26. /// Sets the state of a toggle.
  27. ///
  28. /// - Parameters:
  29. /// - toggle: The toggle to set the state of.
  30. /// - state: The new state.
  31. func setState(ofToggle toggle: Widget, to state: Bool)
  32. }
  33. }