This commit is contained in:
Robert Payne 2015-11-08 21:18:01 +13:00
parent fdcc715085
commit 2dcf3bddfa
5 changed files with 59 additions and 64 deletions

View File

@ -7,8 +7,8 @@
objects = {
/* Begin PBXBuildFile section */
779230441BCB6FC30027CF5F /* SourceLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779230431BCB6FC30027CF5F /* SourceLocation.swift */; settings = {ASSET_TAGS = (); }; };
779230451BCB6FC30027CF5F /* SourceLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779230431BCB6FC30027CF5F /* SourceLocation.swift */; settings = {ASSET_TAGS = (); }; };
779230441BCB6FC30027CF5F /* SourceLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779230431BCB6FC30027CF5F /* SourceLocation.swift */; };
779230451BCB6FC30027CF5F /* SourceLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779230431BCB6FC30027CF5F /* SourceLocation.swift */; };
EE4910981B19A26000A54F1F /* ViewController+SnapKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4910971B19A26000A54F1F /* ViewController+SnapKit.swift */; };
EE4910991B19A40200A54F1F /* SnapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EEBCC9D819CC627D0083B827 /* SnapKit.framework */; };
EE94F6091AC0F10A008767FF /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EE94F6081AC0F10A008767FF /* UIKit.framework */; };

View File

