Windowing.swift 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. extension BackendFeatures {
  2. /// Extra backend methods for window handling.
  3. ///
  4. /// ## Topics
  5. ///
  6. /// ### Constituent Protocols
  7. /// - ``WindowBehaviors``
  8. /// - ``WindowClosing``
  9. public typealias Windowing = WindowBehaviors & WindowClosing
  10. /// Backend methods for setting window behaviors.
  11. @MainActor
  12. public protocol WindowBehaviors<Window>: Core {
  13. /// Sets the behaviors of a window.
  14. ///
  15. /// - Parameters:
  16. /// - window: The window to set the behaviors on.
  17. /// - closable: Whether the window can be closed by the user.
  18. /// - minimizable: Whether the window can be minimized by the user.
  19. /// - resizable: Whether the window can be resized by the user. Even if
  20. /// resizable, the window shouldn't be allowed to become smaller than its
  21. /// minimum size, or larger than its maximum size.
  22. func setBehaviors(
  23. ofWindow window: Window,
  24. closable: Bool,
  25. minimizable: Bool,
  26. resizable: Bool
  27. )
  28. }
  29. /// Backend methods for closing windows.
  30. @MainActor
  31. public protocol WindowClosing<Window>: Core {
  32. /// Closes a window.
  33. ///
  34. /// At some point during or after execution of this function, the handler
  35. /// set by ``setCloseHandler(ofWindow:to:)`` should be called.
  36. /// Oftentimes this will be done automatically by the backend's underlying
  37. /// UI framework.
  38. ///
  39. /// This is primarily used by ``DismissWindowAction``.
  40. func close(window: Window)
  41. /// Sets the handler for the window's close events (for example, when the
  42. /// user clicks the close button in the title bar).
  43. ///
  44. /// The close handler should also be called whenever ``close(window:)-9xucx``
  45. /// is called (some UI frameworks do this automatically).
  46. ///
  47. /// This is used by SwiftCrossUI to release scene nodes' references to
  48. /// `window` when the window is closed.
  49. ///
  50. /// This is only called once per window; as such, it doesn't matter if
  51. /// setting the close handler again overrides the previous handler or adds a
  52. /// new one.
  53. func setCloseHandler(
  54. ofWindow window: Window,
  55. to action: @escaping () -> Void
  56. )
  57. }
  58. }