宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-04-06 a1ae6802080a22e6e6ce6d0935e95facb1daca5c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
//  QLUtils.swift
//  QuickLayout
//
//  Created by Daniel Huri on 11/21/17.
//
 
import Foundation
#if os(OSX)
import AppKit
#else
import UIKit
#endif
 
/**
 Typealias for dictionary that contains multiple constraints
 */
public typealias QLMultipleConstraints = [QLAttribute: NSLayoutConstraint]
 
/**
 Extends layout priority to other readable types
 */
public extension QLPriority {
    static let must = QLPriority(rawValue: 999)
    static let zero = QLPriority(rawValue: 0)
}
 
/**
 Represents pair of attributes
 */
public struct QLAttributePair {
    public let first: QLAttribute
    public let second: QLAttribute
}
 
/**
 Represents size constraints
 */
public struct QLSizeConstraints {
    public let width: NSLayoutConstraint
    public let height: NSLayoutConstraint
}
 
/**
 Represents center constraints
 */
public struct QLCenterConstraints {
    public let x: NSLayoutConstraint
    public let y: NSLayoutConstraint
}
 
/**
 Represents axis constraints (might be .top and .bottom, .left and .right, .leading and .trailing)
 */
public struct QLAxisConstraints {
    public let first: NSLayoutConstraint
    public let second: NSLayoutConstraint
}
 
/**
 Represents center and size constraints
 */
public struct QLFillConstraints {
    public let center: QLCenterConstraints
    public let size: QLSizeConstraints
}
 
/**
 Represents pair of priorities
 */
public struct QLPriorityPair {
    
    public let horizontal: QLPriority
    public let vertical: QLPriority
    public static var required: QLPriorityPair {
        return QLPriorityPair(.required, .required)
    }
    
    public static var must: QLPriorityPair {
        return QLPriorityPair(.must, .must)
    }
    
    public init(_ horizontal: QLPriority, _ vertical: QLPriority) {
        self.horizontal = horizontal
        self.vertical = vertical
    }
}
 
/**
 Represents axis description
 */
public enum QLAxis {
    case horizontally
    case vertically
    
    public var attributes: QLAttributePair {
        
        let first: QLAttribute
        let second: QLAttribute
        
        switch self {
        case .horizontally:
            first = .left
            second = .right
        case .vertically:
            first = .top
            second = .bottom
        }
        return QLAttributePair(first: first, second: second)
    }
}