Skip to content

Commit

Permalink
Merge pull request #29 from jrsaruo/maintenance/line-breaking-style
Browse files Browse the repository at this point in the history
Changed the line-breaking style
  • Loading branch information
jrsaruo committed Mar 30, 2024
2 parents c4e1856 + 29354a1 commit da5bdac
Show file tree
Hide file tree
Showing 26 changed files with 1,899 additions and 809 deletions.
10 changes: 5 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ let package = Package(
platforms: [.iOS(.v11), .macOS(.v10_13), .tvOS(.v11)],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "AceLayout",
targets: ["AceLayout"]),
.library(name: "AceLayout", targets: ["AceLayout"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
Expand All @@ -22,9 +20,11 @@ let package = Package(
.target(
name: "AceLayout",
dependencies: [],
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]),
swiftSettings: [.enableUpcomingFeature("ExistentialAny")]
),
.testTarget(
name: "AceLayoutTests",
dependencies: ["AceLayout"]),
dependencies: ["AceLayout"]
),
]
)
30 changes: 21 additions & 9 deletions Sources/AceLayout/LayoutAnchors/BaselineAnchor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ extension BaselineAnchor {
/// - offset: A constant offset for the constraint. The default value is `0`.
/// - Returns: An `NSLayoutConstraint` object that represents `self` baseline == `another` baseline + `offset`.
@inlinable
public func equal(to another: some BaselinesConstrainable,
plus offset: CGFloat = 0) -> NSLayoutConstraint {
public func equal(
to another: some BaselinesConstrainable,
plus offset: CGFloat = 0
) -> NSLayoutConstraint {
anchor.constraint(equalTo: another[keyPath: anchorKeyPath], constant: offset)
}

Expand All @@ -53,8 +55,10 @@ extension BaselineAnchor {
/// - offset: A constant offset for the constraint. The default value is `0`.
/// - Returns: An `NSLayoutConstraint` object that represents `self` baseline <= `another` baseline + `offset`.
@inlinable
public func lessThanOrEqual(to another: some BaselinesConstrainable,
plus offset: CGFloat = 0) -> NSLayoutConstraint {
public func lessThanOrEqual(
to another: some BaselinesConstrainable,
plus offset: CGFloat = 0
) -> NSLayoutConstraint {
anchor.constraint(lessThanOrEqualTo: another[keyPath: anchorKeyPath], constant: offset)
}

Expand All @@ -72,8 +76,10 @@ extension BaselineAnchor {
/// - offset: A constant offset for the constraint. The default value is `0`.
/// - Returns: An `NSLayoutConstraint` object that represents `self` baseline >= `another` baseline + `offset`.
@inlinable
public func greaterThanOrEqual(to another: some BaselinesConstrainable,
plus offset: CGFloat = 0) -> NSLayoutConstraint {
public func greaterThanOrEqual(
to another: some BaselinesConstrainable,
plus offset: CGFloat = 0
) -> NSLayoutConstraint {
anchor.constraint(greaterThanOrEqualTo: another[keyPath: anchorKeyPath], constant: offset)
}

Expand All @@ -93,7 +99,9 @@ extension BaselineAnchor {
/// - Returns: An `NSLayoutConstraint` object that represents `self` baseline == `superview` baseline + `offset`.
public func equalToSuperview(plus offset: CGFloat = 0) -> NSLayoutConstraint {
guard let superview = target.superview else {
preconditionFailure("The layout target must have a superview before making constraints on it.")
preconditionFailure(
"The layout target must have a superview before making constraints on it."
)
}
return equal(to: superview, plus: offset)
}
Expand All @@ -112,7 +120,9 @@ extension BaselineAnchor {
/// - Returns: An `NSLayoutConstraint` object that represents `self` baseline <= `superview` baseline + `offset`.
public func lessThanOrEqualToSuperview(plus offset: CGFloat = 0) -> NSLayoutConstraint {
guard let superview = target.superview else {
preconditionFailure("The layout target must have a superview before making constraints on it.")
preconditionFailure(
"The layout target must have a superview before making constraints on it."
)
}
return lessThanOrEqual(to: superview, plus: offset)
}
Expand All @@ -131,7 +141,9 @@ extension BaselineAnchor {
/// - Returns: An `NSLayoutConstraint` object that represents `self` baseline >= `superview` baseline + `offset`.
public func greaterThanOrEqualToSuperview(plus offset: CGFloat = 0) -> NSLayoutConstraint {
guard let superview = target.superview else {
preconditionFailure("The layout target must have a superview before making constraints on it.")
preconditionFailure(
"The layout target must have a superview before making constraints on it."
)
}
return greaterThanOrEqual(to: superview, plus: offset)
}
Expand Down
100 changes: 72 additions & 28 deletions Sources/AceLayout/LayoutAnchors/LayoutAnchor+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ extension LayoutAnchor where BaseLayoutAnchor == NSLayoutXAxisAnchor {

/// Returns a constraint of the form `self` x == `anotherAnchor` + systemSpacing \* `multiplier`.
///
/// The constraint causes the current anchor to trail the object in the `anotherAnchor` parameter. For example, in a left-to-right layout, the current anchor is to the right of `anotherAnchor`, but in a right-to-left layout, it is to the left of `anotherAnchor`.
/// The constraint causes the current anchor to trail the object in the `anotherAnchor` parameter.
/// For example, in a left-to-right layout, the current anchor is to the right of `anotherAnchor`, but in a right-to-left layout,
/// it is to the left of `anotherAnchor`.
///
/// The distance between the two anchors is determined by multiplying the system spacing by the value in the `multiplier` parameter. The value of the system space is determined from information available from the anchors.
/// The distance between the two anchors is determined by multiplying the system spacing by the value in the `multiplier` parameter.
/// The value of the system space is determined from information available from the anchors.
///
/// ```
/// view.autoLayout { item in
Expand All @@ -35,16 +38,22 @@ extension LayoutAnchor where BaseLayoutAnchor == NSLayoutXAxisAnchor {
/// - multiplier: The multiple of the system spacing to use as the distance between the two anchors. The default value is `1`.
/// - Returns: An `NSLayoutConstraint` object that represents `self` x == `anotherAnchor` + systemSpacing \* `multiplier`.
@inlinable
public func equal(toSystemSpacingAfter anotherAnchor: BaseLayoutAnchor,
multipliedBy multiplier: CGFloat = 1) -> NSLayoutConstraint {
public func equal(
toSystemSpacingAfter anotherAnchor: BaseLayoutAnchor,
multipliedBy multiplier: CGFloat = 1
) -> NSLayoutConstraint {
anchor.constraint(equalToSystemSpacingAfter: anotherAnchor, multiplier: multiplier)
}

/// Returns a constraint of the form `self` x <= `anotherAnchor` + systemSpacing \* `multiplier`.
///
/// The constraint causes the current anchor to trail the object in the `anotherAnchor` parameter. For example, in a left-to-right layout, the current anchor is to the right of `anotherAnchor`, but in a right-to-left layout, it is to the left of `anotherAnchor`.
/// The constraint causes the current anchor to trail the object in the `anotherAnchor` parameter.
/// For example, in a left-to-right layout, the current anchor is to the right of `anotherAnchor`, but in a right-to-left layout,
/// it is to the left of `anotherAnchor`.
///
/// The maximum distance between the two anchors is determined by multiplying the system spacing by the value in the `multiplier` parameter. (The actual distance must be less than or equal to that value.) The value of the system space is determined from information available from the anchors.
/// The maximum distance between the two anchors is determined by multiplying the system spacing by the value in the `multiplier` parameter.
/// (The actual distance must be less than or equal to that value.)
/// The value of the system space is determined from information available from the anchors.
///
/// ```
/// view.autoLayout { item in
Expand All @@ -61,16 +70,25 @@ extension LayoutAnchor where BaseLayoutAnchor == NSLayoutXAxisAnchor {
/// - multiplier: The multiple of the system spacing to use as the maximum distance between the two anchors. The default value is `1`.
/// - Returns: An `NSLayoutConstraint` object that represents `self` x <= `anotherAnchor` + systemSpacing \* `multiplier`.
@inlinable
public func lessThanOrEqual(toSystemSpacingAfter anotherAnchor: BaseLayoutAnchor,
multipliedBy multiplier: CGFloat = 1) -> NSLayoutConstraint {
anchor.constraint(lessThanOrEqualToSystemSpacingAfter: anotherAnchor, multiplier: multiplier)
public func lessThanOrEqual(
toSystemSpacingAfter anotherAnchor: BaseLayoutAnchor,
multipliedBy multiplier: CGFloat = 1
) -> NSLayoutConstraint {
anchor.constraint(
lessThanOrEqualToSystemSpacingAfter: anotherAnchor,
multiplier: multiplier
)
}

/// Returns a constraint of the form `self` x >= `anotherAnchor` + systemSpacing \* `multiplier`.
///
/// The constraint causes the current anchor to trail the object in the `anotherAnchor` parameter. For example, in a left-to-right layout, the current anchor is to the right of `anotherAnchor`, but in a right-to-left layout, it is to the left of `anotherAnchor`.
/// The constraint causes the current anchor to trail the object in the `anotherAnchor` parameter.
/// For example, in a left-to-right layout, the current anchor is to the right of `anotherAnchor`, but in a right-to-left layout,
/// it is to the left of `anotherAnchor`.
///
/// The minimum distance between the two anchors is determined by multiplying the system spacing by the value in the `multiplier` parameter. (The actual distance must be greater than or equal to that value.) The value of the system space is determined from information available from the anchors.
/// The minimum distance between the two anchors is determined by multiplying the system spacing by the value in the `multiplier` parameter.
/// (The actual distance must be greater than or equal to that value.)
/// The value of the system space is determined from information available from the anchors.
///
/// ```
/// view.autoLayout { item in
Expand All @@ -84,12 +102,18 @@ extension LayoutAnchor where BaseLayoutAnchor == NSLayoutXAxisAnchor {
///
/// - Parameters:
/// - anotherAnchor: The X axis anchor to use as the starting point for the constraint.
/// - multiplier: The multiple of the system spacing to use as the minimum distance between the two anchors. The default value is `1`.
/// - multiplier: The multiple of the system spacing to use as the minimum distance between the two anchors.
/// The default value is `1`.
/// - Returns: An `NSLayoutConstraint` object that represents `self` x >= `anotherAnchor` + systemSpacing \* `multiplier`.
@inlinable
public func greaterThanOrEqual(toSystemSpacingAfter anotherAnchor: BaseLayoutAnchor,
multipliedBy multiplier: CGFloat = 1) -> NSLayoutConstraint {
anchor.constraint(greaterThanOrEqualToSystemSpacingAfter: anotherAnchor, multiplier: multiplier)
public func greaterThanOrEqual(
toSystemSpacingAfter anotherAnchor: BaseLayoutAnchor,
multipliedBy multiplier: CGFloat = 1
) -> NSLayoutConstraint {
anchor.constraint(
greaterThanOrEqualToSystemSpacingAfter: anotherAnchor,
multiplier: multiplier
)
}
}

Expand All @@ -100,7 +124,9 @@ extension LayoutAnchor where BaseLayoutAnchor == NSLayoutYAxisAnchor {
///
/// The constraint causes the current anchor to be positioned below the object in the `anotherAnchor` parameter.
///
/// The distance between the two anchors is determined by multiplying the system spacing by the value in the `multiplier` parameter. The value of the system spacing is determined from information available from the anchors. For example, if the anchors represent text baselines, the spacing is determined by the fonts used at those baselines.
/// The distance between the two anchors is determined by multiplying the system spacing by the value in the `multiplier` parameter.
/// The value of the system spacing is determined from information available from the anchors.
/// For example, if the anchors represent text baselines, the spacing is determined by the fonts used at those baselines.
///
/// ```
/// view.autoLayout { item in
Expand All @@ -114,19 +140,24 @@ extension LayoutAnchor where BaseLayoutAnchor == NSLayoutYAxisAnchor {
///
/// - Parameters:
/// - anotherAnchor: The Y axis anchor to use as the starting point for the constraint.
/// - multiplier: The multiple of the system spacing to use as the distance between the two anchors. The default value is `1`.
/// - multiplier: The multiple of the system spacing to use as the distance between the two anchors.
/// The default value is `1`.
/// - Returns: An `NSLayoutConstraint` object that represents `self` y == `anotherAnchor` + systemSpacing \* `multiplier`.
@inlinable
public func equal(toSystemSpacingBelow anotherAnchor: BaseLayoutAnchor,
multipliedBy multiplier: CGFloat = 1) -> NSLayoutConstraint {
public func equal(
toSystemSpacingBelow anotherAnchor: BaseLayoutAnchor,
multipliedBy multiplier: CGFloat = 1
) -> NSLayoutConstraint {
anchor.constraint(equalToSystemSpacingBelow: anotherAnchor, multiplier: multiplier)
}

/// Returns a constraint of the form `self` y <= `anotherAnchor` + systemSpacing \* `multiplier`.
///
/// The constraint causes the current anchor to be positioned below the object in the `anotherAnchor` parameter.
///
/// The maximum distance between the two anchors is determined by multiplying the system spacing by the value in the `multiplier` parameter. The value of the system spacing is determined from information available from the anchors. For example, if the anchors represent text baselines, the spacing is determined by the fonts used at those baselines.
/// The maximum distance between the two anchors is determined by multiplying the system spacing by the value in the `multiplier` parameter.
/// The value of the system spacing is determined from information available from the anchors.
/// For example, if the anchors represent text baselines, the spacing is determined by the fonts used at those baselines.
///
/// ```
/// view.autoLayout { item in
Expand All @@ -140,19 +171,27 @@ extension LayoutAnchor where BaseLayoutAnchor == NSLayoutYAxisAnchor {
///
/// - Parameters:
/// - anotherAnchor: The Y axis anchor to use as the starting point for the constraint.
/// - multiplier: The multiple of the system spacing to use as the distance between the two anchors. The default value is `1`.
/// - multiplier: The multiple of the system spacing to use as the distance between the two anchors.
/// The default value is `1`.
/// - Returns: An `NSLayoutConstraint` object that represents `self` y <= `anotherAnchor` + systemSpacing \* `multiplier`.
@inlinable
public func lessThanOrEqual(toSystemSpacingBelow anotherAnchor: BaseLayoutAnchor,
multipliedBy multiplier: CGFloat = 1) -> NSLayoutConstraint {
anchor.constraint(lessThanOrEqualToSystemSpacingBelow: anotherAnchor, multiplier: multiplier)
public func lessThanOrEqual(
toSystemSpacingBelow anotherAnchor: BaseLayoutAnchor,
multipliedBy multiplier: CGFloat = 1
) -> NSLayoutConstraint {
anchor.constraint(
lessThanOrEqualToSystemSpacingBelow: anotherAnchor,
multiplier: multiplier
)
}

/// Returns a constraint of the form `self` y >= `anotherAnchor` + systemSpacing \* `multiplier`.
///
/// The constraint causes the current anchor to be positioned below the object in the `anotherAnchor` parameter.
///
/// The minimum distance between the two anchors is determined by multiplying the system spacing by the value in the `multiplier` parameter. The value of the system spacing is determined from information available from the anchors. For example, if the anchors represent text baselines, the spacing is determined by the fonts used at those baselines.
/// The minimum distance between the two anchors is determined by multiplying the system spacing by the value in the `multiplier` parameter.
/// The value of the system spacing is determined from information available from the anchors.
/// For example, if the anchors represent text baselines, the spacing is determined by the fonts used at those baselines.
///
/// ```
/// view.autoLayout { item in
Expand All @@ -169,8 +208,13 @@ extension LayoutAnchor where BaseLayoutAnchor == NSLayoutYAxisAnchor {
/// - multiplier: The multiple of the system spacing to use as the distance between the two anchors. The default value is `1`.
/// - Returns: An `NSLayoutConstraint` object that represents `self` y >= `anotherAnchor` + systemSpacing \* `multiplier`.
@inlinable
public func greaterThanOrEqual(toSystemSpacingBelow anotherAnchor: BaseLayoutAnchor,
multipliedBy multiplier: CGFloat = 1) -> NSLayoutConstraint {
anchor.constraint(greaterThanOrEqualToSystemSpacingBelow: anotherAnchor, multiplier: multiplier)
public func greaterThanOrEqual(
toSystemSpacingBelow anotherAnchor: BaseLayoutAnchor,
multipliedBy multiplier: CGFloat = 1
) -> NSLayoutConstraint {
anchor.constraint(
greaterThanOrEqualToSystemSpacingBelow: anotherAnchor,
multiplier: multiplier
)
}
}

0 comments on commit da5bdac

Please sign in to comment.