Re-establishing uiForm constraints: vertical constraints.

This commit is contained in:
Pietro Gagliardi 2016-06-07 14:59:12 -04:00
parent 7f05b796aa
commit 95fcceef2f
1 changed files with 33 additions and 30 deletions

View File

@ -20,10 +20,6 @@
NSLayoutConstraint *first;
NSMutableArray *inBetweens;
NSLayoutConstraint *last;
NSMutableArray *widths;
NSMutableArray *leadings;
NSMutableArray *middles;
NSMutableArray *trailings;
}
- (id)initWithF:(uiForm *)ff;
- (void)onDestroy;
@ -65,10 +61,6 @@ struct uiForm {
self->nStretchy = 0;
self->inBetweens = [NSMutableArray new];
self->widths = [NSMutableArray new];
self->leadings = [NSMutableArray new];
self->middles = [NSMutableArray new];
self->trailings = [NSMutableArray new];
}
return self;
}
@ -79,10 +71,6 @@ struct uiForm {
[self removeOurConstraints];
[self->inBetweens release];
[self->widths release];
[self->leadings release];
[self->middles release];
[self->trailings release];
for (fc in self->children) {
[self removeConstraint:fc.baseline];
@ -112,22 +100,6 @@ struct uiForm {
[self->last release];
self->last = nil;
}
if ([self->widths count] != 0) {
[self removeConstraints:self->widths];
[self->widths removeAllObjects];
}
if ([self->leadings count] != 0) {
[self removeConstraints:self->leadings];
[self->leadings removeAllObjects];
}
if ([self->middles count] != 0) {
[self removeConstraints:self->middles];
[self->middles removeAllObjects];
}
if ([self->trailings count] != 0) {
[self removeConstraints:self->trailings];
[self->trailings removeAllObjects];
}
}
- (void)syncEnableStates:(int)enabled
@ -158,6 +130,39 @@ struct uiForm {
return;
padding = [self paddingAmount];
// first arrange the main controls vertically
prev = nil;
for (fc in self->children) {
if (prev == nil) { // first control; tie to top
self->first = mkConstraint(self, NSLayoutAttributeTop,
NSLayoutRelationEqual,
[fc view], NSLayoutAttributeTop,
1, 0,
@"uiForm first child top constraint");
[self addConstraint:self->first];
[self->first retain];
prev = [fc view];
continue;
}
// not first; tie to previous
c = mkConstraint(prev, NSLayoutAttributeBottom,
NSLayoutRelationEqual,
[fc view], NSLayoutAttributeTop,
1, -padding,
@"uiForm middle vertical constraint");
[self addConstraint:c];
[self->inBetweens addObject:c];
prev = [fc view];
}
// and the last one
self->last = mkConstraint(prev, NSLayoutAttributeBottom,
NSLayoutRelationEqual,
self, NSLayoutAttributeBottom,
1, 0,
@"uiForm last child bottom constraint");
[self addConstraint:self->last];
[self->last retain];
// we don't arrange the labels vertically; that's done when we add the control since those constraints don't need to change (they just need to be at their baseline)
}
@ -237,8 +242,6 @@ struct uiForm {
padding = [self paddingAmount];
for (c in self->inBetweens)
[c setConstant:-padding];
for (c in self->middles)
[c setConstant:-padding];
}
- (BOOL)hugsTrailing