Skip to content

Commit b8b3d05

Browse files
committed
final cleanup and documentation
1 parent c43908e commit b8b3d05

File tree

5 files changed

+74
-6
lines changed

5 files changed

+74
-6
lines changed

Sources/SwiftCrossUI/Path.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,16 +229,32 @@ public struct Path {
229229

230230
public init() {}
231231

232+
/// Move the path's current point to the given point.
233+
///
234+
/// This does not draw a line segment. For that, see ``addLine(to:)``.
235+
///
236+
/// If ``addLine(to:)``, ``addQuadCurve(control:to:)``,
237+
/// ``addCubicCurve(control1:control2:to:)``, or
238+
/// ``addArc(center:radius:startAngle:endAngle:clockwise:)`` is called on an empty path
239+
/// without calling this method first, the start point is implicitly (0, 0).
232240
public consuming func move(to point: SIMD2<Double>) -> Path {
233241
actions.append(.moveTo(point))
234242
return self
235243
}
236244

245+
/// Add a line segment from the current point to the given point.
246+
///
247+
/// After this, the path's current point will be the endpoint of this line segment.
237248
public consuming func addLine(to point: SIMD2<Double>) -> Path {
238249
actions.append(.lineTo(point))
239250
return self
240251
}
241252

253+
/// Add a quadratic Bézier curve to the path.
254+
///
255+
/// This creates an order-2 curve starting at the path's current point, bending towards
256+
/// `control`, and ending at `endPoint`. After this, the path's current point will be
257+
/// `endPoint`.
242258
public consuming func addQuadCurve(
243259
control: SIMD2<Double>,
244260
to endPoint: SIMD2<Double>
@@ -247,6 +263,11 @@ public struct Path {
247263
return self
248264
}
249265

266+
/// Add a cubic Bézier curve to the path.
267+
///
268+
/// This creates an order-3 curve starting at the path's current point, bending towards
269+
/// `control1` and `control2`, and ending at `endPoint`. After this, the path's current
270+
/// point will be `endPoint`.
250271
public consuming func addCubicCurve(
251272
control1: SIMD2<Double>,
252273
control2: SIMD2<Double>,
@@ -267,6 +288,9 @@ public struct Path {
267288
}
268289

269290
/// Add an arc segment to the path.
291+
///
292+
/// After this, the path's current point will be the endpoint implied by `center`, `radius`,
293+
/// and `endAngle`.
270294
/// - Parameters:
271295
/// - center: The location of the center of the circle.
272296
/// - radius: The radius of the circle.
@@ -297,11 +321,21 @@ public struct Path {
297321
return self
298322
}
299323

324+
/// Apply the given transform to the segments in the path so far.
325+
///
326+
/// While this may adjust the path's current point, it does not otherwise affect segments
327+
/// that are added to the path after this method call.
300328
public consuming func applyTransform(_ transform: AffineTransform) -> Path {
301329
actions.append(.transform(transform))
302330
return self
303331
}
304332

333+
/// Add the entirety of another path as part of this path.
334+
///
335+
/// This can be necessary to section off transforms, as transforms applied to `subpath`
336+
/// will not affect this path.
337+
///
338+
/// The fill rule and preferred stroke style of the subpath are ignored.
305339
public consuming func addSubpath(_ subpath: Path) -> Path {
306340
actions.append(.subpath(subpath.actions))
307341
return self
@@ -316,6 +350,7 @@ public struct Path {
316350
return self
317351
}
318352

353+
/// Set the fill rule for the path.
319354
public consuming func fillRule(_ rule: FillRule) -> Path {
320355
fillRule = rule
321356
return self

Sources/SwiftCrossUI/Views/Shapes/Circle.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public struct Circle: Shape {
1414
idealSize: SIMD2(x: 10, y: 10),
1515
idealWidthForProposedHeight: proposal.y,
1616
idealHeightForProposedWidth: proposal.x,
17-
minimumWidth: 1,
18-
minimumHeight: 1,
17+
minimumWidth: 0,
18+
minimumHeight: 0,
1919
maximumWidth: nil,
2020
maximumHeight: nil
2121
)

Sources/SwiftCrossUI/Views/Shapes/RoundedRectangle.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public struct RoundedRectangle: Shape {
3131
)
3232

3333
// This corresponds to r_{min} in the above Desmos link. This is the minimum ratio of
34-
// cornerRadius to half the side length at which the superellipse is ignored. Above this,
34+
// cornerRadius to half the side length at which the superellipse is not applicable. Above this,
3535
// line segments and circular arcs are used.
3636
private static let rMin = 0.441968022436
3737

Sources/SwiftCrossUI/Views/Shapes/Shape.swift

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
1+
/// A 2-D shape that can be drawn as a view.
2+
///
3+
/// If no stroke color or fill color is specified, the default is no stroke and a fill of the
4+
/// current foreground color.
15
public protocol Shape: View
26
where Content == EmptyView {
37
/// Draw the path for this shape.
48
///
9+
/// The bounds passed to a shape that is immediately drawn as a view will always have an
10+
/// origin of (0, 0). However, you may pass a different bounding box to subpaths. For example,
11+
/// this code draws a rectangle in the left half of the bounds and an ellipse in the right half:
12+
/// ```swift
13+
/// func path(in bounds: Path.Rect) -> Path {
14+
/// Path()
15+
/// .addSubpath(
16+
/// Rectangle().path(
17+
/// in: Path.Rect(
18+
/// x: bounds.x,
19+
/// y: bounds.y,
20+
/// width: bounds.width / 2.0,
21+
/// height: bounds.height
22+
/// )
23+
/// )
24+
/// )
25+
/// .addSubpath(
26+
/// Ellipse().path(
27+
/// in: Path.Rect(
28+
/// x: bounds.center.x,
29+
/// y: bounds.y,
30+
/// width: bounds.width / 2.0,
31+
/// height: bounds.height
32+
/// )
33+
/// )
34+
/// )
35+
/// }
36+
/// ```
537
func path(in bounds: Path.Rect) -> Path
638
/// Determine the ideal size of this shape given the proposed bounds.
739
///
@@ -11,7 +43,7 @@ where Content == EmptyView {
1143
/// frame the shape will actually be rendered with if the current layout pass is not
1244
/// a dry run, while the other properties are used to inform the layout engine how big
1345
/// or small the shape can be. The ``ViewSize/idealSize`` property should not vary with
14-
/// the `proposal`, and should only depend on the view's contents. Pass `nil` for the
46+
/// the `proposal`, and should only depend on the shape's contents. Pass `nil` for the
1547
/// maximum width/height if the shape has no maximum size (and therefore may occupy
1648
/// the entire screen).
1749
func size(fitting proposal: SIMD2<Int>) -> ViewSize
@@ -24,8 +56,8 @@ extension Shape {
2456
return ViewSize(
2557
size: proposal,
2658
idealSize: SIMD2(x: 10, y: 10),
27-
minimumWidth: 1,
28-
minimumHeight: 1,
59+
minimumWidth: 0,
60+
minimumHeight: 0,
2961
maximumWidth: nil,
3062
maximumHeight: nil
3163
)

Sources/SwiftCrossUI/Views/Shapes/StyledShape.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// A shape that has style information attached to it, including color and stroke style.
12
public protocol StyledShape: Shape {
23
var strokeColor: Color? { get }
34
var fillColor: Color? { get }

0 commit comments

Comments
 (0)