Found a possible solution! Needs fine-tuning.

This commit is contained in:
Pietro Gagliardi 2016-05-08 02:54:08 -04:00
parent 2aef3031e3
commit 8867742ec0
1 changed files with 23 additions and 13 deletions

View File

@ -24,7 +24,7 @@
NSLayoutConstraint *first; NSLayoutConstraint *first;
NSMutableArray *inBetweens; NSMutableArray *inBetweens;
NSLayoutConstraint *last; NSLayoutConstraint *last, *last2;
NSMutableArray *otherConstraints; NSMutableArray *otherConstraints;
NSLayoutAttribute primaryStart; NSLayoutAttribute primaryStart;
@ -104,6 +104,7 @@ struct uiBox {
[self->first release]; [self->first release];
[self->inBetweens release]; [self->inBetweens release];
[self->last release]; [self->last release];
[self->last2 release];
[self->otherConstraints release]; [self->otherConstraints release];
n = [self->children count]; n = [self->children count];
@ -121,6 +122,7 @@ struct uiBox {
[self removeConstraint:self->first]; [self removeConstraint:self->first];
[self removeConstraints:self->inBetweens]; [self removeConstraints:self->inBetweens];
[self removeConstraint:self->last]; [self removeConstraint:self->last];
[self removeConstraint:self->last2];
[self removeConstraints:self->otherConstraints]; [self removeConstraints:self->otherConstraints];
} }
@ -152,7 +154,7 @@ struct uiBox {
CGFloat padding; CGFloat padding;
NSView *prev, *next; NSView *prev, *next;
NSLayoutConstraint *c; NSLayoutConstraint *c;
NSLayoutRelation relation; NSLayoutPriority priority;
[super updateConstraints]; [super updateConstraints];
[self removeOurConstraints]; [self removeOurConstraints];
@ -198,8 +200,22 @@ struct uiBox {
prev = next; prev = next;
} }
// and finally end the primary direction
self->last = mkConstraint(prev, self->primaryEnd,
NSLayoutRelationLessThanOrEqual,
self, self->primaryEnd,
1, 0,
@"uiBox last primary constraint");
[self addConstraint:self->last];
[self->last retain];
// if there is a stretchy control, add the no-stretchy view // if there is a stretchy control, add the no-stretchy view
relation = NSLayoutRelationEqual; self->last2 = mkConstraint(prev, self->primaryEnd,
NSLayoutRelationEqual,
self, self->primaryEnd,
1, 0,
@"uiBox last2 primary constraint");
priority = NSLayoutPriorityRequired;
if (!hasStretchy) { if (!hasStretchy) {
BOOL shouldExpand = NO; BOOL shouldExpand = NO;
uiControl *parent; uiControl *parent;
@ -211,17 +227,11 @@ struct uiBox {
else else
shouldExpand = uiDarwinControlChildrenShouldAllowSpaceAtTrailingEdge(uiDarwinControl(parent)); shouldExpand = uiDarwinControlChildrenShouldAllowSpaceAtTrailingEdge(uiDarwinControl(parent));
if (shouldExpand) if (shouldExpand)
relation = NSLayoutRelationLessThanOrEqual; priority = NSLayoutPriorityDefaultLow;
} }
[self->last2 setPriority:priority];
// and finally end the primary direction [self addConstraint:self->last2];
self->last = mkConstraint(prev, self->primaryEnd, [self->last2 retain];
relation,
self, self->primaryEnd,
1, 0,
@"uiBox last primary constraint");
[self addConstraint:self->last];
[self->last retain];
// next: assemble the views in the secondary direction // next: assemble the views in the secondary direction
// each of them will span the secondary direction // each of them will span the secondary direction