Authored by Robert Payne
Committed by GitHub

Merge pull request #388 from iwill/master

Added inset property
@@ -129,6 +129,12 @@ @@ -129,6 +129,12 @@
129 } 129 }
130 } 130 }
131 131
  132 +- (void)setInset:(CGFloat)inset {
  133 + for (MASConstraint *constraint in self.childConstraints) {
  134 + constraint.inset = inset;
  135 + }
  136 +}
  137 +
132 - (void)setOffset:(CGFloat)offset { 138 - (void)setOffset:(CGFloat)offset {
133 for (MASConstraint *constraint in self.childConstraints) { 139 for (MASConstraint *constraint in self.childConstraints) {
134 constraint.offset = offset; 140 constraint.offset = offset;
@@ -27,6 +27,13 @@ @@ -27,6 +27,13 @@
27 /** 27 /**
28 * Modifies the NSLayoutConstraint constant, 28 * Modifies the NSLayoutConstraint constant,
29 * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 29 * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
  30 + * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
  31 + */
  32 +- (MASConstraint * (^)(CGFloat inset))inset;
  33 +
  34 +/**
  35 + * Modifies the NSLayoutConstraint constant,
  36 + * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
30 * NSLayoutAttributeWidth, NSLayoutAttributeHeight 37 * NSLayoutAttributeWidth, NSLayoutAttributeHeight
31 */ 38 */
32 - (MASConstraint * (^)(CGSize offset))sizeOffset; 39 - (MASConstraint * (^)(CGSize offset))sizeOffset;
@@ -166,6 +173,13 @@ @@ -166,6 +173,13 @@
166 /** 173 /**
167 * Modifies the NSLayoutConstraint constant, 174 * Modifies the NSLayoutConstraint constant,
168 * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following 175 * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
  176 + * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
  177 + */
  178 +- (void)setInset:(CGFloat)inset;
  179 +
  180 +/**
  181 + * Modifies the NSLayoutConstraint constant,
  182 + * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
169 * NSLayoutAttributeWidth, NSLayoutAttributeHeight 183 * NSLayoutAttributeWidth, NSLayoutAttributeHeight
170 */ 184 */
171 - (void)setSizeOffset:(CGSize)sizeOffset; 185 - (void)setSizeOffset:(CGSize)sizeOffset;
@@ -92,6 +92,13 @@ @@ -92,6 +92,13 @@
92 }; 92 };
93 } 93 }
94 94
  95 +- (MASConstraint * (^)(CGFloat))inset {
  96 + return ^id(CGFloat inset){
  97 + self.inset = inset;
  98 + return self;
  99 + };
  100 +}
  101 +
95 - (MASConstraint * (^)(CGSize))sizeOffset { 102 - (MASConstraint * (^)(CGSize))sizeOffset {
96 return ^id(CGSize offset) { 103 return ^id(CGSize offset) {
97 self.sizeOffset = offset; 104 self.sizeOffset = offset;
@@ -269,6 +276,8 @@ @@ -269,6 +276,8 @@
269 276
270 - (void)setInsets:(MASEdgeInsets __unused)insets { MASMethodNotImplemented(); } 277 - (void)setInsets:(MASEdgeInsets __unused)insets { MASMethodNotImplemented(); }
271 278
  279 +- (void)setInset:(CGFloat __unused)inset { MASMethodNotImplemented(); }
  280 +
272 - (void)setSizeOffset:(CGSize __unused)sizeOffset { MASMethodNotImplemented(); } 281 - (void)setSizeOffset:(CGSize __unused)sizeOffset { MASMethodNotImplemented(); }
273 282
274 - (void)setCenterOffset:(CGPoint __unused)centerOffset { MASMethodNotImplemented(); } 283 - (void)setCenterOffset:(CGPoint __unused)centerOffset { MASMethodNotImplemented(); }
@@ -254,6 +254,10 @@ static char kInstalledConstraintsKey; @@ -254,6 +254,10 @@ static char kInstalledConstraintsKey;
254 } 254 }
255 } 255 }
256 256
  257 +- (void)setInset:(CGFloat)inset {
  258 + [self setInsets:(MASEdgeInsets){.top = inset, .left = inset, .bottom = inset, .right = inset}];
  259 +}
  260 +
257 - (void)setOffset:(CGFloat)offset { 261 - (void)setOffset:(CGFloat)offset {
258 self.layoutConstant = offset; 262 self.layoutConstant = offset;
259 } 263 }
@@ -133,6 +133,28 @@ SpecBegin(MASCompositeConstraint) { @@ -133,6 +133,28 @@ SpecBegin(MASCompositeConstraint) {
133 expect([children[5] layoutConstant]).to.equal(0); 133 expect([children[5] layoutConstant]).to.equal(0);
134 }; 134 };
135 135
  136 +- (void)testModifyInsetOnAppropriateChildren {
  137 + NSArray *children = @[
  138 + [[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_right],
  139 + [[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_top],
  140 + [[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_bottom],
  141 + [[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_left],
  142 + [[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_baseline],
  143 + [[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_width],
  144 + ];
  145 + composite = [[MASCompositeConstraint alloc] initWithChildren:children];
  146 + composite.delegate = delegate;
  147 +
  148 + composite.with.inset(1);
  149 +
  150 + expect([children[0] layoutConstant]).to.equal(-1);
  151 + expect([children[1] layoutConstant]).to.equal(1);
  152 + expect([children[2] layoutConstant]).to.equal(-1);
  153 + expect([children[3] layoutConstant]).to.equal(1);
  154 + expect([children[4] layoutConstant]).to.equal(0);
  155 + expect([children[5] layoutConstant]).to.equal(0);
  156 +};
  157 +
136 - (void)testUninstall { 158 - (void)testUninstall {
137 NSArray *children = @[ 159 NSArray *children = @[
138 [[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_leading], 160 [[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_leading],