diff --git a/darwin/form.m b/darwin/form.m index 56b1485b..eb3bb2e7 100644 --- a/darwin/form.m +++ b/darwin/form.m @@ -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