-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@frozen | ||
public struct ForegroundStyle: ShapeStyle { | ||
@inlinable | ||
public init() {} | ||
|
||
public static func _makeView<S>(view: _GraphValue<_ShapeView<S, ForegroundStyle>>, inputs: _ViewInputs) -> _ViewOutputs where S: Shape { | ||
fatalError("TODO") | ||
} | ||
} | ||
|
||
#if OPENSWIFTUI_SUPPORT_2021_API | ||
|
||
extension ForegroundStyle { | ||
public func _apply(to shape: inout _ShapeStyle_Shape) { | ||
fatalError("TODO") | ||
} | ||
|
||
public static func _apply(to type: inout _ShapeStyle_ShapeType) { | ||
fatalError("TODO") | ||
} | ||
} | ||
|
||
extension ShapeStyle where Self == ForegroundStyle { | ||
@_alwaysEmitIntoClient | ||
public static var foreground: ForegroundStyle { | ||
.init() | ||
} | ||
} | ||
#endif |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Foundation | ||
|
||
/// A rectangular shape aligned inside the frame of the view containing it. | ||
@frozen | ||
public struct Rectangle: Shape { | ||
public func path(in rect: CGRect) -> Path { | ||
fatalError("TODO") | ||
} | ||
|
||
/// Creates a new rectangle shape. | ||
@inlinable | ||
public init() {} | ||
|
||
public typealias AnimatableData = EmptyAnimatableData | ||
|
||
public typealias Body = _ShapeView<Rectangle, ForegroundStyle> | ||
} | ||
|
||
|
||
extension Shape where Self == Rectangle { | ||
/// A rectangular shape aligned inside the frame of the view containing it. | ||
public static var rect: Rectangle { | ||
Rectangle() | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// Shape.swift | ||
// OpenSwiftUI | ||
// | ||
// Audited for RELEASE_2021 | ||
// Status: WIP | ||
|
||
import Foundation | ||
|
||
/// A 2D shape that you can use when drawing a view. | ||
/// | ||
/// Shapes without an explicit fill or stroke get a default fill based on the | ||
/// foreground color. | ||
/// | ||
/// You can define shapes in relation to an implicit frame of reference, such as | ||
/// the natural size of the view that contains it. Alternatively, you can define | ||
/// shapes in terms of absolute coordinates. | ||
public protocol Shape: Animatable, View { | ||
/// Describes this shape as a path within a rectangular frame of reference. | ||
/// | ||
/// - Parameter rect: The frame of reference for describing this shape. | ||
/// | ||
/// - Returns: A path that describes this shape. | ||
func path(in rect: CGRect) -> Path | ||
|
||
#if OPENSWIFTUI_SUPPORT_2021_API | ||
/// An indication of how to style a shape. | ||
/// | ||
/// OpenSwiftUI looks at a shape's role when deciding how to apply a | ||
/// ``ShapeStyle`` at render time. The ``Shape`` protocol provides a | ||
/// default implementation with a value of ``ShapeRole/fill``. If you | ||
/// create a composite shape, you can provide an override of this property | ||
/// to return another value, if appropriate. | ||
static var role: ShapeRole { get } | ||
#endif | ||
} | ||
|
||
extension Shape { | ||
public var body: _ShapeView<Self, ForegroundStyle> { | ||
_ShapeView(shape: self, style: ForegroundStyle()) | ||
} | ||
} | ||
|
||
#if OPENSWIFTUI_SUPPORT_2021_API | ||
|
||
extension Shape { | ||
public static var role: ShapeRole { | ||
.fill | ||
} | ||
} | ||
#endif |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// ShapeRole.swift | ||
// OpenSwiftUI | ||
// | ||
// Audited for RELEASE_2021 | ||
// Status: Complete | ||
|
||
#if OPENSWIFTUI_SUPPORT_2021_API | ||
|
||
/// Ways of styling a shape. | ||
public enum ShapeRole: Sendable { | ||
/// Indicates to the shape's style that SwiftUI fills the shape. | ||
case fill | ||
|
||
/// Indicates to the shape's style that SwiftUI applies a stroke to | ||
/// the shape's path. | ||
case stroke | ||
|
||
/// Indicates to the shape's style that SwiftUI uses the shape as a | ||
/// separator. | ||
case separator | ||
} | ||
|
||
extension ShapeRole: Equatable {} | ||
extension ShapeRole: Hashable {} | ||
|
||
#endif |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
public protocol ShapeStyle { | ||
@available(*, deprecated, message: "obsolete") | ||
static func _makeView<S>(view: _GraphValue<_ShapeView<S, Self>>, inputs: _ViewInputs) -> _ViewOutputs where S : Shape | ||
|
||
#if OPENSWIFTUI_SUPPORT_2021_API | ||
func _apply(to shape: inout _ShapeStyle_Shape) | ||
|
||
static func _apply(to type: inout _ShapeStyle_ShapeType) | ||
#endif | ||
} | ||
|
||
|
||
#if OPENSWIFTUI_SUPPORT_2021_API | ||
|
||
public struct _ShapeStyle_Shape { | ||
// TODO | ||
} | ||
|
||
public struct _ShapeStyle_ShapeType { | ||
// TODO | ||
} | ||
|
||
extension ShapeStyle { | ||
public static func _makeView<S>(view: _GraphValue<_ShapeView<S, Self>>, inputs: _ViewInputs) -> _ViewOutputs where S: Shape { | ||
fatalError("TODO") | ||
} | ||
|
||
public func _apply(to shape: inout _ShapeStyle_Shape) { | ||
fatalError("TODO") | ||
} | ||
|
||
public static func _apply(to type: inout _ShapeStyle_ShapeType) { | ||
fatalError("TODO") | ||
} | ||
} | ||
|
||
|
||
#endif |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@frozen | ||
public struct _ShapeView<Content, Style>: PrimitiveView where Content : Shape, Style: ShapeStyle { | ||
public var shape: Content | ||
public var style: Style | ||
public var fillStyle: FillStyle | ||
|
||
@inlinable | ||
public init(shape: Content, style: Style, fillStyle: FillStyle = FillStyle()) { | ||
self.shape = shape | ||
self.style = style | ||
self.fillStyle = fillStyle | ||
} | ||
|
||
|
||
public static func _makeView(view: _GraphValue<_ShapeView<Content, Style>>, inputs: _ViewInputs) -> _ViewOutputs { | ||
fatalError("TODO") | ||
} | ||
|
||
public typealias Body = Never | ||
} |