@ -60,7 +60,7 @@ public class Constraint {
internal var makerLocation: SourceLocation = SourceLocation(file: "Unknown", line: 0)
internal(set) public var location : SourceLocation?
internal(set) public var location: SourceLocation?
}
/**
@ -195,7 +195,7 @@ internal class ConcreteConstraint: Constraint {
private var installInfo: ConcreteConstraintInstallInfo? = nil
internal init(fromItem: ConstraintItem, toItem: ConstraintItem, relation: ConstraintRelation, constant: Any, multiplier: Float, priority: Float, location : SourceLocation?) {
internal init(fromItem: ConstraintItem, toItem: ConstraintItem, relation: ConstraintRelation, constant: Any, multiplier: Float, priority: Float, location: SourceLocation?) {
self.fromItem = fromItem
self.toItem = toItem
self.relation = relation

View File

@ -27,87 +27,83 @@ import UIKit
import AppKit
#endif
// Type of object that can be a target of relation constraint.
// Doesn't cover system protocols which can't be extended with additional conformances.
public protocol RelationTarget {
var constraintItem : ConstraintItem { get }
var constraintItem: ConstraintItem { get }
}
// Type of things that can be converted to floats. Used to provide a catch all for
// different numeric types.
public protocol FloatConvertible : RelationTarget {
var floatValue : Float { get }
public protocol FloatConvertible: RelationTarget {
var floatValue: Float { get }
}
extension FloatConvertible {
public var constraintItem : ConstraintItem {
public var constraintItem: ConstraintItem {
return ConstraintItem(object: nil, attributes: ConstraintAttributes.None)
}
}
extension Float : FloatConvertible, RelationTarget {
public var floatValue : Float {
extension Float: FloatConvertible, RelationTarget {
public var floatValue: Float {
return self
}
}
extension Int : FloatConvertible, RelationTarget {
public var floatValue : Float {
extension Int: FloatConvertible, RelationTarget {
public var floatValue: Float {
return Float(self)
}
}
extension UInt : FloatConvertible, RelationTarget {
public var floatValue : Float {
extension UInt: FloatConvertible, RelationTarget {
public var floatValue: Float {
return Float(self)
}
}
extension Double : FloatConvertible, RelationTarget {
public var floatValue : Float {
extension Double: FloatConvertible, RelationTarget {
public var floatValue: Float {
return Float(self)
}
}
extension CGFloat : FloatConvertible, RelationTarget {
public var floatValue : Float {
extension CGFloat: FloatConvertible, RelationTarget {
public var floatValue: Float {
return Float(self)
}
}
@available(iOS 9.0, OSX 10.11, *)
extension NSLayoutAnchor : RelationTarget {
public var constraintItem : ConstraintItem {
extension NSLayoutAnchor: RelationTarget {
public var constraintItem: ConstraintItem {
return ConstraintItem(object: self, attributes: ConstraintAttributes.None)
}
}
extension CGPoint : RelationTarget {
public var constraintItem : ConstraintItem {
extension CGPoint: RelationTarget {
public var constraintItem: ConstraintItem {
return ConstraintItem(object: nil, attributes: ConstraintAttributes.None)
}
}
extension CGSize : RelationTarget {
public var constraintItem : ConstraintItem {
extension CGSize: RelationTarget {
public var constraintItem: ConstraintItem {
return ConstraintItem(object: nil, attributes: ConstraintAttributes.None)
}
}
extension EdgeInsets : RelationTarget {
public var constraintItem : ConstraintItem {
extension EdgeInsets: RelationTarget {
public var constraintItem: ConstraintItem {
return ConstraintItem(object: nil, attributes: ConstraintAttributes.None)
}
}
extension View : RelationTarget {
public var constraintItem : ConstraintItem {
extension View: RelationTarget {
public var constraintItem: ConstraintItem {
return ConstraintItem(object: self, attributes: ConstraintAttributes.None)
}
}
extension ConstraintItem : RelationTarget {
public var constraintItem : ConstraintItem {
extension ConstraintItem: RelationTarget {
public var constraintItem: ConstraintItem {
return self
}
}
@ -117,9 +113,9 @@ extension ConstraintItem : RelationTarget {
*/
public class ConstraintDescriptionFinalizable {
private let backing : ConstraintDescription
private let backing: ConstraintDescription
internal init(_ backing : ConstraintDescription) {
internal init(_ backing: ConstraintDescription) {
self.backing = backing
}
@ -164,7 +160,7 @@ public class ConstraintDescriptionEditable: ConstraintDescriptionPriortizable {
return self.multipliedBy(1 / amount.floatValue)
}
public func offset(amount : FloatConvertible) -> ConstraintDescriptionEditable {
public func offset(amount: FloatConvertible) -> ConstraintDescriptionEditable {
return ConstraintDescriptionEditable(self.backing.offset(amount))
}
public func offset(amount: CGPoint) -> ConstraintDescriptionEditable {
@ -190,38 +186,37 @@ public class ConstraintDescriptionEditable: ConstraintDescriptionPriortizable {
*/
public class ConstraintDescriptionRelatable {
private let backing : ConstraintDescription
private let backing: ConstraintDescription
init(_ backing : ConstraintDescription) {
init(_ backing: ConstraintDescription) {
self.backing = backing
}
public func equalTo(other: RelationTarget, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable {
public func equalTo(other: RelationTarget, file: String = __FILE__, line: UInt = __LINE__) -> ConstraintDescriptionEditable {
let location = SourceLocation(file: file, line: line)
return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .Equal, location: location))
return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .Equal, location: location))
}
public func equalTo(other: LayoutSupport, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable {
public func equalTo(other: LayoutSupport, file: String = __FILE__, line: UInt = __LINE__) -> ConstraintDescriptionEditable {
let location = SourceLocation(file: file, line: line)
return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .Equal, location: location))
return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .Equal, location: location))
}
public func lessThanOrEqualTo(other: RelationTarget, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable {
public func lessThanOrEqualTo(other: RelationTarget, file: String = __FILE__, line: UInt = __LINE__) -> ConstraintDescriptionEditable {
let location = SourceLocation(file: file, line: line)
return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .LessThanOrEqualTo, location: location))
return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .LessThanOrEqualTo, location: location))
}
public func lessThanOrEqualTo(other: LayoutSupport, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable {
public func lessThanOrEqualTo(other: LayoutSupport, file: String = __FILE__, line: UInt = __LINE__) -> ConstraintDescriptionEditable {
let location = SourceLocation(file: file, line: line)
return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .LessThanOrEqualTo, location: location))
return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .LessThanOrEqualTo, location: location))
}
public func greaterThanOrEqualTo(other: RelationTarget, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable {
public func greaterThanOrEqualTo(other: RelationTarget, file: String = __FILE__, line: UInt = __LINE__) -> ConstraintDescriptionEditable {
let location = SourceLocation(file: file, line: line)
return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .GreaterThanOrEqualTo, location: location))
return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .GreaterThanOrEqualTo, location: location))
}
public func greaterThanOrEqualTo(other: LayoutSupport, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable {
public func greaterThanOrEqualTo(other: LayoutSupport, file: String = __FILE__, line: UInt = __LINE__) -> ConstraintDescriptionEditable {
let location = SourceLocation(file: file, line: line)
return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .GreaterThanOrEqualTo, location: location))
return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation: .GreaterThanOrEqualTo, location: location))
}
}
@ -307,7 +302,7 @@ public class ConstraintDescriptionExtendable: ConstraintDescriptionRelatable {
*/
internal class ConstraintDescription {
private var location : SourceLocation?
private var location: SourceLocation? = nil
private var left: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Left) }
private var top: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Top) }
@ -480,7 +475,7 @@ internal class ConstraintDescription {
return self
}
private func constrainTo(other: RelationTarget, relation: ConstraintRelation, location : SourceLocation) -> ConstraintDescription {
private func constrainTo(other: RelationTarget, relation: ConstraintRelation, location: SourceLocation) -> ConstraintDescription {
self.location = location
@ -507,7 +502,7 @@ internal class ConstraintDescription {
}
@available(iOS 7.0, *)
private func constrainTo(other: LayoutSupport, relation: ConstraintRelation, location : SourceLocation) -> ConstraintDescription {
private func constrainTo(other: LayoutSupport, relation: ConstraintRelation, location: SourceLocation) -> ConstraintDescription {
return constrainTo(ConstraintItem(object: other, attributes: ConstraintAttributes.None), relation: relation, location: location)
}

View File

@ -135,7 +135,7 @@ public class ConstraintMaker {
}
internal class func prepareConstraints(view view: View, location: SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] {
let maker = ConstraintMaker(view: view, location : location)
let maker = ConstraintMaker(view: view, location: location)
closure(make: maker)
let constraints = maker.constraintDescriptions.map { $0.constraint }
@ -157,7 +157,7 @@ public class ConstraintMaker {
}
}
internal class func remakeConstraints(view view: View, location : SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) {
internal class func remakeConstraints(view view: View, location: SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) {
view.translatesAutoresizingMaskIntoConstraints = false
let maker = ConstraintMaker(view: view, location: location)
closure(make: maker)

View File

@ -23,10 +23,10 @@
public struct SourceLocation {
public let file : String
public let line : UInt
public let file: String
public let line: UInt
init(file : String, line : UInt) {
init(file: String, line: UInt) {
self.file = file
self.line = line
}