mirror of https://github.com/SnapKit/SnapKit
Increased primitives support
Added support for CGFloat, Double and UInt in addition to Float/Double. Note they all are typecast to a Float as that is what autolayout works with.
This commit is contained in:
parent
598835a2c7
commit
0a40ba4d78
|
@ -64,9 +64,18 @@ public class Constraint {
|
||||||
public func equalTo(other: Float) -> Constraint {
|
public func equalTo(other: Float) -> Constraint {
|
||||||
return constrainTo(other, relation: .Equal)
|
return constrainTo(other, relation: .Equal)
|
||||||
}
|
}
|
||||||
|
public func equalTo(other: Double) -> Constraint {
|
||||||
|
return constrainTo(Float(other), relation: .Equal)
|
||||||
|
}
|
||||||
|
public func equalTo(other: CGFloat) -> Constraint {
|
||||||
|
return constrainTo(Float(other), relation: .Equal)
|
||||||
|
}
|
||||||
public func equalTo(other: Int) -> Constraint {
|
public func equalTo(other: Int) -> Constraint {
|
||||||
return constrainTo(Float(other), relation: .Equal)
|
return constrainTo(Float(other), relation: .Equal)
|
||||||
}
|
}
|
||||||
|
public func equalTo(other: UInt) -> Constraint {
|
||||||
|
return constrainTo(Float(other), relation: .Equal)
|
||||||
|
}
|
||||||
public func equalTo(other: CGSize) -> Constraint {
|
public func equalTo(other: CGSize) -> Constraint {
|
||||||
return constrainTo(other, relation: .Equal)
|
return constrainTo(other, relation: .Equal)
|
||||||
}
|
}
|
||||||
|
@ -88,9 +97,18 @@ public class Constraint {
|
||||||
public func lessThanOrEqualTo(other: Float) -> Constraint {
|
public func lessThanOrEqualTo(other: Float) -> Constraint {
|
||||||
return constrainTo(other, relation: .LessThanOrEqualTo)
|
return constrainTo(other, relation: .LessThanOrEqualTo)
|
||||||
}
|
}
|
||||||
|
public func lessThanOrEqualTo(other: Double) -> Constraint {
|
||||||
|
return constrainTo(Float(other), relation: .LessThanOrEqualTo)
|
||||||
|
}
|
||||||
|
public func lessThanOrEqualTo(other: CGFloat) -> Constraint {
|
||||||
|
return constrainTo(Float(other), relation: .LessThanOrEqualTo)
|
||||||
|
}
|
||||||
public func lessThanOrEqualTo(other: Int) -> Constraint {
|
public func lessThanOrEqualTo(other: Int) -> Constraint {
|
||||||
return constrainTo(Float(other), relation: .LessThanOrEqualTo)
|
return constrainTo(Float(other), relation: .LessThanOrEqualTo)
|
||||||
}
|
}
|
||||||
|
public func lessThanOrEqualTo(other: UInt) -> Constraint {
|
||||||
|
return constrainTo(Float(other), relation: .LessThanOrEqualTo)
|
||||||
|
}
|
||||||
public func lessThanOrEqualTo(other: CGSize) -> Constraint {
|
public func lessThanOrEqualTo(other: CGSize) -> Constraint {
|
||||||
return constrainTo(other, relation: .LessThanOrEqualTo)
|
return constrainTo(other, relation: .LessThanOrEqualTo)
|
||||||
}
|
}
|
||||||
|
@ -112,9 +130,18 @@ public class Constraint {
|
||||||
public func greaterThanOrEqualTo(other: Float) -> Constraint {
|
public func greaterThanOrEqualTo(other: Float) -> Constraint {
|
||||||
return constrainTo(other, relation: .GreaterThanOrEqualTo)
|
return constrainTo(other, relation: .GreaterThanOrEqualTo)
|
||||||
}
|
}
|
||||||
|
public func greaterThanOrEqualTo(other: Double) -> Constraint {
|
||||||
|
return constrainTo(Float(other), relation: .GreaterThanOrEqualTo)
|
||||||
|
}
|
||||||
|
public func greaterThanOrEqualTo(other: CGFloat) -> Constraint {
|
||||||
|
return constrainTo(Float(other), relation: .GreaterThanOrEqualTo)
|
||||||
|
}
|
||||||
public func greaterThanOrEqualTo(other: Int) -> Constraint {
|
public func greaterThanOrEqualTo(other: Int) -> Constraint {
|
||||||
return constrainTo(Float(other), relation: .GreaterThanOrEqualTo)
|
return constrainTo(Float(other), relation: .GreaterThanOrEqualTo)
|
||||||
}
|
}
|
||||||
|
public func greaterThanOrEqualTo(other: UInt) -> Constraint {
|
||||||
|
return constrainTo(Float(other), relation: .GreaterThanOrEqualTo)
|
||||||
|
}
|
||||||
public func greaterThanOrEqualTo(other: CGSize) -> Constraint {
|
public func greaterThanOrEqualTo(other: CGSize) -> Constraint {
|
||||||
return constrainTo(other, relation: .GreaterThanOrEqualTo)
|
return constrainTo(other, relation: .GreaterThanOrEqualTo)
|
||||||
}
|
}
|
||||||
|
@ -131,10 +158,35 @@ public class Constraint {
|
||||||
self.multiplier = amount
|
self.multiplier = amount
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
public func multipliedBy(amount: Double) -> Constraint {
|
||||||
|
return self.multipliedBy(Float(amount))
|
||||||
|
}
|
||||||
|
public func multipliedBy(amount: CGFloat) -> Constraint {
|
||||||
|
return self.multipliedBy(Float(amount))
|
||||||
|
}
|
||||||
|
public func multipliedBy(amount: Int) -> Constraint {
|
||||||
|
return self.multipliedBy(Float(amount))
|
||||||
|
}
|
||||||
|
public func multipliedBy(amount: UInt) -> Constraint {
|
||||||
|
return self.multipliedBy(Float(amount))
|
||||||
|
}
|
||||||
|
|
||||||
public func dividedBy(amount: Float) -> Constraint {
|
public func dividedBy(amount: Float) -> Constraint {
|
||||||
self.multiplier = 1.0 / amount;
|
self.multiplier = 1.0 / amount;
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
public func dividedBy(amount: Double) -> Constraint {
|
||||||
|
return self.dividedBy(Float(amount))
|
||||||
|
}
|
||||||
|
public func dividedBy(amount: CGFloat) -> Constraint {
|
||||||
|
return self.dividedBy(Float(amount))
|
||||||
|
}
|
||||||
|
public func dividedBy(amount: Int) -> Constraint {
|
||||||
|
return self.dividedBy(Float(amount))
|
||||||
|
}
|
||||||
|
public func dividedBy(amount: UInt) -> Constraint {
|
||||||
|
return self.dividedBy(Float(amount))
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: priority
|
// MARK: priority
|
||||||
|
|
||||||
|
@ -142,14 +194,26 @@ public class Constraint {
|
||||||
self.priority = priority
|
self.priority = priority
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
public func priority(priority: Double) -> Constraint {
|
||||||
|
return self.priority(Float(priority))
|
||||||
|
}
|
||||||
|
public func priority(priority: CGFloat) -> Constraint {
|
||||||
|
return self.priority(Float(priority))
|
||||||
|
}
|
||||||
|
public func priority(priority: UInt) -> Constraint {
|
||||||
|
return self.priority(Float(priority))
|
||||||
|
}
|
||||||
|
public func priority(priority: Int) -> Constraint {
|
||||||
|
return self.priority(Float(priority))
|
||||||
|
}
|
||||||
public func priorityRequired() -> Constraint {
|
public func priorityRequired() -> Constraint {
|
||||||
return priority(1000.0)
|
return self.priority(1000.0)
|
||||||
}
|
}
|
||||||
public func priorityHigh() -> Constraint {
|
public func priorityHigh() -> Constraint {
|
||||||
return priority(750.0)
|
return self.priority(750.0)
|
||||||
}
|
}
|
||||||
public func priorityLow() -> Constraint {
|
public func priorityLow() -> Constraint {
|
||||||
return priority(250.0)
|
return self.priority(250.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: offset
|
// MARK: offset
|
||||||
|
@ -158,9 +222,17 @@ public class Constraint {
|
||||||
self.offset = amount
|
self.offset = amount
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
public func offset(amount: Double) -> Constraint {
|
||||||
|
return self.offset(Float(amount))
|
||||||
|
}
|
||||||
|
public func offset(amount: CGFloat) -> Constraint {
|
||||||
|
return self.offset(Float(amount))
|
||||||
|
}
|
||||||
public func offset(amount: Int) -> Constraint {
|
public func offset(amount: Int) -> Constraint {
|
||||||
self.offset = amount
|
return self.offset(Float(amount))
|
||||||
return self
|
}
|
||||||
|
public func offset(amount: UInt) -> Constraint {
|
||||||
|
return self.offset(Float(amount))
|
||||||
}
|
}
|
||||||
public func offset(amount: CGPoint) -> Constraint {
|
public func offset(amount: CGPoint) -> Constraint {
|
||||||
self.offset = amount
|
self.offset = amount
|
||||||
|
@ -315,6 +387,10 @@ public class Constraint {
|
||||||
self.constant = other
|
self.constant = other
|
||||||
return constrainTo(ConstraintItem(view: nil, attributes: ConstraintAttributes.None), relation: relation)
|
return constrainTo(ConstraintItem(view: nil, attributes: ConstraintAttributes.None), relation: relation)
|
||||||
}
|
}
|
||||||
|
private func constrainTo(other: Double, relation: ConstraintRelation) -> Constraint {
|
||||||
|
self.constant = other
|
||||||
|
return constrainTo(ConstraintItem(view: nil, attributes: ConstraintAttributes.None), relation: relation)
|
||||||
|
}
|
||||||
private func constrainTo(other: CGSize, relation: ConstraintRelation) -> Constraint {
|
private func constrainTo(other: CGSize, relation: ConstraintRelation) -> Constraint {
|
||||||
self.constant = other
|
self.constant = other
|
||||||
return constrainTo(ConstraintItem(view: nil, attributes: ConstraintAttributes.None), relation: relation)
|
return constrainTo(ConstraintItem(view: nil, attributes: ConstraintAttributes.None), relation: relation)
|
||||||
|
@ -352,10 +428,18 @@ private extension NSLayoutAttribute {
|
||||||
if let float = value as? Float {
|
if let float = value as? Float {
|
||||||
return CGFloat(float)
|
return CGFloat(float)
|
||||||
}
|
}
|
||||||
// Int
|
// Double
|
||||||
|
else if let double = value as? Double {
|
||||||
|
return CGFloat(double)
|
||||||
|
}
|
||||||
|
// UInt
|
||||||
else if let int = value as? Int {
|
else if let int = value as? Int {
|
||||||
return CGFloat(int)
|
return CGFloat(int)
|
||||||
}
|
}
|
||||||
|
// Int
|
||||||
|
else if let uint = value as? UInt {
|
||||||
|
return CGFloat(uint)
|
||||||
|
}
|
||||||
// CGFloat
|
// CGFloat
|
||||||
else if let float = value as? CGFloat {
|
else if let float = value as? CGFloat {
|
||||||
return float
|
return float
|
||||||
|
@ -401,10 +485,18 @@ private extension NSLayoutAttribute {
|
||||||
if let float = value as? Float {
|
if let float = value as? Float {
|
||||||
return CGFloat(float)
|
return CGFloat(float)
|
||||||
}
|
}
|
||||||
// Int
|
// Double
|
||||||
|
else if let double = value as? Double {
|
||||||
|
return CGFloat(double)
|
||||||
|
}
|
||||||
|
// UInt
|
||||||
else if let int = value as? Int {
|
else if let int = value as? Int {
|
||||||
return CGFloat(int)
|
return CGFloat(int)
|
||||||
}
|
}
|
||||||
|
// Int
|
||||||
|
else if let uint = value as? UInt {
|
||||||
|
return CGFloat(uint)
|
||||||
|
}
|
||||||
// CGFloat
|
// CGFloat
|
||||||
else if let float = value as? CGFloat {
|
else if let float = value as? CGFloat {
|
||||||
return float
|
return float
|
||||||
|
|
Loading…
Reference in New Issue