From 60c988100a61ef68d2af4792ea508bc0e5949a56 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 12 May 2016 11:57:32 -0400 Subject: [PATCH] Some more uiBox work. We've ALMOST got it; just a few more tweaks to get groupboxes and tabs right and to fix page 3... --- darwin/box.m | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/darwin/box.m b/darwin/box.m index 270d9b08..fe89b782 100644 --- a/darwin/box.m +++ b/darwin/box.m @@ -41,6 +41,7 @@ - (void)removeOurConstraints; - (void)syncEnableStates:(int)enabled; - (CGFloat)paddingAmount; +- (void)establishOurConstraints; - (void)append:(uiControl *)c stretchy:(int)stretchy; - (void)delete:(uintmax_t)n; - (int)isPadded; @@ -154,14 +155,16 @@ struct uiBox { } // TODO something about spinbox hugging -- (void)updateConstraints +- (void)establishOurConstraints { boxChild *bc; CGFloat padding; NSView *prev; NSLayoutConstraint *c; + NSLayoutRelation relation; + BOOL (*hugsSecondary)(uiDarwinControl *); - [super updateConstraints]; + [self removeOurConstraints]; if ([self->children count] == 0) return; padding = [self paddingAmount]; @@ -199,6 +202,9 @@ struct uiBox { [self->last retain]; // then arrange in the secondary direction + hugsSecondary = uiDarwinControlHugsTrailingEdge; + if (!self->vertical) + hugsSecondary = uiDarwinControlHugsBottom; for (bc in self->children) { c = mkConstraint(self, self->secondaryStart, NSLayoutRelationEqual, @@ -207,8 +213,11 @@ struct uiBox { @"uiBox secondary start constraint"); [self addConstraint:c]; [self->otherConstraints addObject:c]; + relation = NSLayoutRelationLessThanOrEqual; + if ((*hugsSecondary)(uiDarwinControl(bc.c))) + relation = NSLayoutRelationEqual; c = mkConstraint([bc view], self->secondaryEnd, - NSLayoutRelationEqual, + relation, self, self->secondaryEnd, 1, 0, @"uiBox secondary end constraint"); @@ -268,8 +277,7 @@ struct uiBox { [self->children addObject:bc]; - [self removeOurConstraints]; - [self setNeedsUpdateConstraints:YES]; + [self establishOurConstraints]; if (bc.stretchy) { oldnStretchy = self->nStretchy; self->nStretchy++; @@ -305,8 +313,7 @@ struct uiBox { [self->children removeObjectAtIndex:n]; - [self removeOurConstraints]; - [self setNeedsUpdateConstraints:YES]; + [self establishOurConstraints]; if (stretchy) { self->nStretchy--; if (self->nStretchy == 0) { @@ -402,8 +409,7 @@ static void uiBoxChildEdgeHuggingChanged(uiDarwinControl *c) { uiBox *b = uiBox(c); - [b->view removeOurConstraints]; - [b->view setNeedsUpdateConstraints:YES]; + [b->view establishOurConstraints]; } void uiBoxAppend(uiBox *b, uiControl *c, int stretchy)