Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
7f374791
Commit
7f374791
authored
May 23, 2019
by
Orkhan Alikhanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added relationer operators
parent
8225dd36
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
146 additions
and
76 deletions
+146
-76
Sources/iOS/Layout/Layout.swift
+146
-76
No files found.
Sources/iOS/Layout/Layout.swift
View file @
7f374791
...
@@ -198,61 +198,67 @@ public extension Layout {
...
@@ -198,61 +198,67 @@ public extension Layout {
/**
/**
Constraints top of the view to its parent's.
Constraints top of the view to its parent's.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
top
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
top
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
top
,
constant
:
offset
)
return
constraint
(
.
top
,
relationer
:
relationer
,
constant
:
offset
)
}
}
/**
/**
Constraints left of the view to its parent's.
Constraints left of the view to its parent's.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
left
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
left
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
left
,
constant
:
offset
)
return
constraint
(
.
left
,
relationer
:
relationer
,
constant
:
offset
)
}
}
/**
/**
Constraints right of the view to its parent.
Constraints right of the view to its parent.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
right
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
right
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
right
,
constant
:
-
offset
)
return
constraint
(
.
right
,
relationer
:
relationer
,
constant
:
-
offset
)
}
}
/**
/**
Constraints leading of the view to its parent's.
Constraints leading of the view to its parent's.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
leading
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
leading
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
leading
,
constant
:
offset
)
return
constraint
(
.
leading
,
relationer
:
relationer
,
constant
:
offset
)
}
}
/**
/**
Constraints trailing of the view to its parent.
Constraints trailing of the view to its parent.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
trailing
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
trailing
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
trailing
,
constant
:
-
offset
)
return
constraint
(
.
trailing
,
relationer
:
relationer
,
constant
:
-
offset
)
}
}
/**
/**
Constraints bottom of the view to its parent's.
Constraints bottom of the view to its parent's.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
bottom
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
bottom
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
bottom
,
constant
:
-
offset
)
return
constraint
(
.
bottom
,
relationer
:
relationer
,
constant
:
-
offset
)
}
}
/**
/**
...
@@ -390,41 +396,45 @@ public extension Layout {
...
@@ -390,41 +396,45 @@ public extension Layout {
/**
/**
Constraints horizontal center of the view to its parent's.
Constraints horizontal center of the view to its parent's.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
centerX
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
centerX
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
centerX
,
constant
:
offset
)
return
constraint
(
.
centerX
,
relationer
:
relationer
,
constant
:
offset
)
}
}
/**
/**
Constraints vertical center of the view to its parent's.
Constraints vertical center of the view to its parent's.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
centerY
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
centerY
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
centerY
,
constant
:
offset
)
return
constraint
(
.
centerY
,
relationer
:
relationer
,
constant
:
offset
)
}
}
/**
/**
Constraints width of the view to its parent's.
Constraints width of the view to its parent's.
- Parameter offset: A CGFloat offset.
- Parameter offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
width
(
offset
:
CGFloat
=
0
)
->
Layout
{
func
width
(
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
width
,
constant
:
offset
)
return
constraint
(
.
width
,
relationer
:
relationer
,
constant
:
offset
)
}
}
/**
/**
Constraints height of the view to its parent's.
Constraints height of the view to its parent's.
- Parameter offset: A CGFloat offset.
- Parameter offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
height
(
offset
:
CGFloat
=
0
)
->
Layout
{
func
height
(
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
height
,
constant
:
offset
)
return
constraint
(
.
height
,
relationer
:
relationer
,
constant
:
offset
)
}
}
/**
/**
...
@@ -445,61 +455,67 @@ public extension Layout {
...
@@ -445,61 +455,67 @@ public extension Layout {
/**
/**
Constraints top of the view to its parent's safeArea.
Constraints top of the view to its parent's safeArea.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
topSafe
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
topSafe
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
top
,
constant
:
offset
,
useSafeArea
:
true
)
return
constraint
(
.
top
,
relationer
:
relationer
,
constant
:
offset
,
useSafeArea
:
true
)
}
}
/**
/**
Constraints left of the view to its parent's safeArea.
Constraints left of the view to its parent's safeArea.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
leftSafe
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
leftSafe
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
left
,
constant
:
offset
,
useSafeArea
:
true
)
return
constraint
(
.
left
,
relationer
:
relationer
,
constant
:
offset
,
useSafeArea
:
true
)
}
}
/**
/**
Constraints right of the view to its parent.
Constraints right of the view to its parent.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
rightSafe
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
rightSafe
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
right
,
constant
:
-
offset
,
useSafeArea
:
true
)
return
constraint
(
.
right
,
relationer
:
relationer
,
constant
:
-
offset
,
useSafeArea
:
true
)
}
}
/**
/**
Constraints leading of the view to its parent's safeArea.
Constraints leading of the view to its parent's safeArea.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
leadingSafe
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
leadingSafe
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
leading
,
constant
:
offset
,
useSafeArea
:
true
)
return
constraint
(
.
leading
,
relationer
:
relationer
,
constant
:
offset
,
useSafeArea
:
true
)
}
}
/**
/**
Constraints trailing of the view to its parent.
Constraints trailing of the view to its parent.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
trailingSafe
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
trailingSafe
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
trailing
,
constant
:
-
offset
,
useSafeArea
:
true
)
return
constraint
(
.
trailing
,
relationer
:
relationer
,
constant
:
-
offset
,
useSafeArea
:
true
)
}
}
/**
/**
Constraints bottom of the view to its parent's safeArea.
Constraints bottom of the view to its parent's safeArea.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
bottomSafe
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
bottomSafe
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
bottom
,
constant
:
-
offset
,
useSafeArea
:
true
)
return
constraint
(
.
bottom
,
relationer
:
relationer
,
constant
:
-
offset
,
useSafeArea
:
true
)
}
}
/**
/**
...
@@ -637,41 +653,45 @@ public extension Layout {
...
@@ -637,41 +653,45 @@ public extension Layout {
/**
/**
Constraints horizontal center of the view to its parent's safeArea.
Constraints horizontal center of the view to its parent's safeArea.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
centerXSafe
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
centerXSafe
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
centerX
,
constant
:
offset
,
useSafeArea
:
true
)
return
constraint
(
.
centerX
,
relationer
:
relationer
,
constant
:
offset
,
useSafeArea
:
true
)
}
}
/**
/**
Constraints vertical center of the view to its parent's safeArea.
Constraints vertical center of the view to its parent's safeArea.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
centerYSafe
(
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
centerYSafe
(
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
centerY
,
constant
:
offset
,
useSafeArea
:
true
)
return
constraint
(
.
centerY
,
relationer
:
relationer
,
constant
:
offset
,
useSafeArea
:
true
)
}
}
/**
/**
Constraints width of the view to its parent's safeArea.
Constraints width of the view to its parent's safeArea.
- Parameter offset: A CGFloat offset.
- Parameter offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
widthSafe
(
offset
:
CGFloat
=
0
)
->
Layout
{
func
widthSafe
(
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
width
,
constant
:
offset
,
useSafeArea
:
true
)
return
constraint
(
.
width
,
relationer
:
relationer
,
constant
:
offset
,
useSafeArea
:
true
)
}
}
/**
/**
Constraints height of the view to its parent's safeArea.
Constraints height of the view to its parent's safeArea.
- Parameter offset: A CGFloat offset.
- Parameter offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
heightSafe
(
offset
:
CGFloat
=
0
)
->
Layout
{
func
heightSafe
(
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
height
,
constant
:
offset
,
useSafeArea
:
true
)
return
constraint
(
.
height
,
relationer
:
relationer
,
constant
:
offset
,
useSafeArea
:
true
)
}
}
/**
/**
...
@@ -692,21 +712,23 @@ public extension Layout {
...
@@ -692,21 +712,23 @@ public extension Layout {
/**
/**
Constraints width of the view to a constant value.
Constraints width of the view to a constant value.
- Parameter _ width: A CGFloat value.
- Parameter _ width: A CGFloat value.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
width
(
_
width
:
CGFloat
)
->
Layout
{
func
width
(
_
width
:
CGFloat
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
constantWidth
,
constants
:
width
)
return
constraint
(
.
constantWidth
,
relationer
:
relationer
,
constants
:
width
)
}
}
/**
/**
Constraints height of the view to a constant value.
Constraints height of the view to a constant value.
- Parameter _ height: A CGFloat value.
- Parameter _ height: A CGFloat value.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
height
(
_
height
:
CGFloat
)
->
Layout
{
func
height
(
_
height
:
CGFloat
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
constantHeight
,
constants
:
height
)
return
constraint
(
.
constantHeight
,
relationer
:
relationer
,
constants
:
height
)
}
}
/**
/**
...
@@ -725,66 +747,72 @@ public extension Layout {
...
@@ -725,66 +747,72 @@ public extension Layout {
Constraints top of the view to the given anchor.
Constraints top of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
top
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
top
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
top
,
to
:
anchor
,
constant
:
offset
)
return
constraint
(
.
top
,
to
:
anchor
,
relationer
:
relationer
,
constant
:
offset
)
}
}
/**
/**
Constraints left of the view to the given anchor.
Constraints left of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
left
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
left
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
left
,
to
:
anchor
,
constant
:
offset
)
return
constraint
(
.
left
,
to
:
anchor
,
relationer
:
relationer
,
constant
:
offset
)
}
}
/**
/**
Constraints right of the view to the given anchor.
Constraints right of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
right
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
right
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
right
,
to
:
anchor
,
constant
:
-
offset
)
return
constraint
(
.
right
,
to
:
anchor
,
relationer
:
relationer
,
constant
:
-
offset
)
}
}
/**
/**
Constraints leading of the view to the given anchor.
Constraints leading of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
leading
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
leading
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
leading
,
to
:
anchor
,
constant
:
offset
)
return
constraint
(
.
leading
,
to
:
anchor
,
relationer
:
relationer
,
constant
:
offset
)
}
}
/**
/**
Constraints trailing of the view to the given anchor.
Constraints trailing of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
trailing
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
trailing
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
trailing
,
to
:
anchor
,
constant
:
-
offset
)
return
constraint
(
.
trailing
,
to
:
anchor
,
relationer
:
relationer
,
constant
:
-
offset
)
}
}
/**
/**
Constraints bottom of the view to the given anchor.
Constraints bottom of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
bottom
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
bottom
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
bottom
,
to
:
anchor
,
constant
:
-
offset
)
return
constraint
(
.
bottom
,
to
:
anchor
,
relationer
:
relationer
,
constant
:
-
offset
)
}
}
/**
/**
...
@@ -935,44 +963,48 @@ public extension Layout {
...
@@ -935,44 +963,48 @@ public extension Layout {
Constraints horizontal center of the view to the given anchor.
Constraints horizontal center of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
centerX
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
centerX
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
centerX
,
to
:
anchor
,
constant
:
offset
)
return
constraint
(
.
centerX
,
to
:
anchor
,
relationer
:
relationer
,
constant
:
offset
)
}
}
/**
/**
Constraints vertical center of the view to the given anchor.
Constraints vertical center of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
centerY
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
centerY
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
centerY
,
to
:
anchor
,
constant
:
offset
)
return
constraint
(
.
centerY
,
to
:
anchor
,
relationer
:
relationer
,
constant
:
offset
)
}
}
/**
/**
Constraints width of the view to the given anchor.
Constraints width of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
width
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
width
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
width
,
to
:
anchor
,
constant
:
offset
)
return
constraint
(
.
width
,
to
:
anchor
,
relationer
:
relationer
,
constant
:
offset
)
}
}
/**
/**
Constraints height of the view to the given anchor.
Constraints height of the view to the given anchor.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter _ anchor: A LayoutAnchorable.
- Parameter offset: A CGFloat offset.
- Parameter _ offset: A CGFloat offset.
- Parameter _ relationer: A LayoutRelationer.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
@discardableResult
@discardableResult
func
height
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
)
->
Layout
{
func
height
(
_
anchor
:
LayoutAnchorable
,
_
offset
:
CGFloat
=
0
,
_
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
)
->
Layout
{
return
constraint
(
.
height
,
to
:
anchor
,
constant
:
offset
)
return
constraint
(
.
height
,
to
:
anchor
,
relationer
:
relationer
,
constant
:
offset
)
}
}
/**
/**
...
@@ -1051,21 +1083,23 @@ private extension Layout {
...
@@ -1051,21 +1083,23 @@ private extension Layout {
Constraints the view to its parent according to the provided attribute.
Constraints the view to its parent according to the provided attribute.
If the constraint already exists, will update its constant.
If the constraint already exists, will update its constant.
- Parameter _ attribute: A LayoutAttribute.
- Parameter _ attribute: A LayoutAttribute.
- Parameter _ relationer: A LayoutRelationer.
- Parameter constant: A CGFloat.
- Parameter constant: A CGFloat.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
func
constraint
(
_
attribute
:
LayoutAttribute
,
constant
:
CGFloat
,
useSafeArea
:
Bool
=
false
)
->
Layout
{
func
constraint
(
_
attribute
:
LayoutAttribute
,
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
,
constant
:
CGFloat
,
useSafeArea
:
Bool
=
false
)
->
Layout
{
return
constraint
([
attribute
],
constants
:
constant
,
useSafeArea
:
useSafeArea
)
return
constraint
([
attribute
],
relationer
:
relationer
,
constants
:
constant
,
useSafeArea
:
useSafeArea
)
}
}
/**
/**
Constraints the view to its parent according to the provided attributes.
Constraints the view to its parent according to the provided attributes.
If any of the constraints already exists, will update its constant.
If any of the constraints already exists, will update its constant.
- Parameter _ attributes: An array of LayoutAttribute.
- Parameter _ attributes: An array of LayoutAttribute.
- Parameter _ relationer: A LayoutRelationer.
- Parameter constants: A list of CGFloat.
- Parameter constants: A list of CGFloat.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
func
constraint
(
_
attributes
:
[
LayoutAttribute
],
constants
:
CGFloat
...
,
useSafeArea
:
Bool
=
false
)
->
Layout
{
func
constraint
(
_
attributes
:
[
LayoutAttribute
],
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
,
constants
:
CGFloat
...
,
useSafeArea
:
Bool
=
false
)
->
Layout
{
var
attributes
=
attributes
var
attributes
=
attributes
var
anchor
:
LayoutAnchor
!
var
anchor
:
LayoutAnchor
!
...
@@ -1080,7 +1114,7 @@ private extension Layout {
...
@@ -1080,7 +1114,7 @@ private extension Layout {
anchor
=
LayoutAnchor
(
constraintable
:
useSafeArea
?
parent
?
.
safeAnchor
.
constraintable
:
parent
,
attributes
:
attributes
)
anchor
=
LayoutAnchor
(
constraintable
:
useSafeArea
?
parent
?
.
safeAnchor
.
constraintable
:
parent
,
attributes
:
attributes
)
}
}
return
constraint
(
attributes
,
to
:
anchor
,
constants
:
constants
)
return
constraint
(
attributes
,
to
:
anchor
,
relationer
:
relationer
,
constants
:
constants
)
}
}
/**
/**
...
@@ -1088,11 +1122,12 @@ private extension Layout {
...
@@ -1088,11 +1122,12 @@ private extension Layout {
If the constraint already exists, will update its constant.
If the constraint already exists, will update its constant.
- Parameter _ attribute: A LayoutAttribute.
- Parameter _ attribute: A LayoutAttribute.
- Parameter to anchor: A LayoutAnchorable.
- Parameter to anchor: A LayoutAnchorable.
- Parameter relation: A LayoutRelation between anchors.
- Parameter constant: A CGFloat.
- Parameter constant: A CGFloat.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
func
constraint
(
_
attribute
:
LayoutAttribute
,
to
anchor
:
LayoutAnchorable
,
constant
:
CGFloat
)
->
Layout
{
func
constraint
(
_
attribute
:
LayoutAttribute
,
to
anchor
:
LayoutAnchorable
,
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
,
constant
:
CGFloat
)
->
Layout
{
return
constraint
([
attribute
],
to
:
anchor
,
constants
:
constant
)
return
constraint
([
attribute
],
to
:
anchor
,
relationer
:
relationer
,
constants
:
constant
)
}
}
/**
/**
...
@@ -1100,11 +1135,12 @@ private extension Layout {
...
@@ -1100,11 +1135,12 @@ private extension Layout {
If any of the constraints already exists, will update its constant.
If any of the constraints already exists, will update its constant.
- Parameter _ attributes: An array of LayoutAttribute.
- Parameter _ attributes: An array of LayoutAttribute.
- Parameter to anchor: A LayoutAnchorable.
- Parameter to anchor: A LayoutAnchorable.
- Parameter relation: A LayoutRelation between anchors.
- Parameter constants: A list of CGFloat.
- Parameter constants: A list of CGFloat.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
func
constraint
(
_
attributes
:
[
LayoutAttribute
],
to
anchor
:
LayoutAnchorable
,
constants
:
CGFloat
...
)
->
Layout
{
func
constraint
(
_
attributes
:
[
LayoutAttribute
],
to
anchor
:
LayoutAnchorable
,
relationer
:
LayoutRelationer
=
LayoutRelationerStruct
.
equal
,
constants
:
CGFloat
...
)
->
Layout
{
return
constraint
(
attributes
,
to
:
anchor
,
constants
:
constants
)
return
constraint
(
attributes
,
to
:
anchor
,
relationer
:
relationer
,
constants
:
constants
)
}
}
/**
/**
...
@@ -1112,17 +1148,18 @@ private extension Layout {
...
@@ -1112,17 +1148,18 @@ private extension Layout {
If any of the constraints already exists, will update its constant.
If any of the constraints already exists, will update its constant.
- Parameter _ attributes: An array of LayoutAttribute.
- Parameter _ attributes: An array of LayoutAttribute.
- Parameter to anchor: A LayoutAnchorable.
- Parameter to anchor: A LayoutAnchorable.
- Parameter relation: A LayoutRelation between anchors.
- Parameter constants: An array of CGFloat.
- Parameter constants: An array of CGFloat.
- Returns: A Layout instance to allow chaining.
- Returns: A Layout instance to allow chaining.
*/
*/
func
constraint
(
_
attributes
:
[
LayoutAttribute
],
to
anchor
:
LayoutAnchorable
,
constants
:
[
CGFloat
])
->
Layout
{
func
constraint
(
_
attributes
:
[
LayoutAttribute
],
to
anchor
:
LayoutAnchorable
,
relationer
:
LayoutRelationer
,
constants
:
[
CGFloat
])
->
Layout
{
let
from
=
LayoutAnchor
(
constraintable
:
constraintable
,
attributes
:
attributes
)
let
from
=
LayoutAnchor
(
constraintable
:
constraintable
,
attributes
:
attributes
)
var
to
=
anchor
as?
LayoutAnchor
var
to
=
anchor
as?
LayoutAnchor
if
to
?
.
attributes
.
isEmpty
??
true
{
if
to
?
.
attributes
.
isEmpty
??
true
{
let
v
=
(
anchor
as?
UIView
)
??
(
anchor
as?
LayoutAnchor
)?
.
constraintable
let
v
=
(
anchor
as?
UIView
)
??
(
anchor
as?
LayoutAnchor
)?
.
constraintable
to
=
LayoutAnchor
(
constraintable
:
v
,
attributes
:
attributes
)
to
=
LayoutAnchor
(
constraintable
:
v
,
attributes
:
attributes
)
}
}
let
constraint
=
LayoutConstraint
(
fromAnchor
:
from
,
toAnchor
:
to
!
,
relation
:
.
equal
,
constants
:
constants
)
let
constraint
=
LayoutConstraint
(
fromAnchor
:
from
,
toAnchor
:
to
!
,
relation
:
relationer
(
.
nil
,
.
nil
)
,
constants
:
constants
)
let
constraints
=
(
view
?
.
constraints
??
[])
+
(
view
?
.
superview
?
.
constraints
??
[])
let
constraints
=
(
view
?
.
constraints
??
[])
+
(
view
?
.
superview
?
.
constraints
??
[])
...
@@ -1140,3 +1177,36 @@ private extension Layout {
...
@@ -1140,3 +1177,36 @@ private extension Layout {
return
self
return
self
}
}
}
}
/// A closure typealias for relation operators.
public
typealias
LayoutRelationer
=
(
LayoutRelationerStruct
,
LayoutRelationerStruct
)
->
LayoutRelation
/// A dummy struct used in creating relation operators (==, >=, <=).
public
struct
LayoutRelationerStruct
{
/// Passed as an unused argument to the LayoutRelationer closures.
static
let
`
nil
`
=
LayoutRelationerStruct
()
/**
A method used as a default parameter for LayoutRelationer closures.
Swift does not allow using == operator directly, so we had to create this.
*/
public
static
func
equal
(
left
:
LayoutRelationerStruct
,
right
:
LayoutRelationerStruct
)
->
LayoutRelation
{
return
.
equal
}
}
/// A method returning `LayoutRelation.equal`
public
func
==
(
left
:
LayoutRelationerStruct
,
right
:
LayoutRelationerStruct
)
->
LayoutRelation
{
return
.
equal
}
/// A method returning `LayoutRelation.greaterThanOrEqual`
public
func
>=
(
left
:
LayoutRelationerStruct
,
right
:
LayoutRelationerStruct
)
->
LayoutRelation
{
return
.
greaterThanOrEqual
}
/// A method returning `LayoutRelation.lessThanOrEqual`
public
func
<=
(
left
:
LayoutRelationerStruct
,
right
:
LayoutRelationerStruct
)
->
LayoutRelation
{
return
.
lessThanOrEqual
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment