1
0

MenuImplementationStyle.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /// How a backend implements popover menus.
  2. ///
  3. /// Regardless of implementation style, backends are expected to implement
  4. /// the methods in ``BackendFeatures/MenuButtons``.
  5. ///
  6. /// ## See Also
  7. /// - ``BackendFeatures/MenuButtons/menuImplementationStyle-4blzf``
  8. public enum MenuImplementationStyle<Widget, Menu> {
  9. /// The backend can show popover menus arbitrarily.
  10. ///
  11. /// Backends that use this style must implement ``BackendFeatures/PopoverMenus``.
  12. /// For these backends, ``BackendFeatures/MenuButtons/createPopoverMenu()`` is not
  13. /// called until after the button is tapped.
  14. ///
  15. /// When returning this from a manual implementation of
  16. /// ``BackendFeatures/MenuButtons/menuImplementationStyle-4blzf``, it is recommended to simply
  17. /// conform your existing backend to ``BackendFeatures/PopoverMenus`` and use `self`
  18. /// as the associated value:
  19. ///
  20. /// ```swift
  21. /// extension MyBackend: BackendFeatures.PopoverMenus {
  22. /// var menuImplementationStyle: MenuImplementationStyle<Widget, Menu> {
  23. /// .dynamicPopover(self)
  24. /// }
  25. ///
  26. /// // ...other methods...
  27. /// }
  28. /// ```
  29. ///
  30. /// ## See Also
  31. /// - ``BackendFeatures/MenuButtons/menuImplementationStyle-4blzf``
  32. /// - ``BackendFeatures/MenuButtons/menuImplementationStyle-136z8`` <!-- default implementation -->
  33. case dynamicPopover(any BackendFeatures.PopoverMenus<Widget, Menu>)
  34. /// The backend requires menus to be constructed and attached to buttons
  35. /// ahead of time.
  36. ///
  37. /// Backends that use this style must implement
  38. /// ``BackendFeatures/AttachedMenus``.
  39. ///
  40. /// When returning this from a manual implementation of
  41. /// ``BackendFeatures/MenuButtons/menuImplementationStyle-4blzf``, it is recommended to simply
  42. /// conform your existing backend to ``BackendFeatures/AttachedMenus`` and use `self`
  43. /// as the associated value:
  44. ///
  45. /// ```swift
  46. /// extension MyBackend: BackendFeatures.AttachedMenus {
  47. /// var menuImplementationStyle: MenuImplementationStyle<Widget, Menu> {
  48. /// .menuButton(self)
  49. /// }
  50. ///
  51. /// // ...other methods...
  52. /// }
  53. /// ```
  54. ///
  55. /// ## See Also
  56. /// - ``BackendFeatures/MenuButtons/menuImplementationStyle-4blzf``
  57. /// - ``BackendFeatures/MenuButtons/menuImplementationStyle-29bja`` <!-- default implementation -->
  58. case menuButton(any BackendFeatures.AttachedMenus<Widget, Menu>)
  59. }