Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ios
/
Masonry
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
Lukas Stabe
11 years ago
Commit
c2688ca94422e90ff8e92d14497282df798f6a73
1 parent
04ace9d1
reimplement composite attributes based on MASAttribute
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
65 deletions
Masonry/MASConstraintMaker.m
Tests/Specs/MASConstraintMakerSpec.m
Masonry/MASConstraintMaker.m
View file @
c2688ca
...
...
@@ -59,6 +59,37 @@
return
constraint
;
}
-
(
MASConstraint
*
)
addConstraintWithAttributes
:
(
MASAttribute
)
attrs
{
MASAttribute
anyAttribute
=
MASAttributeLeft
|
MASAttributeRight
|
MASAttributeTop
|
MASAttributeBottom
|
MASAttributeLeading
|
MASAttributeTrailing
|
MASAttributeWidth
|
MASAttributeHeight
|
MASAttributeCenterX
|
MASAttributeCenterY
|
MASAttributeBaseline
;
NSAssert
((
attrs
&
anyAttribute
)
!=
0
,
@"You didn't pass any attribute to make.attributes(...)"
);
NSMutableArray
*
attributes
=
[
NSMutableArray
array
];
if
(
attrs
&
MASAttributeLeft
)
[
attributes
addObject
:
self
.
view
.
mas_left
];
if
(
attrs
&
MASAttributeRight
)
[
attributes
addObject
:
self
.
view
.
mas_right
];
if
(
attrs
&
MASAttributeTop
)
[
attributes
addObject
:
self
.
view
.
mas_top
];
if
(
attrs
&
MASAttributeBottom
)
[
attributes
addObject
:
self
.
view
.
mas_bottom
];
if
(
attrs
&
MASAttributeLeading
)
[
attributes
addObject
:
self
.
view
.
mas_leading
];
if
(
attrs
&
MASAttributeTrailing
)
[
attributes
addObject
:
self
.
view
.
mas_trailing
];
if
(
attrs
&
MASAttributeWidth
)
[
attributes
addObject
:
self
.
view
.
mas_width
];
if
(
attrs
&
MASAttributeHeight
)
[
attributes
addObject
:
self
.
view
.
mas_height
];
if
(
attrs
&
MASAttributeCenterX
)
[
attributes
addObject
:
self
.
view
.
mas_centerX
];
if
(
attrs
&
MASAttributeCenterY
)
[
attributes
addObject
:
self
.
view
.
mas_centerY
];
if
(
attrs
&
MASAttributeBaseline
)
[
attributes
addObject
:
self
.
view
.
mas_baseline
];
NSMutableArray
*
children
=
[
NSMutableArray
arrayWithCapacity
:
attributes
.
count
];
for
(
MASViewAttribute
*
a
in
attributes
)
{
[
children
addObject
:[[
MASViewConstraint
alloc
]
initWithFirstViewAttribute
:
a
]];
}
MASCompositeConstraint
*
constraint
=
[[
MASCompositeConstraint
alloc
]
initWithChildren
:
children
];
constraint
.
delegate
=
self
;
[
self
.
constraints
addObject
:
constraint
];
return
constraint
;
}
#pragma mark - standard Attributes
-
(
MASConstraint
*
)
left
{
...
...
@@ -107,34 +138,7 @@
-
(
MASConstraint
*
(
^
)(
MASAttribute
))
attributes
{
return
^
(
MASAttribute
attrs
){
MASAttribute
anyAttribute
=
MASAttributeLeft
|
MASAttributeRight
|
MASAttributeTop
|
MASAttributeBottom
|
MASAttributeLeading
|
MASAttributeTrailing
|
MASAttributeWidth
|
MASAttributeHeight
|
MASAttributeCenterX
|
MASAttributeCenterY
|
MASAttributeBaseline
;
NSAssert
((
attrs
&
anyAttribute
)
!=
0
,
@"You didn't pass any attribute to make.attributes(...)"
);
NSMutableArray
*
attributes
=
[
NSMutableArray
array
];
if
(
attrs
&
MASAttributeLeft
)
[
attributes
addObject
:
self
.
view
.
mas_left
];
if
(
attrs
&
MASAttributeRight
)
[
attributes
addObject
:
self
.
view
.
mas_right
];
if
(
attrs
&
MASAttributeTop
)
[
attributes
addObject
:
self
.
view
.
mas_top
];
if
(
attrs
&
MASAttributeBottom
)
[
attributes
addObject
:
self
.
view
.
mas_bottom
];
if
(
attrs
&
MASAttributeLeading
)
[
attributes
addObject
:
self
.
view
.
mas_leading
];
if
(
attrs
&
MASAttributeTrailing
)
[
attributes
addObject
:
self
.
view
.
mas_trailing
];
if
(
attrs
&
MASAttributeWidth
)
[
attributes
addObject
:
self
.
view
.
mas_width
];
if
(
attrs
&
MASAttributeHeight
)
[
attributes
addObject
:
self
.
view
.
mas_height
];
if
(
attrs
&
MASAttributeCenterX
)
[
attributes
addObject
:
self
.
view
.
mas_centerX
];
if
(
attrs
&
MASAttributeCenterY
)
[
attributes
addObject
:
self
.
view
.
mas_centerY
];
if
(
attrs
&
MASAttributeBaseline
)
[
attributes
addObject
:
self
.
view
.
mas_baseline
];
NSMutableArray
*
children
=
[
NSMutableArray
arrayWithCapacity
:
attributes
.
count
];
for
(
MASViewAttribute
*
a
in
attributes
)
{
[
children
addObject
:[[
MASViewConstraint
alloc
]
initWithFirstViewAttribute
:
a
]];
}
MASCompositeConstraint
*
constraint
=
[[
MASCompositeConstraint
alloc
]
initWithChildren
:
children
];
constraint
.
delegate
=
self
;
[
self
.
constraints
addObject
:
constraint
];
return
constraint
;
return
[
self
addConstraintWithAttributes
:
attrs
];
};
}
...
...
@@ -142,38 +146,15 @@
#pragma mark - composite Attributes
-
(
MASConstraint
*
)
edges
{
NSArray
*
children
=
@[
[[
MASViewConstraint
alloc
]
initWithFirstViewAttribute
:
self
.
view
.
mas_top
],
[[
MASViewConstraint
alloc
]
initWithFirstViewAttribute
:
self
.
view
.
mas_left
],
[[
MASViewConstraint
alloc
]
initWithFirstViewAttribute
:
self
.
view
.
mas_bottom
],
[[
MASViewConstraint
alloc
]
initWithFirstViewAttribute
:
self
.
view
.
mas_right
]
];
MASCompositeConstraint
*
constraint
=
[[
MASCompositeConstraint
alloc
]
initWithChildren
:
children
];
constraint
.
delegate
=
self
;
[
self
.
constraints
addObject
:
constraint
];
return
constraint
;
return
[
self
addConstraintWithAttributes
:
MASAttributeTop
|
MASAttributeLeft
|
MASAttributeRight
|
MASAttributeBottom
];
}
-
(
MASConstraint
*
)
size
{
NSArray
*
children
=
@[
[[
MASViewConstraint
alloc
]
initWithFirstViewAttribute
:
self
.
view
.
mas_width
],
[[
MASViewConstraint
alloc
]
initWithFirstViewAttribute
:
self
.
view
.
mas_height
]
];
MASCompositeConstraint
*
constraint
=
[[
MASCompositeConstraint
alloc
]
initWithChildren
:
children
];
constraint
.
delegate
=
self
;
[
self
.
constraints
addObject
:
constraint
];
return
constraint
;
return
[
self
addConstraintWithAttributes
:
MASAttributeWidth
|
MASAttributeHeight
];
}
-
(
MASConstraint
*
)
center
{
NSArray
*
children
=
@[
[[
MASViewConstraint
alloc
]
initWithFirstViewAttribute
:
self
.
view
.
mas_centerX
],
[[
MASViewConstraint
alloc
]
initWithFirstViewAttribute
:
self
.
view
.
mas_centerY
]
];
MASCompositeConstraint
*
constraint
=
[[
MASCompositeConstraint
alloc
]
initWithChildren
:
children
];
constraint
.
delegate
=
self
;
[
self
.
constraints
addObject
:
constraint
];
return
constraint
;
return
[
self
addConstraintWithAttributes
:
MASAttributeCenterX
|
MASAttributeCenterY
];
}
#pragma mark - grouping
...
...
Tests/Specs/MASConstraintMakerSpec.m
View file @
c2688ca
...
...
@@ -85,25 +85,27 @@ SpecBegin(MASConstraintMaker) {
expect
(
composite
.
childConstraints
).
to
.
haveCountOf
(
4
);
//top
MASViewConstraint
*
viewConstraint
=
composite
.
childConstraints
[
0
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
maker
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeTop
);
MASViewConstraint
*
viewConstraint
;
//left
viewConstraint
=
composite
.
childConstraints
[
1
];
viewConstraint
=
composite
.
childConstraints
[
0
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
maker
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeLeft
);
//bottom
//right
viewConstraint
=
composite
.
childConstraints
[
1
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
maker
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeRight
);
//top
viewConstraint
=
composite
.
childConstraints
[
2
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
maker
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttribute
Bottom
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttribute
Top
);
//
right
//
bottom
viewConstraint
=
composite
.
childConstraints
[
3
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
maker
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttribute
Right
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttribute
Bottom
);
}
-
(
void
)
testCreateWidthAndHeightChildren
{
...
...
Please
register
or
login
to post a comment