mirror of https://github.com/SnapKit/SnapKit
nits
This commit is contained in:
parent
fdcc715085
commit
2dcf3bddfa
|
@ -7,8 +7,8 @@
|
||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
779230441BCB6FC30027CF5F /* 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 */; settings = {ASSET_TAGS = (); }; };
|
779230451BCB6FC30027CF5F /* SourceLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779230431BCB6FC30027CF5F /* SourceLocation.swift */; };
|
||||||
EE4910981B19A26000A54F1F /* ViewController+SnapKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4910971B19A26000A54F1F /* ViewController+SnapKit.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 */; };
|
EE4910991B19A40200A54F1F /* SnapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EEBCC9D819CC627D0083B827 /* SnapKit.framework */; };
|
||||||
EE94F6091AC0F10A008767FF /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EE94F6081AC0F10A008767FF /* UIKit.framework */; };
|
EE94F6091AC0F10A008767FF /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EE94F6081AC0F10A008767FF /* UIKit.framework */; };
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class Constraint {
|
||||||
|
|
||||||
internal var makerLocation: SourceLocation = SourceLocation(file: "Unknown", line: 0)
|
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
|
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.fromItem = fromItem
|
||||||
self.toItem = toItem
|
self.toItem = toItem
|
||||||
self.relation = relation
|
self.relation = relation
|
||||||
|
|
|
@ -27,87 +27,83 @@ import UIKit
|
||||||
import AppKit
|
import AppKit
|
||||||
#endif
|
#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 {
|
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
|
public protocol FloatConvertible: RelationTarget {
|
||||||
// different numeric types.
|
var floatValue: Float { get }
|
||||||
public protocol FloatConvertible : RelationTarget {
|
|
||||||
var floatValue : Float { get }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension FloatConvertible {
|
extension FloatConvertible {
|
||||||
public var constraintItem : ConstraintItem {
|
public var constraintItem: ConstraintItem {
|
||||||
return ConstraintItem(object: nil, attributes: ConstraintAttributes.None)
|
return ConstraintItem(object: nil, attributes: ConstraintAttributes.None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Float : FloatConvertible, RelationTarget {
|
extension Float: FloatConvertible, RelationTarget {
|
||||||
public var floatValue : Float {
|
public var floatValue: Float {
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Int : FloatConvertible, RelationTarget {
|
extension Int: FloatConvertible, RelationTarget {
|
||||||
public var floatValue : Float {
|
public var floatValue: Float {
|
||||||
return Float(self)
|
return Float(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension UInt : FloatConvertible, RelationTarget {
|
extension UInt: FloatConvertible, RelationTarget {
|
||||||
public var floatValue : Float {
|
public var floatValue: Float {
|
||||||
return Float(self)
|
return Float(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Double : FloatConvertible, RelationTarget {
|
extension Double: FloatConvertible, RelationTarget {
|
||||||
public var floatValue : Float {
|
public var floatValue: Float {
|
||||||
return Float(self)
|
return Float(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension CGFloat : FloatConvertible, RelationTarget {
|
extension CGFloat: FloatConvertible, RelationTarget {
|
||||||
public var floatValue : Float {
|
public var floatValue: Float {
|
||||||
return Float(self)
|
return Float(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(iOS 9.0, OSX 10.11, *)
|
@available(iOS 9.0, OSX 10.11, *)
|
||||||
extension NSLayoutAnchor : RelationTarget {
|
extension NSLayoutAnchor: RelationTarget {
|
||||||
public var constraintItem : ConstraintItem {
|
public var constraintItem: ConstraintItem {
|
||||||
return ConstraintItem(object: self, attributes: ConstraintAttributes.None)
|
return ConstraintItem(object: self, attributes: ConstraintAttributes.None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension CGPoint : RelationTarget {
|
extension CGPoint: RelationTarget {
|
||||||
public var constraintItem : ConstraintItem {
|
public var constraintItem: ConstraintItem {
|
||||||
return ConstraintItem(object: nil, attributes: ConstraintAttributes.None)
|
return ConstraintItem(object: nil, attributes: ConstraintAttributes.None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension CGSize : RelationTarget {
|
extension CGSize: RelationTarget {
|
||||||
public var constraintItem : ConstraintItem {
|
public var constraintItem: ConstraintItem {
|
||||||
return ConstraintItem(object: nil, attributes: ConstraintAttributes.None)
|
return ConstraintItem(object: nil, attributes: ConstraintAttributes.None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension EdgeInsets : RelationTarget {
|
extension EdgeInsets: RelationTarget {
|
||||||
public var constraintItem : ConstraintItem {
|
public var constraintItem: ConstraintItem {
|
||||||
return ConstraintItem(object: nil, attributes: ConstraintAttributes.None)
|
return ConstraintItem(object: nil, attributes: ConstraintAttributes.None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension View : RelationTarget {
|
extension View: RelationTarget {
|
||||||
public var constraintItem : ConstraintItem {
|
public var constraintItem: ConstraintItem {
|
||||||
return ConstraintItem(object: self, attributes: ConstraintAttributes.None)
|
return ConstraintItem(object: self, attributes: ConstraintAttributes.None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ConstraintItem : RelationTarget {
|
extension ConstraintItem: RelationTarget {
|
||||||
public var constraintItem : ConstraintItem {
|
public var constraintItem: ConstraintItem {
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,9 +113,9 @@ extension ConstraintItem : RelationTarget {
|
||||||
*/
|
*/
|
||||||
public class ConstraintDescriptionFinalizable {
|
public class ConstraintDescriptionFinalizable {
|
||||||
|
|
||||||
private let backing : ConstraintDescription
|
private let backing: ConstraintDescription
|
||||||
|
|
||||||
internal init(_ backing : ConstraintDescription) {
|
internal init(_ backing: ConstraintDescription) {
|
||||||
self.backing = backing
|
self.backing = backing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +160,7 @@ public class ConstraintDescriptionEditable: ConstraintDescriptionPriortizable {
|
||||||
return self.multipliedBy(1 / amount.floatValue)
|
return self.multipliedBy(1 / amount.floatValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func offset(amount : FloatConvertible) -> ConstraintDescriptionEditable {
|
public func offset(amount: FloatConvertible) -> ConstraintDescriptionEditable {
|
||||||
return ConstraintDescriptionEditable(self.backing.offset(amount))
|
return ConstraintDescriptionEditable(self.backing.offset(amount))
|
||||||
}
|
}
|
||||||
public func offset(amount: CGPoint) -> ConstraintDescriptionEditable {
|
public func offset(amount: CGPoint) -> ConstraintDescriptionEditable {
|
||||||
|
@ -190,38 +186,37 @@ public class ConstraintDescriptionEditable: ConstraintDescriptionPriortizable {
|
||||||
*/
|
*/
|
||||||
public class ConstraintDescriptionRelatable {
|
public class ConstraintDescriptionRelatable {
|
||||||
|
|
||||||
private let backing : ConstraintDescription
|
private let backing: ConstraintDescription
|
||||||
|
|
||||||
init(_ backing : ConstraintDescription) {
|
init(_ backing: ConstraintDescription) {
|
||||||
self.backing = backing
|
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)
|
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)
|
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)
|
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)
|
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)
|
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)
|
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 {
|
internal class ConstraintDescription {
|
||||||
|
|
||||||
private var location : SourceLocation?
|
private var location: SourceLocation? = nil
|
||||||
|
|
||||||
private var left: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Left) }
|
private var left: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Left) }
|
||||||
private var top: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Top) }
|
private var top: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Top) }
|
||||||
|
@ -480,7 +475,7 @@ internal class ConstraintDescription {
|
||||||
return self
|
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
|
self.location = location
|
||||||
|
|
||||||
|
@ -507,7 +502,7 @@ internal class ConstraintDescription {
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(iOS 7.0, *)
|
@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)
|
return constrainTo(ConstraintItem(object: other, attributes: ConstraintAttributes.None), relation: relation, location: location)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ public class ConstraintMaker {
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class func prepareConstraints(view view: View, location: SourceLocation, @noescape closure: (make: ConstraintMaker) -> Void) -> [Constraint] {
|
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)
|
closure(make: maker)
|
||||||
|
|
||||||
let constraints = maker.constraintDescriptions.map { $0.constraint }
|
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
|
view.translatesAutoresizingMaskIntoConstraints = false
|
||||||
let maker = ConstraintMaker(view: view, location: location)
|
let maker = ConstraintMaker(view: view, location: location)
|
||||||
closure(make: maker)
|
closure(make: maker)
|
||||||
|
|
|
@ -23,10 +23,10 @@
|
||||||
|
|
||||||
public struct SourceLocation {
|
public struct SourceLocation {
|
||||||
|
|
||||||
public let file : String
|
public let file: String
|
||||||
public let line : UInt
|
public let line: UInt
|
||||||
|
|
||||||
init(file : String, line : UInt) {
|
init(file: String, line: UInt) {
|
||||||
self.file = file
|
self.file = file
|
||||||
self.line = line
|
self.line = line
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue