Fixed the last remaining edge cases. We're done! Auto Layout works~ ♫

This commit is contained in:
Pietro Gagliardi 2016-05-13 13:28:20 -04:00
parent 8f55b7e331
commit 8d5442b83f
3 changed files with 26 additions and 6 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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];