-
Notifications
You must be signed in to change notification settings - Fork 528
/
LayoutProxy.swift
196 lines (165 loc) · 5.43 KB
/
LayoutProxy.swift
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
//
// LayoutProxy.swift
// Cartography
//
// Created by Robert Böhnke on 17/06/14.
// Copyright (c) 2014 Robert Böhnke. All rights reserved.
//
import Foundation
public struct LayoutProxy {
/// The width of the view.
public var width: Dimension {
return Dimension(context, view, .Width)
}
/// The height of the view.
public var height: Dimension {
return Dimension(context, view, .Height)
}
/// The size of the view. This property affects both `width` and `height`.
public var size: Size {
return Size(context, [
Dimension(context, view, .Width),
Dimension(context, view, .Height)
])
}
/// The top edge of the view.
public var top: Edge {
return Edge(context, view, .Top)
}
/// The right edge of the view.
public var right: Edge {
return Edge(context, view, .Right)
}
/// The bottom edge of the view.
public var bottom: Edge {
return Edge(context, view, .Bottom)
}
/// The left edge of the view.
public var left: Edge {
return Edge(context, view, .Left)
}
/// All edges of the view. This property affects `top`, `bottom`, `leading`
/// and `trailing`.
public var edges: Edges {
return Edges(context, [
Edge(context, view, .Top),
Edge(context, view, .Leading),
Edge(context, view, .Bottom),
Edge(context, view, .Trailing)
])
}
/// The leading edge of the view.
public var leading: Edge {
return Edge(context, view, .Leading)
}
/// The trailing edge of the view.
public var trailing: Edge {
return Edge(context, view, .Trailing)
}
/// The horizontal center of the view.
public var centerX: Edge {
return Edge(context, view, .CenterX)
}
/// The vertical center of the view.
public var centerY: Edge {
return Edge(context, view, .CenterY)
}
/// The center point of the view. This property affects `centerX` and
/// `centerY`.
public var center: Point {
return Point(context, [
Edge(context, view, .CenterX),
Edge(context, view, .CenterY)
])
}
/// The baseline of the view.
public var baseline: Edge {
return Edge(context, view, .LastBaseline)
}
/// The last baseline of the view.
public var lastBaseline: Edge {
return Edge(context, view, .LastBaseline)
}
#if os(iOS) || os(tvOS)
/// The first baseline of the view. iOS exclusive.
@available(iOS, introduced=8.0)
public var firstBaseline: Edge {
return Edge(context, view, .FirstBaseline)
}
/// All edges of the view with their respective margins. This property
/// affects `topMargin`, `bottomMargin`, `leadingMargin` and
/// `trailingMargin`.
@available(iOS, introduced=8.0)
public var edgesWithinMargins: Edges {
return Edges(context, [
Edge(context, view, .TopMargin),
Edge(context, view, .LeadingMargin),
Edge(context, view, .BottomMargin),
Edge(context, view, .TrailingMargin)
])
}
/// The left margin of the view. iOS exclusive.
@available(iOS, introduced=8.0)
public var leftMargin: Edge {
return Edge(context, view, .LeftMargin)
}
/// The right margin of the view. iOS exclusive.
@available(iOS, introduced=8.0)
public var rightMargin: Edge {
return Edge(context, view, .RightMargin)
}
/// The top margin of the view. iOS exclusive.
@available(iOS, introduced=8.0)
public var topMargin: Edge {
return Edge(context, view, .TopMargin)
}
/// The bottom margin of the view. iOS exclusive.
@available(iOS, introduced=8.0)
public var bottomMargin: Edge {
return Edge(context, view, .BottomMargin)
}
/// The leading margin of the view. iOS exclusive.
@available(iOS, introduced=8.0)
public var leadingMargin: Edge {
return Edge(context, view, .LeadingMargin)
}
/// The trailing margin of the view. iOS exclusive.
@available(iOS, introduced=8.0)
public var trailingMargin: Edge {
return Edge(context, view, .TrailingMargin)
}
/// The horizontal center within the margins of the view. iOS exclusive.
@available(iOS, introduced=8.0)
public var centerXWithinMargins: Edge {
return Edge(context, view, .CenterXWithinMargins)
}
/// The vertical center within the margins of the view. iOS exclusive.
@available(iOS, introduced=8.0)
public var centerYWithinMargins: Edge {
return Edge(context, view, .CenterYWithinMargins)
}
/// The center point within the margins of the view. This property affects
/// `centerXWithinMargins` and `centerYWithinMargins`. iOS exclusive.
@available(iOS, introduced=8.0)
public var centerWithinMargins: Point {
return Point(context, [
Edge(context, view, .CenterXWithinMargins),
Edge(context, view, .CenterYWithinMargins)
])
}
#endif
internal let context: Context
internal let view: View
/// The superview of the view, if it exists.
public var superview: LayoutProxy? {
if let superview = view.superview {
return LayoutProxy(context, superview)
} else {
return nil
}
}
init(_ context: Context, _ view: View) {
self.context = context
self.view = view
}
}