From 21f9b9666bd396600d14af01f2fa6ceaeaf8533f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 12 May 2016 01:49:00 -0400 Subject: [PATCH] Fixed more problems. --- darwin/autolayout.m | 16 ++++++++-------- darwin/box.m | 26 +++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/darwin/autolayout.m b/darwin/autolayout.m index f4488797..61cedf9a 100644 --- a/darwin/autolayout.m +++ b/darwin/autolayout.m @@ -35,14 +35,14 @@ void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *c c->leadingConstraint = mkConstraint(contentView, NSLayoutAttributeLeading, NSLayoutRelationEqual, childView, NSLayoutAttributeLeading, - 1, margin, + 1, -margin, [desc stringByAppendingString:@" leading constraint"]); [contentView addConstraint:c->leadingConstraint]; c->topConstraint = mkConstraint(contentView, NSLayoutAttributeTop, NSLayoutRelationEqual, childView, NSLayoutAttributeTop, - 1, margin, + 1, -margin, [desc stringByAppendingString:@" top constraint"]); [contentView addConstraint:c->topConstraint]; @@ -52,7 +52,7 @@ void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *c c->trailingConstraint = mkConstraint(contentView, NSLayoutAttributeTrailing, relation, childView, NSLayoutAttributeTrailing, - 1, -margin, + 1, margin, [desc stringByAppendingString:@" trailing constraint"]); [contentView addConstraint:c->trailingConstraint]; @@ -62,7 +62,7 @@ void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *c c->bottomConstraint = mkConstraint(contentView, NSLayoutAttributeBottom, relation, childView, NSLayoutAttributeBottom, - 1, -margin, + 1, margin, [desc stringByAppendingString:@" bottom constraint"]); [contentView addConstraint:c->bottomConstraint]; } @@ -97,11 +97,11 @@ void singleChildConstraintsSetMargined(struct singleChildConstraints *c, int mar margin = margins(margined); if (c->leadingConstraint != nil) - [c->leadingConstraint setConstant:margin]; + [c->leadingConstraint setConstant:-margin]; if (c->topConstraint != nil) - [c->topConstraint setConstant:margin]; + [c->topConstraint setConstant:-margin]; if (c->trailingConstraint != nil) - [c->trailingConstraint setConstant:-margin]; + [c->trailingConstraint setConstant:margin]; if (c->bottomConstraint != nil) - [c->bottomConstraint setConstant:-margin]; + [c->bottomConstraint setConstant:margin]; } diff --git a/darwin/box.m b/darwin/box.m index 4f5310a5..c9e81380 100644 --- a/darwin/box.m +++ b/darwin/box.m @@ -180,7 +180,7 @@ struct uiBox { c = mkConstraint(prev, self->primaryEnd, NSLayoutRelationEqual, [bc view], self->primaryStart, - 1, padding, + 1, -padding, @"uiBox in-between primary constraint"); [self addConstraint:c]; [self->inBetweens addObject:c]; @@ -201,16 +201,36 @@ struct uiBox { [bc view], self->secondaryStart, 1, 0, @"uiBox secondary start constraint"); + [self addConstraint:c]; [self->otherConstraints addObject:c]; c = mkConstraint([bc view], self->secondaryEnd, NSLayoutRelationEqual, self, self->secondaryEnd, 1, 0, @"uiBox secondary end constraint"); + [self addConstraint:c]; [self->otherConstraints addObject:c]; } - // TODO stretchies + // and make all stretchy controls the same size + if (self->nStretchy == 0) + return; + prev = nil; // first stretchy view + for (bc in self->children) { + if (!bc.stretchy) + continue; + if (prev == nil) { + prev = [bc view]; + continue; + } + c = mkConstraint(prev, self->primarySize, + NSLayoutRelationEqual, + [bc view], self->primarySize, + 1, 0, + @"uiBox stretchy size constraint"); + [self addConstraint:c]; + [self->otherConstraints addObject:c]; + } } - (void)append:(uiControl *)c stretchy:(int)stretchy @@ -309,7 +329,7 @@ struct uiBox { self->padded = p; padding = [self paddingAmount]; for (c in self->inBetweens) - [c setConstant:padding]; + [c setConstant:-padding]; // TODO call anything? }