Last active
September 1, 2023 09:36
-
-
Save sebj/a053cc42005e214a4257cb7014fdaa15 to your computer and use it in GitHub Desktop.
AnyInsettableShape
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// A type-erased shape that is able to inset itself to produce another shape. | |
/// | |
/// See: [AnyShape](https://developer.apple.com/documentation/swiftui/anyshape), [InsettableShape](https://developer.apple.com/documentation/swiftui/insettableshape) | |
struct AnyInsettableShape: InsettableShape { | |
private let _sizeThatFits: (ProposedViewSize) -> CGSize | |
private let _path: (CGRect) -> Path | |
private let _inset: (CGFloat) -> AnyInsettableShape | |
init<S>(_ shape: S) where S : InsettableShape { | |
_sizeThatFits = shape.sizeThatFits | |
_path = shape.path | |
_inset = { AnyInsettableShape(shape.inset(by: $0)) } | |
} | |
func sizeThatFits(_ proposal: ProposedViewSize) -> CGSize { | |
_sizeThatFits(proposal) | |
} | |
func path(in rect: CGRect) -> Path { | |
_path(rect) | |
} | |
func inset(by amount: CGFloat) -> some InsettableShape { | |
_inset(amount) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment