InlinePickerStyle.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. /// A picker style that shows its options inline within the picker's content.
  2. ///
  3. /// Depending on the backend, this may appear as a radio group, a wheel picker,
  4. /// or a segmented picker.
  5. ///
  6. /// Only supported by AppKitBackend, UIKitBackend, and WinUIBackend.
  7. public struct InlinePickerStyle: PickerStyle, _BuiltinPickerStyle {
  8. public nonisolated init() {}
  9. public func _asBackendPickerStyle<Backend: BaseAppBackend>(backend: Backend)
  10. -> BackendPickerStyle
  11. {
  12. // If the backend only supports .menu, or doesn't support pickers at
  13. // all, then inline pickers aren't supported regardless -- so it doesn't
  14. // matter which of the three is returned in that case.
  15. if backend.supportedPickerStyles.contains(.radioGroup) {
  16. .radioGroup
  17. } else if backend.supportedPickerStyles.contains(.wheel) {
  18. .wheel
  19. } else {
  20. .segmented
  21. }
  22. }
  23. }
  24. extension PickerStyle where Self == InlinePickerStyle {
  25. /// A picker style that shows its options inline within the picker's content.
  26. ///
  27. /// Depending on the backend, this may appear as a radio group, a wheel picker,
  28. /// or a segmented picker.
  29. ///
  30. /// Only supported by AppKitBackend, UIKitBackend, and WinUIBackend.
  31. public static nonisolated var inline: Self { Self() }
  32. }