Skip to content

Commit

Permalink
Updates to offset operator to work with axis-specific Edge types
Browse files Browse the repository at this point in the history
  • Loading branch information
jayrhynas committed Apr 27, 2023
1 parent c1e194b commit de0452d
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Cartography/Edge+OffsetOperator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@ precedencegroup OffsetPrecedence {
infix operator |-|: OffsetPrecedence

@available(iOS 10.0, macOS 10.12, tvOS 10.0, *)
extension Edge {
public static func |-|(lhs: Edge, rhs: Edge) -> Dimension {
if let first = lhs.xAnchor, let second = rhs.xAnchor {
return Dimension(lhs.context, first.anchorWithOffset(to: second))
} else if let first = lhs.yAnchor, let second = rhs.yAnchor {
extension EdgeXAxis {
public static func |-|(lhs: EdgeXAxis, rhs: EdgeXAxis) -> Dimension {
if let first = lhs.anchor, let second = rhs.anchor {
return Dimension(lhs.context, first.anchorWithOffset(to: second))
} else {
return Dimension(lhs.context, lhs.item, .notAnAttribute)
}
}

internal var xAnchor: NSLayoutXAxisAnchor? {
internal var anchor: NSLayoutXAxisAnchor? {
if attribute == .left, let item = item as? SupportsLeftAnchor {
return item.leftAnchor
}
Expand All @@ -53,8 +51,19 @@ extension Edge {
return nil
}
}

internal var yAnchor: NSLayoutYAxisAnchor? {
}

@available(iOS 10.0, macOS 10.12, tvOS 10.0, *)
extension EdgeYAxis {
public static func |-|(lhs: EdgeYAxis, rhs: EdgeYAxis) -> Dimension {
if let first = lhs.anchor, let second = rhs.anchor {
return Dimension(lhs.context, first.anchorWithOffset(to: second))
} else {
return Dimension(lhs.context, lhs.item, .notAnAttribute)
}
}

internal var anchor: NSLayoutYAxisAnchor? {
if attribute == .top, let item = item as? SupportsTopAnchor {
return item.topAnchor
}
Expand Down

0 comments on commit de0452d

Please sign in to comment.