Skip to content

Commit

Permalink
move edges/size/center to MASLayoutConstraint protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
cntrump committed May 30, 2021
1 parent 08e05b1 commit e983a38
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
21 changes: 21 additions & 0 deletions Masonry/MASConstraintMaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ typedef NS_OPTIONS(NSInteger, MASAttribute) {
@property (nonatomic, strong, readonly) MASConstraint *centerX;
@property (nonatomic, strong, readonly) MASConstraint *centerY;

/**
* Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges
* which generates the appropriate MASViewConstraint children (top, left, bottom, right)
* with the first item set to the makers associated view
*/
@property (nonatomic, strong, readonly) MASConstraint *edges;

/**
* Creates a MASCompositeConstraint with type MASCompositeConstraintTypeSize
* which generates the appropriate MASViewConstraint children (width, height)
* with the first item set to the makers associated view
*/
@property (nonatomic, strong, readonly) MASConstraint *size;

/**
* Creates a MASCompositeConstraint with type MASCompositeConstraintTypeCenter
* which generates the appropriate MASViewConstraint children (centerX, centerY)
* with the first item set to the makers associated view
*/
@property (nonatomic, strong, readonly) MASConstraint *center;

@end

/**
Expand Down
25 changes: 14 additions & 11 deletions Masonry/MASConstraintMaker.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
#import "MASConstraint+Private.h"
#import "MASViewAttribute.h"
#import "View+MASAdditions.h"
#import "LayoutGuide+MASAdditions.h"

@interface MASConstraintMaker () <MASConstraintDelegate>

@property (nonatomic, weak) MAS_VIEW *view;
@property (nonatomic, weak) id item;
@property (nonatomic, weak) MASLayoutGuide *item;
@property (nonatomic, strong) NSMutableArray *constraints;

@end
Expand Down Expand Up @@ -95,17 +96,19 @@ - (MASConstraint *)addConstraintWithAttributes:(MASAttribute)attrs {
NSAssert((attrs & anyAttribute) != 0, @"You didn't pass any attribute to make.attributes(...)");

NSMutableArray *attributes = [NSMutableArray array];

#define layoutItem (self.item ?: self.view)

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 & MASAttributeLeft) [attributes addObject:layoutItem.mas_left];
if (attrs & MASAttributeRight) [attributes addObject:layoutItem.mas_right];
if (attrs & MASAttributeTop) [attributes addObject:layoutItem.mas_top];
if (attrs & MASAttributeBottom) [attributes addObject:layoutItem.mas_bottom];
if (attrs & MASAttributeLeading) [attributes addObject:layoutItem.mas_leading];
if (attrs & MASAttributeTrailing) [attributes addObject:layoutItem.mas_trailing];
if (attrs & MASAttributeWidth) [attributes addObject:layoutItem.mas_width];
if (attrs & MASAttributeHeight) [attributes addObject:layoutItem.mas_height];
if (attrs & MASAttributeCenterX) [attributes addObject:layoutItem.mas_centerX];
if (attrs & MASAttributeCenterY) [attributes addObject:layoutItem.mas_centerY];
if (attrs & MASAttributeBaseline) [attributes addObject:self.view.mas_baseline];
if (attrs & MASAttributeFirstBaseline) [attributes addObject:self.view.mas_firstBaseline];
if (attrs & MASAttributeLastBaseline) [attributes addObject:self.view.mas_lastBaseline];
Expand Down

0 comments on commit e983a38

Please sign in to comment.