Revert "Undid all of that. There's an easier way..."
...that only works for nibs. :(
This reverts commit 0fa706b8d4
.
This commit is contained in:
parent
0fa706b8d4
commit
0fe5214c09
|
@ -20,10 +20,7 @@
|
||||||
NSLayoutConstraint *first;
|
NSLayoutConstraint *first;
|
||||||
NSMutableArray *inBetweens;
|
NSMutableArray *inBetweens;
|
||||||
NSLayoutConstraint *last;
|
NSLayoutConstraint *last;
|
||||||
NSMutableArray *widths;
|
NSMutableArray *hEdges;
|
||||||
NSMutableArray *leadings;
|
|
||||||
NSMutableArray *middles;
|
|
||||||
NSMutableArray *trailings;
|
|
||||||
}
|
}
|
||||||
- (id)initWithF:(uiForm *)ff;
|
- (id)initWithF:(uiForm *)ff;
|
||||||
- (void)onDestroy;
|
- (void)onDestroy;
|
||||||
|
@ -65,10 +62,7 @@ struct uiForm {
|
||||||
self->nStretchy = 0;
|
self->nStretchy = 0;
|
||||||
|
|
||||||
self->inBetweens = [NSMutableArray new];
|
self->inBetweens = [NSMutableArray new];
|
||||||
self->widths = [NSMutableArray new];
|
self->hEdges = [NSMutableArray new];
|
||||||
self->leadings = [NSMutableArray new];
|
|
||||||
self->middles = [NSMutableArray new];
|
|
||||||
self->trailings = [NSMutableArray new];
|
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -79,10 +73,7 @@ struct uiForm {
|
||||||
|
|
||||||
[self removeOurConstraints];
|
[self removeOurConstraints];
|
||||||
[self->inBetweens release];
|
[self->inBetweens release];
|
||||||
[self->widths release];
|
[self->hEdges release];
|
||||||
[self->leadings release];
|
|
||||||
[self->middles release];
|
|
||||||
[self->trailings release];
|
|
||||||
|
|
||||||
for (fc in self->children) {
|
for (fc in self->children) {
|
||||||
[self removeConstraint:fc.baseline];
|
[self removeConstraint:fc.baseline];
|
||||||
|
@ -112,21 +103,9 @@ struct uiForm {
|
||||||
[self->last release];
|
[self->last release];
|
||||||
self->last = nil;
|
self->last = nil;
|
||||||
}
|
}
|
||||||
if ([self->widths count] != 0) {
|
if ([self->hEdges count] != 0) {
|
||||||
[self removeConstraints:self->widths];
|
[self removeConstraints:self->hEdges];
|
||||||
[self->widths removeAllObjects];
|
[self->hEdges 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];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,81 +137,55 @@ struct uiForm {
|
||||||
return;
|
return;
|
||||||
padding = [self paddingAmount];
|
padding = [self paddingAmount];
|
||||||
|
|
||||||
// first arrange the children vertically and make them the same width
|
// first arrange the main controls vertically
|
||||||
prev = nil;
|
prev = nil;
|
||||||
for (fc in self->children) {
|
for (fc in self->children) {
|
||||||
if (prev == nil) { // first view
|
if (prev == nil) { // first control; tie to top
|
||||||
self->first = mkConstraint(self, NSLayoutAttributeTop,
|
self->first = mkConstraint(self, NSLayoutAttributeTop,
|
||||||
NSLayoutRelationEqual,
|
NSLayoutRelationEqual,
|
||||||
[fc view], NSLayoutAttributeTop,
|
[fc view], NSLayoutAttributeTop,
|
||||||
1, 0,
|
1, 0,
|
||||||
@"uiForm first vertical constraint");
|
@"uiForm first child top constraint");
|
||||||
[self addConstraint:self->first];
|
[self addConstraint:self->first];
|
||||||
[self->first retain];
|
[self->first retain];
|
||||||
prev = [fc view];
|
prev = [fc view];
|
||||||
prevlabel = fc.label;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// not the first; link it
|
// not first; tie to previous
|
||||||
c = mkConstraint(prev, NSLayoutAttributeBottom,
|
c = mkConstraint(prev, NSLayoutAttributeBottom,
|
||||||
NSLayoutRelationEqual,
|
NSLayoutRelationEqual,
|
||||||
[fc view], NSLayoutAttributeTop,
|
[fc view], NSLayoutAttributeTop,
|
||||||
1, -padding,
|
1, -padding,
|
||||||
@"uiForm in-between vertical constraint");
|
@"uiForm middle vertical constraint");
|
||||||
[self addConstraint:c];
|
[self addConstraint:c];
|
||||||
[self->inBetweens addObject:c];
|
[self->inBetweens addObject:c];
|
||||||
// and make the same width
|
|
||||||
c = mkConstraint(prev, NSLayoutAttributeWidth,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
[fc view], NSLayoutAttributeWidth,
|
|
||||||
1, 0,
|
|
||||||
@"uiForm control width constraint");
|
|
||||||
[self addConstraint:c];
|
|
||||||
[self->widths addObject:c];
|
|
||||||
c = mkConstraint(prevlabel, NSLayoutAttributeWidth,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
fc.label, NSLayoutAttributeWidth,
|
|
||||||
1, 0,
|
|
||||||
@"uiForm label lwidth constraint");
|
|
||||||
[self addConstraint:c];
|
|
||||||
[self->widths addObject:c];
|
|
||||||
prev = [fc view];
|
prev = [fc view];
|
||||||
prevlabel = fc.label;
|
|
||||||
}
|
}
|
||||||
relation = NSLayoutRelationEqual;
|
// and the last one
|
||||||
if (self->nStretchy != 0)
|
|
||||||
relation = NSLayoutRelationLessThanOrEqual;
|
|
||||||
self->last = mkConstraint(prev, NSLayoutAttributeBottom,
|
self->last = mkConstraint(prev, NSLayoutAttributeBottom,
|
||||||
NSLayoutRelationEqual,
|
NSLayoutRelationEqual,
|
||||||
self, NSLayoutAttributeBottom,
|
self, NSLayoutAttributeBottom,
|
||||||
1, 0,
|
1, 0,
|
||||||
@"uiForm last vertical constraint");
|
@"uiForm last child bottom constraint");
|
||||||
[self addConstraint:self->last];
|
[self addConstraint:self->last];
|
||||||
[self->last retain];
|
[self->last retain];
|
||||||
|
|
||||||
// now arrange the controls horizontally
|
// now tiethe labels to the left (weakly, for right-alignment) and tie the controls to the right (strongly)
|
||||||
for (fc in self->children) {
|
for (fc in self->children) {
|
||||||
c = mkConstraint(self, NSLayoutAttributeLeading,
|
c = mkConstraint(self, NSLayoutAttributeLeading,
|
||||||
NSLayoutRelationEqual,
|
NSLayoutRelationLessThanOrEqual,
|
||||||
fc.label, NSLayoutAttributeLeading,
|
fc.label, NSLayoutAttributeLeading,
|
||||||
1, 0,
|
1, 0,
|
||||||
@"uiForm leading constraint");
|
@"uiForm label leading edge constraint");
|
||||||
[self addConstraint:c];
|
[self addConstraint:c];
|
||||||
[self->leadings addObject:c];
|
[self->hEdges addObject:c];
|
||||||
c = mkConstraint(fc.label, NSLayoutAttributeTrailing,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
[fc view], NSLayoutAttributeLeading,
|
|
||||||
1, -padding,
|
|
||||||
@"uiForm middle constraint");
|
|
||||||
[self addConstraint:c];
|
|
||||||
[self->middles addObject:c];
|
|
||||||
c = mkConstraint([fc view], NSLayoutAttributeTrailing,
|
c = mkConstraint([fc view], NSLayoutAttributeTrailing,
|
||||||
NSLayoutRelationEqual,
|
NSLayoutRelationEqual,
|
||||||
self, NSLayoutAttributeTrailing,
|
self, NSLayoutAttributeTrailing,
|
||||||
1, 0,
|
1, 0,
|
||||||
@"uiForm trailing constraint");
|
@"uiForm child trailing edge constraint");
|
||||||
[self addConstraint:c];
|
[self addConstraint:c];
|
||||||
[self->trailings addObject:c];
|
[self->hEdges addObject:c];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
// 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)
|
||||||
|
@ -249,6 +202,9 @@ struct uiForm {
|
||||||
fc.c = c;
|
fc.c = c;
|
||||||
fc.label = newLabel(label);
|
fc.label = newLabel(label);
|
||||||
[fc.label setTranslatesAutoresizingMaskIntoConstraints:NO];
|
[fc.label setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||||
|
// and make the label no larger than it needs to be
|
||||||
|
[fc.label setContentHuggingPriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationHorizontal];
|
||||||
|
[fc.label setContentHuggingPriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationVertical];
|
||||||
[self addSubview:fc.label];
|
[self addSubview:fc.label];
|
||||||
fc.stretchy = stretchy;
|
fc.stretchy = stretchy;
|
||||||
fc.oldHorzHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(fc.c), NSLayoutConstraintOrientationHorizontal);
|
fc.oldHorzHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(fc.c), NSLayoutConstraintOrientationHorizontal);
|
||||||
|
@ -311,8 +267,6 @@ struct uiForm {
|
||||||
padding = [self paddingAmount];
|
padding = [self paddingAmount];
|
||||||
for (c in self->inBetweens)
|
for (c in self->inBetweens)
|
||||||
[c setConstant:-padding];
|
[c setConstant:-padding];
|
||||||
for (c in self->middles)
|
|
||||||
[c setConstant:-padding];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)hugsTrailing
|
- (BOOL)hugsTrailing
|
||||||
|
|
Loading…
Reference in New Issue