Path builder is a complete result builder for lifting Path
into the declarative SwiftUI world. This @resultBuilder
can be used for elegant and short definition of paths. Missing documentation gaps in SwiftUI are filled in using the old but good CGMutablePath knowledge.
I just wanted to learn to implement result builders. And during playing with animated paths in SwiftUI found a perfect place to experiment.
With PathBuilder you can write this to draw a triangle:
Path {
Move(to: CGPoint(x: 50, y: 50))
Line(to: CGPoint(x: 100, y: 100))
Line(to: CGPoint(x: 0, y: 100))
Close()
}
Instead of longer version:
Path { p in
p.move(to: CGPoint(x: 50, y: 50))
p.addLine(to: CGPoint(x: 100, y: 100))
p.addLine(to: CGPoint(x: 0, y: 100))
p.closeSubpath()
}
Drawing a Swift logo can be implemented like this.
There are many basic path components present. You can create a new one by conforming to the PathComponent
protocol.
For Swift 5.1 to 5.3 use package version 1.1.1.
Otherwise for version 2.0+ use latest tools:
Using Swift Package Manager in Xcode or by adding to your Package manifest file.
All contributions are welcome.
Project was created by Matěj Kašpar Jirásek.
Project is licensed under MIT license.
link |
Stars: 68 |
Last commit: 19 weeks ago |
Full Changelog: https://github.com/mkj-is/PathBuilder/compare/2.0.1...2.1.0
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics