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
04ace9d19ce942070562c4a54c90a8a44d903b70
1 parent
18f57bd6
change to and test make.attributes(...)
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
6 deletions
Masonry/MASConstraintMaker.h
Masonry/MASConstraintMaker.m
Tests/Specs/MASConstraintMakerSpec.m
Masonry/MASConstraintMaker.h
View file @
04ace9d
...
...
@@ -9,6 +9,20 @@
#import "MASConstraint.h"
#import "MASUtilities.h"
typedef
NS_OPTIONS
(
NSInteger
,
MASAttribute
)
{
MASAttributeLeft
=
1
<<
NSLayoutAttributeLeft
,
MASAttributeRight
=
1
<<
NSLayoutAttributeRight
,
MASAttributeTop
=
1
<<
NSLayoutAttributeTop
,
MASAttributeBottom
=
1
<<
NSLayoutAttributeBottom
,
MASAttributeLeading
=
1
<<
NSLayoutAttributeLeading
,
MASAttributeTrailing
=
1
<<
NSLayoutAttributeTrailing
,
MASAttributeWidth
=
1
<<
NSLayoutAttributeWidth
,
MASAttributeHeight
=
1
<<
NSLayoutAttributeHeight
,
MASAttributeCenterX
=
1
<<
NSLayoutAttributeCenterX
,
MASAttributeCenterY
=
1
<<
NSLayoutAttributeCenterY
,
MASAttributeBaseline
=
1
<<
NSLayoutAttributeBaseline
,
};
/**
* Provides factory methods for creating MASConstraints.
* Constraints are collected until they are ready to be installed
...
...
@@ -33,10 +47,11 @@
@property
(
nonatomic
,
strong
,
readonly
)
MASConstraint
*
baseline
;
/**
* Returns a block which creates a new MASViewConstraint with the first item set
* to the makers associated view and the passed-in attribute
* Returns a block which creates a new MASCompositeConstraint with the first item set
* to the makers associated view and children corresponding to the set bits in the
* MASAttribute parameter. Combine multiple attributes via binary-or.
*/
@property
(
nonatomic
,
strong
,
readonly
)
MASConstraint
*
(
^
attribute
)(
NSLayoutAttribute
attr
);
@property
(
nonatomic
,
strong
,
readonly
)
MASConstraint
*
(
^
attribute
s
)(
MASAttribute
attrs
);
/**
* Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges
...
...
Masonry/MASConstraintMaker.m
View file @
04ace9d
...
...
@@ -105,9 +105,36 @@
return
[
self
addConstraintWithLayoutAttribute
:
NSLayoutAttributeBaseline
];
}
-
(
MASConstraint
*
(
^
)(
NSLayoutAttribute
))
attribute
{
return
^
(
NSLayoutAttribute
attr
){
return
[
self
addConstraintWithLayoutAttribute
:
attr
];
-
(
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
;
};
}
...
...
Tests/Specs/MASConstraintMakerSpec.m
View file @
04ace9d
...
...
@@ -39,6 +39,31 @@ SpecBegin(MASConstraintMaker) {
maker
=
[[
MASConstraintMaker
alloc
]
initWithView
:
view
];
}
-
(
void
)
testCreateSingleAttribute
{
composite
=
(
MASCompositeConstraint
*
)
maker
.
attributes
(
MASAttributeHeight
);
expect
(
composite
.
childConstraints
).
to
.
haveCountOf
(
1
);
MASViewConstraint
*
viewConstraint
=
composite
.
childConstraints
[
0
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
maker
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeHeight
);
}
-
(
void
)
testCreateAttributes
{
composite
=
(
MASCompositeConstraint
*
)
maker
.
attributes
(
MASAttributeCenterX
|
MASAttributeWidth
);
expect
(
composite
.
childConstraints
).
to
.
haveCountOf
(
2
);
// children are ordered like MASAttribute, so the first is width
MASViewConstraint
*
viewConstraint
=
composite
.
childConstraints
[
0
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
maker
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeWidth
);
viewConstraint
=
composite
.
childConstraints
[
1
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
maker
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeCenterX
);
}
-
(
void
)
testCreateCenterYAndCenterXChildren
{
composite
=
(
MASCompositeConstraint
*
)
maker
.
center
;
...
...
Please
register
or
login
to post a comment