From 8d5442b83f523ee5c85064a042da3ed46bff06cc Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 13 May 2016 13:28:20 -0400 Subject: [PATCH] =?UTF-8?q?Fixed=20the=20last=20remaining=20edge=20cases.?= =?UTF-8?q?=20We're=20done!=20Auto=20Layout=20works~=20=E2=99=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- darwin/box.m | 4 ---- darwin/group.m | 12 ++++++++++-- darwin/tab.m | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/darwin/box.m b/darwin/box.m index 5a35ff04..0c05d070 100644 --- a/darwin/box.m +++ b/darwin/box.m @@ -1,10 +1,6 @@ // 15 august 2015 #import "uipriv_darwin.h" -// TODOs: -// - tab on page 2 doesn't grow (groupbox does instead) -// - page 3 doesn't work right; probably due to our shouldExpand logic being applied incorrectly - // TODOs to confirm // - 10.8: if we switch to page 4, then switch back to page 1, check Spaced, and go back to page 4, some controls (progress bar, popup button) are clipped on the sides diff --git a/darwin/group.m b/darwin/group.m index fd6e65e9..6a2cbe62 100644 --- a/darwin/group.m +++ b/darwin/group.m @@ -7,6 +7,8 @@ struct uiGroup { uiDarwinControl c; NSBox *box; uiControl *child; + NSLayoutPriority oldHorzHuggingPri; + NSLayoutPriority oldVertHuggingPri; int margined; struct singleChildConstraints constraints; NSLayoutPriority horzHuggingPri; @@ -135,9 +137,10 @@ void uiGroupSetChild(uiGroup *g, uiControl *child) if (g->child != NULL) { removeConstraints(g); - childView = (NSView *) uiControlHandle(g->child); - [childView removeFromSuperview]; + uiDarwinControlSetHuggingPriority(uiDarwinControl(g->child), g->oldHorzHuggingPri, NSLayoutConstraintOrientationHorizontal); + uiDarwinControlSetHuggingPriority(uiDarwinControl(g->child), g->oldVertHuggingPri, NSLayoutConstraintOrientationVertical); uiControlSetParent(g->child, NULL); + uiDarwinControlSetSuperview(uiDarwinControl(g->child), nil); } g->child = child; if (g->child != NULL) { @@ -145,6 +148,11 @@ void uiGroupSetChild(uiGroup *g, uiControl *child) uiControlSetParent(g->child, uiControl(g)); uiDarwinControlSetSuperview(uiDarwinControl(g->child), [g->box contentView]); uiDarwinControlSyncEnableState(uiDarwinControl(g->child), uiControlEnabledToUser(uiControl(g))); + // don't hug, just in case we're a stretchy group + g->oldHorzHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(g->child), NSLayoutConstraintOrientationHorizontal); + g->oldVertHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(g->child), NSLayoutConstraintOrientationVertical); + uiDarwinControlSetHuggingPriority(uiDarwinControl(g->child), NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationHorizontal); + uiDarwinControlSetHuggingPriority(uiDarwinControl(g->child), NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationVertical); } groupRelayout(g); } diff --git a/darwin/tab.m b/darwin/tab.m index 325099a3..0e7a0d19 100644 --- a/darwin/tab.m +++ b/darwin/tab.m @@ -1,6 +1,9 @@ // 15 august 2015 #import "uipriv_darwin.h" +// TODOs +// - page 2 tab doesn't lay out properly at first; need to jiggle on page change too :S + @interface tabPage : NSObject { struct singleChildConstraints constraints; int margined; @@ -8,6 +11,8 @@ NSObject *pageID; } @property uiControl *c; +@property NSLayoutPriority oldHorzHuggingPri; +@property NSLayoutPriority oldVertHuggingPri; - (id)initWithView:(NSView *)v pageID:(NSObject *)o; - (NSView *)childView; - (void)establishChildConstraints; @@ -193,6 +198,13 @@ void uiTabInsertAt(uiTab *t, const char *name, uintmax_t n, uiControl *child) pageID = [NSObject new]; page = [[tabPage alloc] initWithView:view pageID:pageID]; page.c = child; + + // don't hug, just in case we're a stretchy tab + page.oldHorzHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(page.c), NSLayoutConstraintOrientationHorizontal); + page.oldVertHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(page.c), NSLayoutConstraintOrientationVertical); + uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationHorizontal); + uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), NSLayoutPriorityDefaultLow, NSLayoutConstraintOrientationVertical); + [t->pages insertObject:page atIndex:n]; [page release]; // no need for initial reference @@ -215,6 +227,10 @@ void uiTabDelete(uiTab *t, uintmax_t n) NSTabViewItem *i; page = (tabPage *) [t->pages objectAtIndex:n]; + + uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), page.oldHorzHuggingPri, NSLayoutConstraintOrientationHorizontal); + uiDarwinControlSetHuggingPriority(uiDarwinControl(page.c), page.oldVertHuggingPri, NSLayoutConstraintOrientationVertical); + child = page.c; [page removeChildConstraints]; [t->pages removeObjectAtIndex:n];