Paths.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. public typealias UIPath = Path
  2. extension BackendFeatures {
  3. /// Backend methods for path rendering.
  4. ///
  5. /// These are used by ``Shape`` and related types and modifiers.
  6. @MainActor
  7. public protocol Paths<Path>: Core {
  8. /// The underlying path type. Can be a wrapper or subclass.
  9. associatedtype Path
  10. /// Create a widget that can contain a path.
  11. ///
  12. /// - Returns: A path widget.
  13. func createPathWidget() -> Widget
  14. /// Create a path.
  15. ///
  16. /// - Returns: An empty path.
  17. func createPath() -> Path
  18. /// Add the instructions from a path to a backend path.
  19. ///
  20. /// The instructions shouldn't be added to the path again on subsequent updates. Wait for
  21. /// `updatePath` to be called with `pointsChanged == true` before re-applying instructions.
  22. ///
  23. /// If a backend's path isn't mutable, this method should return the new path rather than
  24. /// updating it in-place. Alternatively, the old path can be mutated in-place and returned.
  25. ///
  26. /// - Parameters:
  27. /// - path: The backend path to update.
  28. /// - source: The path instructions.
  29. /// - bounds: The bounds that the path is being rendered within.
  30. /// - pointsChanged: An indicator of whether the instructions have changed since the last
  31. /// call to this method. The backend can use this to optimize when updates occur.
  32. /// - environment: The environment of the path.
  33. func updatePath(
  34. _ path: Path,
  35. _ source: UIPath,
  36. bounds: UIPath.Rect,
  37. pointsChanged: Bool,
  38. environment: EnvironmentValues
  39. )
  40. /// Draw a path to the screen.
  41. ///
  42. /// - Parameters:
  43. /// - path: The path to be rendered.
  44. /// - container: The container widget that the path will render in.
  45. /// Created with ``createPathWidget()``.
  46. /// - strokeColor: The color to draw the path's stroke.
  47. /// - fillColor: The color to shade the path's fill.
  48. /// - overrideStrokeStyle: A value to override the path's stroke style.
  49. func renderPath(
  50. _ path: Path,
  51. container: Widget,
  52. strokeColor: Color.Resolved,
  53. fillColor: Color.Resolved,
  54. overrideStrokeStyle: StrokeStyle?
  55. )
  56. }
  57. }