mirror of https://github.com/SnapKit/SnapKit
Added better offset/constant maths
This commit is contained in:
parent
8f70c8290a
commit
03ba3d603e
|
@ -586,27 +586,51 @@ private extension NSLayoutAttribute {
|
||||||
}
|
}
|
||||||
// CGPoint
|
// CGPoint
|
||||||
else if let point = value as? CGPoint {
|
else if let point = value as? CGPoint {
|
||||||
if self == .Left || self == .CenterX {
|
#if os(iOS)
|
||||||
return point.x
|
switch self {
|
||||||
} else if self == .Top || self == .CenterY {
|
case .Left, .CenterX, .LeftMargin, .CenterXWithinMargins: return point.x
|
||||||
return point.y
|
case .Top, .CenterY, .TopMargin, .CenterYWithinMargins, .Baseline, .FirstBaseline: return point.y
|
||||||
} else if self == .Right {
|
case .Right, .RightMargin: return -point.x
|
||||||
return -point.x
|
case .Bottom, .BottomMargin: return -point.y
|
||||||
} else if self == .Bottom {
|
case .Leading, .LeadingMargin: return (Config.interfaceLayoutDirection == .LeftToRight) ? point.x : -point.x
|
||||||
return -point.y
|
case .Trailing, .TrailingMargin: return (Config.interfaceLayoutDirection == .LeftToRight) ? -point.x : point.x
|
||||||
|
case .Width, .Height, .NotAnAttribute: return CGFloat(0)
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
switch self {
|
||||||
|
case .Left, .CenterX: return point.x
|
||||||
|
case .Top, .CenterY, .Baseline: return point.y
|
||||||
|
case .Right: return -point.x
|
||||||
|
case .Bottom: return -point.y
|
||||||
|
case .Leading: return (Config.interfaceLayoutDirection == .LeftToRight) ? point.x : -point.x
|
||||||
|
case .Trailing: return (Config.interfaceLayoutDirection == .LeftToRight) ? -point.x : point.x
|
||||||
|
case .Width, .Height, .NotAnAttribute: return CGFloat(0)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
// EdgeInsets
|
// EdgeInsets
|
||||||
else if let insets = value as? EdgeInsets {
|
else if let insets = value as? EdgeInsets {
|
||||||
if self == .Left {
|
#if os(iOS)
|
||||||
return insets.left
|
switch self {
|
||||||
} else if self == .Top {
|
case .Left, .CenterX, .LeftMargin, .CenterXWithinMargins: return insets.left
|
||||||
return insets.top
|
case .Top, .CenterY, .TopMargin, .CenterYWithinMargins, .Baseline, .FirstBaseline: return insets.top
|
||||||
} else if self == .Right {
|
case .Right, .RightMargin: return -insets.right
|
||||||
return -insets.right
|
case .Bottom, .BottomMargin: return -insets.bottom
|
||||||
} else if self == .Bottom {
|
case .Leading, .LeadingMargin: return (Config.interfaceLayoutDirection == .LeftToRight) ? insets.left : -insets.right
|
||||||
return -insets.bottom
|
case .Trailing, .TrailingMargin: return (Config.interfaceLayoutDirection == .LeftToRight) ? -insets.right : insets.left
|
||||||
|
case .Width, .Height, .NotAnAttribute: return CGFloat(0)
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
switch self {
|
||||||
|
case .Left, .CenterX: return insets.left
|
||||||
|
case .Top, .CenterY, .Baseline: return insets.top
|
||||||
|
case .Right: return -insets.right
|
||||||
|
case .Bottom: return -insets.bottom
|
||||||
|
case .Leading: return (Config.interfaceLayoutDirection == .LeftToRight) ? insets.left : -insets.right
|
||||||
|
case .Trailing: return (Config.interfaceLayoutDirection == .LeftToRight) ? -insets.right : insets.left
|
||||||
|
case .Width, .Height, .NotAnAttribute: return CGFloat(0)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return CGFloat(0)
|
return CGFloat(0)
|
||||||
|
@ -643,27 +667,51 @@ private extension NSLayoutAttribute {
|
||||||
}
|
}
|
||||||
// CGPoint
|
// CGPoint
|
||||||
else if let point = value as? CGPoint {
|
else if let point = value as? CGPoint {
|
||||||
if self == .Left || self == .CenterX {
|
#if os(iOS)
|
||||||
return point.x
|
switch self {
|
||||||
} else if self == .Top || self == .CenterY {
|
case .Left, .CenterX, .LeftMargin, .CenterXWithinMargins: return point.x
|
||||||
return point.y
|
case .Top, .CenterY, .TopMargin, .CenterYWithinMargins, .Baseline, .FirstBaseline: return point.y
|
||||||
} else if self == .Right {
|
case .Right, .RightMargin: return -point.x
|
||||||
return point.x
|
case .Bottom, .BottomMargin: return -point.y
|
||||||
} else if self == .Bottom {
|
case .Leading, .LeadingMargin: return (Config.interfaceLayoutDirection == .LeftToRight) ? point.x : -point.x
|
||||||
return point.y
|
case .Trailing, .TrailingMargin: return (Config.interfaceLayoutDirection == .LeftToRight) ? -point.x : point.x
|
||||||
|
case .Width, .Height, .NotAnAttribute: return CGFloat(0)
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
switch self {
|
||||||
|
case .Left, .CenterX: return point.x
|
||||||
|
case .Top, .CenterY, .Baseline: return point.y
|
||||||
|
case .Right: return -point.x
|
||||||
|
case .Bottom: return -point.y
|
||||||
|
case .Leading: return (Config.interfaceLayoutDirection == .LeftToRight) ? point.x : -point.x
|
||||||
|
case .Trailing: return (Config.interfaceLayoutDirection == .LeftToRight) ? -point.x : point.x
|
||||||
|
case .Width, .Height, .NotAnAttribute: return CGFloat(0)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
// EdgeInsets
|
// EdgeInsets
|
||||||
else if let insets = value as? EdgeInsets {
|
else if let insets = value as? EdgeInsets {
|
||||||
if self == .Left {
|
#if os(iOS)
|
||||||
return insets.left
|
switch self {
|
||||||
} else if self == .Top {
|
case .Left, .CenterX, .LeftMargin, .CenterXWithinMargins: return insets.left
|
||||||
return insets.top
|
case .Top, .CenterY, .TopMargin, .CenterYWithinMargins, .Baseline, .FirstBaseline: return insets.top
|
||||||
} else if self == .Right {
|
case .Right, .RightMargin: return -insets.right
|
||||||
return -insets.right
|
case .Bottom, .BottomMargin: return -insets.bottom
|
||||||
} else if self == .Bottom {
|
case .Leading, .LeadingMargin: return (Config.interfaceLayoutDirection == .LeftToRight) ? insets.left : -insets.right
|
||||||
return -insets.bottom
|
case .Trailing, .TrailingMargin: return (Config.interfaceLayoutDirection == .LeftToRight) ? -insets.right : insets.left
|
||||||
|
case .Width, .Height, .NotAnAttribute: return CGFloat(0)
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
switch self {
|
||||||
|
case .Left, .CenterX: return insets.left
|
||||||
|
case .Top, .CenterY, .Baseline: return insets.top
|
||||||
|
case .Right: return -insets.right
|
||||||
|
case .Bottom: return -insets.bottom
|
||||||
|
case .Leading: return (Config.interfaceLayoutDirection == .LeftToRight) ? insets.left : -insets.right
|
||||||
|
case .Trailing: return (Config.interfaceLayoutDirection == .LeftToRight) ? -insets.right : insets.left
|
||||||
|
case .Width, .Height, .NotAnAttribute: return CGFloat(0)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return CGFloat(0);
|
return CGFloat(0);
|
||||||
|
|
Loading…
Reference in New Issue