Migrated shared functions and types of autolayout.m.

This commit is contained in:
Pietro Gagliardi 2018-05-05 20:15:32 -04:00
parent eb28beff1b
commit b8fc9fa817
12 changed files with 94 additions and 93 deletions

View File

@ -1,19 +1,4 @@
// autolayout.m
extern NSLayoutConstraint *mkConstraint(id view1, NSLayoutAttribute attr1, NSLayoutRelation relation, id view2, NSLayoutAttribute attr2, CGFloat multiplier, CGFloat c, NSString *desc);
extern void jiggleViewLayout(NSView *view);
struct singleChildConstraints {
NSLayoutConstraint *leadingConstraint;
NSLayoutConstraint *topConstraint;
NSLayoutConstraint *trailingConstraintGreater;
NSLayoutConstraint *trailingConstraintEqual;
NSLayoutConstraint *bottomConstraintGreater;
NSLayoutConstraint *bottomConstraintEqual;
};
extern void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *contentView, NSView *childView, BOOL hugsTrailing, BOOL hugsBottom, int margined, NSString *desc);
extern void singleChildConstraintsRemove(struct singleChildConstraints *c, NSView *cv);
extern void singleChildConstraintsSetMargined(struct singleChildConstraints *c, int margined);
// area.m // area.m
extern int sendAreaEvents(NSEvent *); extern int sendAreaEvents(NSEvent *);

View File

@ -1,7 +1,7 @@
// 15 august 2015 // 15 august 2015
#import "uipriv_darwin.h" #import "uipriv_darwin.h"
NSLayoutConstraint *mkConstraint(id view1, NSLayoutAttribute attr1, NSLayoutRelation relation, id view2, NSLayoutAttribute attr2, CGFloat multiplier, CGFloat c, NSString *desc) NSLayoutConstraint *uiprivMkConstraint(id view1, NSLayoutAttribute attr1, NSLayoutRelation relation, id view2, NSLayoutAttribute attr2, CGFloat multiplier, CGFloat c, NSString *desc)
{ {
NSLayoutConstraint *constraint; NSLayoutConstraint *constraint;
@ -29,7 +29,7 @@ CGFloat uiDarwinPaddingAmount(void *reserved)
// this is needed for NSSplitView to work properly; see http://stackoverflow.com/questions/34574478/how-can-i-set-the-position-of-a-nssplitview-nowadays-setpositionofdivideratind (stal in irc.freenode.net/#macdev came up with the exact combination) // this is needed for NSSplitView to work properly; see http://stackoverflow.com/questions/34574478/how-can-i-set-the-position-of-a-nssplitview-nowadays-setpositionofdivideratind (stal in irc.freenode.net/#macdev came up with the exact combination)
// turns out it also works on NSTabView and NSBox too, possibly others! // turns out it also works on NSTabView and NSBox too, possibly others!
// and for bonus points, it even seems to fix unsatisfiable-constraint-autoresizing-mask issues with NSTabView and NSBox too!!! this is nuts // and for bonus points, it even seems to fix unsatisfiable-constraint-autoresizing-mask issues with NSTabView and NSBox too!!! this is nuts
void jiggleViewLayout(NSView *view) void uiprivJiggleViewLayout(NSView *view)
{ {
[view setNeedsLayout:YES]; [view setNeedsLayout:YES];
[view layoutSubtreeIfNeeded]; [view layoutSubtreeIfNeeded];
@ -42,13 +42,13 @@ static CGFloat margins(int margined)
return uiDarwinMarginAmount(NULL); return uiDarwinMarginAmount(NULL);
} }
void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *contentView, NSView *childView, BOOL hugsTrailing, BOOL hugsBottom, int margined, NSString *desc) void uiprivSingleChildConstraintsEstablish(uiprivSingleChildConstraints *c, NSView *contentView, NSView *childView, BOOL hugsTrailing, BOOL hugsBottom, int margined, NSString *desc)
{ {
CGFloat margin; CGFloat margin;
margin = margins(margined); margin = margins(margined);
c->leadingConstraint = mkConstraint(contentView, NSLayoutAttributeLeading, c->leadingConstraint = uiprivMkConstraint(contentView, NSLayoutAttributeLeading,
NSLayoutRelationEqual, NSLayoutRelationEqual,
childView, NSLayoutAttributeLeading, childView, NSLayoutAttributeLeading,
1, -margin, 1, -margin,
@ -56,7 +56,7 @@ void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *c
[contentView addConstraint:c->leadingConstraint]; [contentView addConstraint:c->leadingConstraint];
[c->leadingConstraint retain]; [c->leadingConstraint retain];
c->topConstraint = mkConstraint(contentView, NSLayoutAttributeTop, c->topConstraint = uiprivMkConstraint(contentView, NSLayoutAttributeTop,
NSLayoutRelationEqual, NSLayoutRelationEqual,
childView, NSLayoutAttributeTop, childView, NSLayoutAttributeTop,
1, -margin, 1, -margin,
@ -64,7 +64,7 @@ void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *c
[contentView addConstraint:c->topConstraint]; [contentView addConstraint:c->topConstraint];
[c->topConstraint retain]; [c->topConstraint retain];
c->trailingConstraintGreater = mkConstraint(contentView, NSLayoutAttributeTrailing, c->trailingConstraintGreater = uiprivMkConstraint(contentView, NSLayoutAttributeTrailing,
NSLayoutRelationGreaterThanOrEqual, NSLayoutRelationGreaterThanOrEqual,
childView, NSLayoutAttributeTrailing, childView, NSLayoutAttributeTrailing,
1, margin, 1, margin,
@ -74,7 +74,7 @@ void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *c
[contentView addConstraint:c->trailingConstraintGreater]; [contentView addConstraint:c->trailingConstraintGreater];
[c->trailingConstraintGreater retain]; [c->trailingConstraintGreater retain];
c->trailingConstraintEqual = mkConstraint(contentView, NSLayoutAttributeTrailing, c->trailingConstraintEqual = uiprivMkConstraint(contentView, NSLayoutAttributeTrailing,
NSLayoutRelationEqual, NSLayoutRelationEqual,
childView, NSLayoutAttributeTrailing, childView, NSLayoutAttributeTrailing,
1, margin, 1, margin,
@ -84,7 +84,7 @@ void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *c
[contentView addConstraint:c->trailingConstraintEqual]; [contentView addConstraint:c->trailingConstraintEqual];
[c->trailingConstraintEqual retain]; [c->trailingConstraintEqual retain];
c->bottomConstraintGreater = mkConstraint(contentView, NSLayoutAttributeBottom, c->bottomConstraintGreater = uiprivMkConstraint(contentView, NSLayoutAttributeBottom,
NSLayoutRelationGreaterThanOrEqual, NSLayoutRelationGreaterThanOrEqual,
childView, NSLayoutAttributeBottom, childView, NSLayoutAttributeBottom,
1, margin, 1, margin,
@ -94,7 +94,7 @@ void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *c
[contentView addConstraint:c->bottomConstraintGreater]; [contentView addConstraint:c->bottomConstraintGreater];
[c->bottomConstraintGreater retain]; [c->bottomConstraintGreater retain];
c->bottomConstraintEqual = mkConstraint(contentView, NSLayoutAttributeBottom, c->bottomConstraintEqual = uiprivMkConstraint(contentView, NSLayoutAttributeBottom,
NSLayoutRelationEqual, NSLayoutRelationEqual,
childView, NSLayoutAttributeBottom, childView, NSLayoutAttributeBottom,
1, margin, 1, margin,
@ -105,7 +105,7 @@ void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *c
[c->bottomConstraintEqual retain]; [c->bottomConstraintEqual retain];
} }
void singleChildConstraintsRemove(struct singleChildConstraints *c, NSView *cv) void uiprivSingleChildConstraintsRemove(uiprivSingleChildConstraints *c, NSView *cv)
{ {
if (c->leadingConstraint != nil) { if (c->leadingConstraint != nil) {
[cv removeConstraint:c->leadingConstraint]; [cv removeConstraint:c->leadingConstraint];
@ -139,7 +139,7 @@ void singleChildConstraintsRemove(struct singleChildConstraints *c, NSView *cv)
} }
} }
void singleChildConstraintsSetMargined(struct singleChildConstraints *c, int margined) void uiprivSingleChildConstraintsSetMargined(uiprivSingleChildConstraints *c, int margined)
{ {
CGFloat margin; CGFloat margin;

View File

@ -167,7 +167,7 @@ struct uiBox {
if (!uiControlVisible(bc.c)) if (!uiControlVisible(bc.c))
continue; continue;
if (prev == nil) { // first view if (prev == nil) { // first view
self->first = mkConstraint(self, self->primaryStart, self->first = uiprivMkConstraint(self, self->primaryStart,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[bc view], self->primaryStart, [bc view], self->primaryStart,
1, 0, 1, 0,
@ -178,7 +178,7 @@ struct uiBox {
continue; continue;
} }
// not the first; link it // not the first; link it
c = mkConstraint(prev, self->primaryEnd, c = uiprivMkConstraint(prev, self->primaryEnd,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[bc view], self->primaryStart, [bc view], self->primaryStart,
1, -padding, 1, -padding,
@ -189,7 +189,7 @@ struct uiBox {
} }
if (prev == nil) // no control visible; act as if no controls if (prev == nil) // no control visible; act as if no controls
return; return;
self->last = mkConstraint(prev, self->primaryEnd, self->last = uiprivMkConstraint(prev, self->primaryEnd,
NSLayoutRelationEqual, NSLayoutRelationEqual,
self, self->primaryEnd, self, self->primaryEnd,
1, 0, 1, 0,
@ -204,14 +204,14 @@ struct uiBox {
for (bc in self->children) { for (bc in self->children) {
if (!uiControlVisible(bc.c)) if (!uiControlVisible(bc.c))
continue; continue;
c = mkConstraint(self, self->secondaryStart, c = uiprivMkConstraint(self, self->secondaryStart,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[bc view], self->secondaryStart, [bc view], self->secondaryStart,
1, 0, 1, 0,
@"uiBox secondary start constraint"); @"uiBox secondary start constraint");
[self addConstraint:c]; [self addConstraint:c];
[self->otherConstraints addObject:c]; [self->otherConstraints addObject:c];
c = mkConstraint([bc view], self->secondaryEnd, c = uiprivMkConstraint([bc view], self->secondaryEnd,
NSLayoutRelationLessThanOrEqual, NSLayoutRelationLessThanOrEqual,
self, self->secondaryEnd, self, self->secondaryEnd,
1, 0, 1, 0,
@ -220,7 +220,7 @@ struct uiBox {
[c setPriority:NSLayoutPriorityDefaultLow]; [c setPriority:NSLayoutPriorityDefaultLow];
[self addConstraint:c]; [self addConstraint:c];
[self->otherConstraints addObject:c]; [self->otherConstraints addObject:c];
c = mkConstraint([bc view], self->secondaryEnd, c = uiprivMkConstraint([bc view], self->secondaryEnd,
NSLayoutRelationEqual, NSLayoutRelationEqual,
self, self->secondaryEnd, self, self->secondaryEnd,
1, 0, 1, 0,
@ -244,7 +244,7 @@ struct uiBox {
prev = [bc view]; prev = [bc view];
continue; continue;
} }
c = mkConstraint(prev, self->primarySize, c = uiprivMkConstraint(prev, self->primarySize,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[bc view], self->primarySize, [bc view], self->primarySize,
1, 0, 1, 0,

View File

@ -66,25 +66,25 @@ struct uiForm {
[self.label setContentCompressionResistancePriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationVertical]; [self.label setContentCompressionResistancePriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationVertical];
[self addSubview:self.label]; [self addSubview:self.label];
self.leading = mkConstraint(self.label, NSLayoutAttributeLeading, self.leading = uiprivMkConstraint(self.label, NSLayoutAttributeLeading,
NSLayoutRelationGreaterThanOrEqual, NSLayoutRelationGreaterThanOrEqual,
self, NSLayoutAttributeLeading, self, NSLayoutAttributeLeading,
1, 0, 1, 0,
@"uiForm label leading"); @"uiForm label leading");
[self addConstraint:self.leading]; [self addConstraint:self.leading];
self.top = mkConstraint(self.label, NSLayoutAttributeTop, self.top = uiprivMkConstraint(self.label, NSLayoutAttributeTop,
NSLayoutRelationEqual, NSLayoutRelationEqual,
self, NSLayoutAttributeTop, self, NSLayoutAttributeTop,
1, 0, 1, 0,
@"uiForm label top"); @"uiForm label top");
[self addConstraint:self.top]; [self addConstraint:self.top];
self.trailing = mkConstraint(self.label, NSLayoutAttributeTrailing, self.trailing = uiprivMkConstraint(self.label, NSLayoutAttributeTrailing,
NSLayoutRelationEqual, NSLayoutRelationEqual,
self, NSLayoutAttributeTrailing, self, NSLayoutAttributeTrailing,
1, 0, 1, 0,
@"uiForm label trailing"); @"uiForm label trailing");
[self addConstraint:self.trailing]; [self addConstraint:self.trailing];
self.bottom = mkConstraint(self.label, NSLayoutAttributeBottom, self.bottom = uiprivMkConstraint(self.label, NSLayoutAttributeBottom,
NSLayoutRelationEqual, NSLayoutRelationEqual,
self, NSLayoutAttributeBottom, self, NSLayoutAttributeBottom,
1, 0, 1, 0,
@ -224,7 +224,7 @@ struct uiForm {
if (!uiControlVisible(fc.c)) if (!uiControlVisible(fc.c))
continue; continue;
if (prev == nil) { // first view if (prev == nil) { // first view
self->first = mkConstraint(self, NSLayoutAttributeTop, self->first = uiprivMkConstraint(self, NSLayoutAttributeTop,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[fc view], NSLayoutAttributeTop, [fc view], NSLayoutAttributeTop,
1, 0, 1, 0,
@ -236,7 +236,7 @@ struct uiForm {
continue; continue;
} }
// not the first; link it // not the first; link it
c = mkConstraint(prev, NSLayoutAttributeBottom, c = uiprivMkConstraint(prev, NSLayoutAttributeBottom,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[fc view], NSLayoutAttributeTop, [fc view], NSLayoutAttributeTop,
1, -padding, 1, -padding,
@ -244,14 +244,14 @@ struct uiForm {
[self addConstraint:c]; [self addConstraint:c];
[self->inBetweens addObject:c]; [self->inBetweens addObject:c];
// and make the same width // and make the same width
c = mkConstraint(prev, NSLayoutAttributeWidth, c = uiprivMkConstraint(prev, NSLayoutAttributeWidth,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[fc view], NSLayoutAttributeWidth, [fc view], NSLayoutAttributeWidth,
1, 0, 1, 0,
@"uiForm control width constraint"); @"uiForm control width constraint");
[self addConstraint:c]; [self addConstraint:c];
[self->widths addObject:c]; [self->widths addObject:c];
c = mkConstraint(prevlabel, NSLayoutAttributeWidth, c = uiprivMkConstraint(prevlabel, NSLayoutAttributeWidth,
NSLayoutRelationEqual, NSLayoutRelationEqual,
fc, NSLayoutAttributeWidth, fc, NSLayoutAttributeWidth,
1, 0, 1, 0,
@ -263,7 +263,7 @@ struct uiForm {
} }
if (prev == nil) // all hidden; act as if nothing there if (prev == nil) // all hidden; act as if nothing there
return; return;
self->last = mkConstraint(prev, NSLayoutAttributeBottom, self->last = uiprivMkConstraint(prev, NSLayoutAttributeBottom,
NSLayoutRelationEqual, NSLayoutRelationEqual,
self, NSLayoutAttributeBottom, self, NSLayoutAttributeBottom,
1, 0, 1, 0,
@ -275,7 +275,7 @@ struct uiForm {
for (fc in self->children) { for (fc in self->children) {
if (!uiControlVisible(fc.c)) if (!uiControlVisible(fc.c))
continue; continue;
c = mkConstraint(self, NSLayoutAttributeLeading, c = uiprivMkConstraint(self, NSLayoutAttributeLeading,
NSLayoutRelationEqual, NSLayoutRelationEqual,
fc, NSLayoutAttributeLeading, fc, NSLayoutAttributeLeading,
1, 0, 1, 0,
@ -284,7 +284,7 @@ struct uiForm {
[self->leadings addObject:c]; [self->leadings addObject:c];
// coerce the control to be as wide as possible // coerce the control to be as wide as possible
// see http://stackoverflow.com/questions/37710892/in-auto-layout-i-set-up-labels-that-shouldnt-grow-horizontally-and-controls-th // see http://stackoverflow.com/questions/37710892/in-auto-layout-i-set-up-labels-that-shouldnt-grow-horizontally-and-controls-th
c = mkConstraint(self, NSLayoutAttributeLeading, c = uiprivMkConstraint(self, NSLayoutAttributeLeading,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[fc view], NSLayoutAttributeLeading, [fc view], NSLayoutAttributeLeading,
1, 0, 1, 0,
@ -292,14 +292,14 @@ struct uiForm {
[c setPriority:NSLayoutPriorityDefaultHigh]; [c setPriority:NSLayoutPriorityDefaultHigh];
[self addConstraint:c]; [self addConstraint:c];
[self->leadings addObject:c]; [self->leadings addObject:c];
c = mkConstraint(fc, NSLayoutAttributeTrailing, c = uiprivMkConstraint(fc, NSLayoutAttributeTrailing,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[fc view], NSLayoutAttributeLeading, [fc view], NSLayoutAttributeLeading,
1, -padding, 1, -padding,
@"uiForm middle constraint"); @"uiForm middle constraint");
[self addConstraint:c]; [self addConstraint:c];
[self->middles addObject:c]; [self->middles addObject:c];
c = mkConstraint([fc view], NSLayoutAttributeTrailing, c = uiprivMkConstraint([fc view], NSLayoutAttributeTrailing,
NSLayoutRelationEqual, NSLayoutRelationEqual,
self, NSLayoutAttributeTrailing, self, NSLayoutAttributeTrailing,
1, 0, 1, 0,
@ -307,7 +307,7 @@ struct uiForm {
[self addConstraint:c]; [self addConstraint:c];
[self->trailings addObject:c]; [self->trailings addObject:c];
// TODO // TODO
c = mkConstraint(fc, NSLayoutAttributeBottom, c = uiprivMkConstraint(fc, NSLayoutAttributeBottom,
NSLayoutRelationLessThanOrEqual, NSLayoutRelationLessThanOrEqual,
self, NSLayoutAttributeBottom, self, NSLayoutAttributeBottom,
1, 0, 1, 0,
@ -327,7 +327,7 @@ struct uiForm {
prev = [fc view]; prev = [fc view];
continue; continue;
} }
c = mkConstraint([fc view], NSLayoutAttributeHeight, c = uiprivMkConstraint([fc view], NSLayoutAttributeHeight,
NSLayoutRelationEqual, NSLayoutRelationEqual,
prev, NSLayoutAttributeHeight, prev, NSLayoutAttributeHeight,
1, 0, 1, 0,
@ -376,7 +376,7 @@ struct uiForm {
attribute = NSLayoutAttributeBaseline; attribute = NSLayoutAttributeBaseline;
if ([[fc view] isKindOfClass:[NSScrollView class]]) if ([[fc view] isKindOfClass:[NSScrollView class]])
attribute = NSLayoutAttributeTop; attribute = NSLayoutAttributeTop;
fc.baseline = mkConstraint(fc.label, attribute, fc.baseline = uiprivMkConstraint(fc.label, attribute,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[fc view], attribute, [fc view], attribute,
1, 0, 1, 0,

View File

@ -72,7 +72,7 @@ struct uiGrid {
uiDarwinControlSyncEnableState(uiDarwinControl(self.c), uiControlEnabledToUser(uiControl(g))); uiDarwinControlSyncEnableState(uiDarwinControl(self.c), uiControlEnabledToUser(uiControl(g)));
if (self.halign == uiAlignStart || self.halign == uiAlignFill) { if (self.halign == uiAlignStart || self.halign == uiAlignFill) {
self.leadingc = mkConstraint(self, NSLayoutAttributeLeading, self.leadingc = uiprivMkConstraint(self, NSLayoutAttributeLeading,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[self view], NSLayoutAttributeLeading, [self view], NSLayoutAttributeLeading,
1, 0, 1, 0,
@ -80,7 +80,7 @@ struct uiGrid {
[self addConstraint:self.leadingc]; [self addConstraint:self.leadingc];
} }
if (self.halign == uiAlignCenter) { if (self.halign == uiAlignCenter) {
self.xcenterc = mkConstraint(self, NSLayoutAttributeCenterX, self.xcenterc = uiprivMkConstraint(self, NSLayoutAttributeCenterX,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[self view], NSLayoutAttributeCenterX, [self view], NSLayoutAttributeCenterX,
1, 0, 1, 0,
@ -88,7 +88,7 @@ struct uiGrid {
[self addConstraint:self.xcenterc]; [self addConstraint:self.xcenterc];
} }
if (self.halign == uiAlignEnd || self.halign == uiAlignFill) { if (self.halign == uiAlignEnd || self.halign == uiAlignFill) {
self.trailingc = mkConstraint(self, NSLayoutAttributeTrailing, self.trailingc = uiprivMkConstraint(self, NSLayoutAttributeTrailing,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[self view], NSLayoutAttributeTrailing, [self view], NSLayoutAttributeTrailing,
1, 0, 1, 0,
@ -97,7 +97,7 @@ struct uiGrid {
} }
if (self.valign == uiAlignStart || self.valign == uiAlignFill) { if (self.valign == uiAlignStart || self.valign == uiAlignFill) {
self.topc = mkConstraint(self, NSLayoutAttributeTop, self.topc = uiprivMkConstraint(self, NSLayoutAttributeTop,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[self view], NSLayoutAttributeTop, [self view], NSLayoutAttributeTop,
1, 0, 1, 0,
@ -105,7 +105,7 @@ struct uiGrid {
[self addConstraint:self.topc]; [self addConstraint:self.topc];
} }
if (self.valign == uiAlignCenter) { if (self.valign == uiAlignCenter) {
self.ycenterc = mkConstraint(self, NSLayoutAttributeCenterY, self.ycenterc = uiprivMkConstraint(self, NSLayoutAttributeCenterY,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[self view], NSLayoutAttributeCenterY, [self view], NSLayoutAttributeCenterY,
1, 0, 1, 0,
@ -113,7 +113,7 @@ struct uiGrid {
[self addConstraint:self.ycenterc]; [self addConstraint:self.ycenterc];
} }
if (self.valign == uiAlignEnd || self.valign == uiAlignFill) { if (self.valign == uiAlignEnd || self.valign == uiAlignFill) {
self.bottomc = mkConstraint(self, NSLayoutAttributeBottom, self.bottomc = uiprivMkConstraint(self, NSLayoutAttributeBottom,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[self view], NSLayoutAttributeBottom, [self view], NSLayoutAttributeBottom,
1, 0, 1, 0,
@ -403,14 +403,14 @@ struct uiGrid {
// now establish all the edge constraints // now establish all the edge constraints
// leading and trailing edges // leading and trailing edges
for (y = 0; y < ycount; y++) { for (y = 0; y < ycount; y++) {
c = mkConstraint(self, NSLayoutAttributeLeading, c = uiprivMkConstraint(self, NSLayoutAttributeLeading,
NSLayoutRelationEqual, NSLayoutRelationEqual,
gv[y][0], NSLayoutAttributeLeading, gv[y][0], NSLayoutAttributeLeading,
1, 0, 1, 0,
@"uiGrid leading edge constraint"); @"uiGrid leading edge constraint");
[self addConstraint:c]; [self addConstraint:c];
[self->edges addObject:c]; [self->edges addObject:c];
c = mkConstraint(self, NSLayoutAttributeTrailing, c = uiprivMkConstraint(self, NSLayoutAttributeTrailing,
NSLayoutRelationEqual, NSLayoutRelationEqual,
gv[y][xcount - 1], NSLayoutAttributeTrailing, gv[y][xcount - 1], NSLayoutAttributeTrailing,
1, 0, 1, 0,
@ -420,14 +420,14 @@ struct uiGrid {
} }
// top and bottom edges // top and bottom edges
for (x = 0; x < xcount; x++) { for (x = 0; x < xcount; x++) {
c = mkConstraint(self, NSLayoutAttributeTop, c = uiprivMkConstraint(self, NSLayoutAttributeTop,
NSLayoutRelationEqual, NSLayoutRelationEqual,
gv[0][x], NSLayoutAttributeTop, gv[0][x], NSLayoutAttributeTop,
1, 0, 1, 0,
@"uiGrid top edge constraint"); @"uiGrid top edge constraint");
[self addConstraint:c]; [self addConstraint:c];
[self->edges addObject:c]; [self->edges addObject:c];
c = mkConstraint(self, NSLayoutAttributeBottom, c = uiprivMkConstraint(self, NSLayoutAttributeBottom,
NSLayoutRelationEqual, NSLayoutRelationEqual,
gv[ycount - 1][x], NSLayoutAttributeBottom, gv[ycount - 1][x], NSLayoutAttributeBottom,
1, 0, 1, 0,
@ -446,7 +446,7 @@ struct uiGrid {
for (y++; y < ycount; y++) { for (y++; y < ycount; y++) {
if (gspan[y][x]) if (gspan[y][x])
continue; continue;
c = mkConstraint(gv[firsty][x], NSLayoutAttributeLeading, c = uiprivMkConstraint(gv[firsty][x], NSLayoutAttributeLeading,
NSLayoutRelationEqual, NSLayoutRelationEqual,
gv[y][x], NSLayoutAttributeLeading, gv[y][x], NSLayoutAttributeLeading,
1, 0, 1, 0,
@ -463,7 +463,7 @@ struct uiGrid {
for (x++; x < xcount; x++) { for (x++; x < xcount; x++) {
if (gspan[y][x]) if (gspan[y][x])
continue; continue;
c = mkConstraint(gv[y][firstx], NSLayoutAttributeTop, c = uiprivMkConstraint(gv[y][firstx], NSLayoutAttributeTop,
NSLayoutRelationEqual, NSLayoutRelationEqual,
gv[y][x], NSLayoutAttributeTop, gv[y][x], NSLayoutAttributeTop,
1, 0, 1, 0,
@ -477,7 +477,7 @@ struct uiGrid {
for (y = 0; y < ycount; y++) for (y = 0; y < ycount; y++)
for (x = 1; x < xcount; x++) for (x = 1; x < xcount; x++)
if (gv[y][x - 1] != gv[y][x]) { if (gv[y][x - 1] != gv[y][x]) {
c = mkConstraint(gv[y][x - 1], NSLayoutAttributeTrailing, c = uiprivMkConstraint(gv[y][x - 1], NSLayoutAttributeTrailing,
NSLayoutRelationEqual, NSLayoutRelationEqual,
gv[y][x], NSLayoutAttributeLeading, gv[y][x], NSLayoutAttributeLeading,
1, -padding, 1, -padding,
@ -488,7 +488,7 @@ struct uiGrid {
for (x = 0; x < xcount; x++) for (x = 0; x < xcount; x++)
for (y = 1; y < ycount; y++) for (y = 1; y < ycount; y++)
if (gv[y - 1][x] != gv[y][x]) { if (gv[y - 1][x] != gv[y][x]) {
c = mkConstraint(gv[y - 1][x], NSLayoutAttributeBottom, c = uiprivMkConstraint(gv[y - 1][x], NSLayoutAttributeBottom,
NSLayoutRelationEqual, NSLayoutRelationEqual,
gv[y][x], NSLayoutAttributeTop, gv[y][x], NSLayoutAttributeTop,
1, -padding, 1, -padding,

View File

@ -8,7 +8,7 @@ struct uiGroup {
NSLayoutPriority oldHorzHuggingPri; NSLayoutPriority oldHorzHuggingPri;
NSLayoutPriority oldVertHuggingPri; NSLayoutPriority oldVertHuggingPri;
int margined; int margined;
struct singleChildConstraints constraints; uiprivSingleChildConstraints constraints;
NSLayoutPriority horzHuggingPri; NSLayoutPriority horzHuggingPri;
NSLayoutPriority vertHuggingPri; NSLayoutPriority vertHuggingPri;
}; };
@ -16,7 +16,7 @@ struct uiGroup {
static void removeConstraints(uiGroup *g) static void removeConstraints(uiGroup *g)
{ {
// set to contentView instead of to the box itself, otherwise we get clipping underneath the label // set to contentView instead of to the box itself, otherwise we get clipping underneath the label
singleChildConstraintsRemove(&(g->constraints), [g->box contentView]); uiprivSingleChildConstraintsRemove(&(g->constraints), [g->box contentView]);
} }
static void uiGroupDestroy(uiControl *c) static void uiGroupDestroy(uiControl *c)
@ -64,14 +64,14 @@ static void groupRelayout(uiGroup *g)
if (g->child == NULL) if (g->child == NULL)
return; return;
childView = (NSView *) uiControlHandle(g->child); childView = (NSView *) uiControlHandle(g->child);
singleChildConstraintsEstablish(&(g->constraints), uiprivSingleChildConstraintsEstablish(&(g->constraints),
[g->box contentView], childView, [g->box contentView], childView,
uiDarwinControlHugsTrailingEdge(uiDarwinControl(g->child)), uiDarwinControlHugsTrailingEdge(uiDarwinControl(g->child)),
uiDarwinControlHugsBottom(uiDarwinControl(g->child)), uiDarwinControlHugsBottom(uiDarwinControl(g->child)),
g->margined, g->margined,
@"uiGroup"); @"uiGroup");
// needed for some very rare drawing errors... // needed for some very rare drawing errors...
jiggleViewLayout(g->box); uiprivJiggleViewLayout(g->box);
} }
// TODO rename these since I'm starting to get confused by what they mean by hugging // TODO rename these since I'm starting to get confused by what they mean by hugging
@ -168,7 +168,7 @@ int uiGroupMargined(uiGroup *g)
void uiGroupSetMargined(uiGroup *g, int margined) void uiGroupSetMargined(uiGroup *g, int margined)
{ {
g->margined = margined; g->margined = margined;
singleChildConstraintsSetMargined(&(g->constraints), g->margined); uiprivSingleChildConstraintsSetMargined(&(g->constraints), g->margined);
} }
uiGroup *uiNewGroup(const char *title) uiGroup *uiNewGroup(const char *title)

View File

@ -102,14 +102,14 @@ void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
[r->view addSubview:b]; [r->view addSubview:b];
// pin horizontally to the edges of the superview // pin horizontally to the edges of the superview
constraint = mkConstraint(b, NSLayoutAttributeLeading, constraint = uiprivMkConstraint(b, NSLayoutAttributeLeading,
NSLayoutRelationEqual, NSLayoutRelationEqual,
r->view, NSLayoutAttributeLeading, r->view, NSLayoutAttributeLeading,
1, 0, 1, 0,
@"uiRadioButtons button leading constraint"); @"uiRadioButtons button leading constraint");
[r->view addConstraint:constraint]; [r->view addConstraint:constraint];
[r->constraints addObject:constraint]; [r->constraints addObject:constraint];
constraint = mkConstraint(b, NSLayoutAttributeTrailing, constraint = uiprivMkConstraint(b, NSLayoutAttributeTrailing,
NSLayoutRelationEqual, NSLayoutRelationEqual,
r->view, NSLayoutAttributeTrailing, r->view, NSLayoutAttributeTrailing,
1, 0, 1, 0,
@ -120,14 +120,14 @@ void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
// if this is the first view, pin it to the top // if this is the first view, pin it to the top
// otherwise pin to the bottom of the last // otherwise pin to the bottom of the last
if ([r->buttons count] == 1) if ([r->buttons count] == 1)
constraint = mkConstraint(b, NSLayoutAttributeTop, constraint = uiprivMkConstraint(b, NSLayoutAttributeTop,
NSLayoutRelationEqual, NSLayoutRelationEqual,
r->view, NSLayoutAttributeTop, r->view, NSLayoutAttributeTop,
1, 0, 1, 0,
@"uiRadioButtons first button top constraint"); @"uiRadioButtons first button top constraint");
else { else {
b2 = buttonAt(r, [r->buttons count] - 2); b2 = buttonAt(r, [r->buttons count] - 2);
constraint = mkConstraint(b, NSLayoutAttributeTop, constraint = uiprivMkConstraint(b, NSLayoutAttributeTop,
NSLayoutRelationEqual, NSLayoutRelationEqual,
b2, NSLayoutAttributeBottom, b2, NSLayoutAttributeBottom,
1, 0, 1, 0,
@ -144,7 +144,7 @@ void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
} }
// and make the new bottom constraint // and make the new bottom constraint
r->lastv = mkConstraint(b, NSLayoutAttributeBottom, r->lastv = uiprivMkConstraint(b, NSLayoutAttributeBottom,
NSLayoutRelationEqual, NSLayoutRelationEqual,
r->view, NSLayoutAttributeBottom, r->view, NSLayoutAttributeBottom,
1, 0, 1, 0,

View File

@ -70,37 +70,37 @@ static CGFloat stepperYDelta(void)
[self addSubview:self->tf]; [self addSubview:self->tf];
[self addSubview:self->stepper]; [self addSubview:self->stepper];
[self addConstraint:mkConstraint(self->tf, NSLayoutAttributeLeading, [self addConstraint:uiprivMkConstraint(self->tf, NSLayoutAttributeLeading,
NSLayoutRelationEqual, NSLayoutRelationEqual,
self, NSLayoutAttributeLeading, self, NSLayoutAttributeLeading,
1, 0, 1, 0,
@"uiSpinbox left edge")]; @"uiSpinbox left edge")];
[self addConstraint:mkConstraint(self->stepper, NSLayoutAttributeTrailing, [self addConstraint:uiprivMkConstraint(self->stepper, NSLayoutAttributeTrailing,
NSLayoutRelationEqual, NSLayoutRelationEqual,
self, NSLayoutAttributeTrailing, self, NSLayoutAttributeTrailing,
1, 0, 1, 0,
@"uiSpinbox right edge")]; @"uiSpinbox right edge")];
[self addConstraint:mkConstraint(self->tf, NSLayoutAttributeTop, [self addConstraint:uiprivMkConstraint(self->tf, NSLayoutAttributeTop,
NSLayoutRelationEqual, NSLayoutRelationEqual,
self, NSLayoutAttributeTop, self, NSLayoutAttributeTop,
1, 0, 1, 0,
@"uiSpinbox top edge text field")]; @"uiSpinbox top edge text field")];
[self addConstraint:mkConstraint(self->tf, NSLayoutAttributeBottom, [self addConstraint:uiprivMkConstraint(self->tf, NSLayoutAttributeBottom,
NSLayoutRelationEqual, NSLayoutRelationEqual,
self, NSLayoutAttributeBottom, self, NSLayoutAttributeBottom,
1, 0, 1, 0,
@"uiSpinbox bottom edge text field")]; @"uiSpinbox bottom edge text field")];
[self addConstraint:mkConstraint(self->stepper, NSLayoutAttributeTop, [self addConstraint:uiprivMkConstraint(self->stepper, NSLayoutAttributeTop,
NSLayoutRelationEqual, NSLayoutRelationEqual,
self, NSLayoutAttributeTop, self, NSLayoutAttributeTop,
1, stepperYDelta(), 1, stepperYDelta(),
@"uiSpinbox top edge stepper")]; @"uiSpinbox top edge stepper")];
[self addConstraint:mkConstraint(self->stepper, NSLayoutAttributeBottom, [self addConstraint:uiprivMkConstraint(self->stepper, NSLayoutAttributeBottom,
NSLayoutRelationEqual, NSLayoutRelationEqual,
self, NSLayoutAttributeBottom, self, NSLayoutAttributeBottom,
1, stepperYDelta(), 1, stepperYDelta(),
@"uiSpinbox bottom edge stepper")]; @"uiSpinbox bottom edge stepper")];
[self addConstraint:mkConstraint(self->tf, NSLayoutAttributeTrailing, [self addConstraint:uiprivMkConstraint(self->tf, NSLayoutAttributeTrailing,
NSLayoutRelationEqual, NSLayoutRelationEqual,
self->stepper, NSLayoutAttributeLeading, self->stepper, NSLayoutAttributeLeading,
1, -3, // arbitrary amount; good enough visually (and it seems to match NSDatePicker too, at least on 10.11, which is even better) 1, -3, // arbitrary amount; good enough visually (and it seems to match NSDatePicker too, at least on 10.11, which is even better)

View File

@ -4,7 +4,7 @@
// TODO need to jiggle on tab change too (second page disabled tab label initially ambiguous) // TODO need to jiggle on tab change too (second page disabled tab label initially ambiguous)
@interface tabPage : NSObject { @interface tabPage : NSObject {
struct singleChildConstraints constraints; uiprivSingleChildConstraints constraints;
int margined; int margined;
NSView *view; // the NSTabViewItem view itself NSView *view; // the NSTabViewItem view itself
NSObject *pageID; NSObject *pageID;
@ -58,7 +58,7 @@ struct uiTab {
[self removeChildConstraints]; [self removeChildConstraints];
if (self.c == NULL) if (self.c == NULL)
return; return;
singleChildConstraintsEstablish(&(self->constraints), uiprivSingleChildConstraintsEstablish(&(self->constraints),
self->view, [self childView], self->view, [self childView],
uiDarwinControlHugsTrailingEdge(uiDarwinControl(self.c)), uiDarwinControlHugsTrailingEdge(uiDarwinControl(self.c)),
uiDarwinControlHugsBottom(uiDarwinControl(self.c)), uiDarwinControlHugsBottom(uiDarwinControl(self.c)),
@ -68,7 +68,7 @@ struct uiTab {
- (void)removeChildConstraints - (void)removeChildConstraints
{ {
singleChildConstraintsRemove(&(self->constraints), self->view); uiprivSingleChildConstraintsRemove(&(self->constraints), self->view);
} }
- (int)isMargined - (int)isMargined
@ -79,7 +79,7 @@ struct uiTab {
- (void)setMargined:(int)m - (void)setMargined:(int)m
{ {
self->margined = m; self->margined = m;
singleChildConstraintsSetMargined(&(self->constraints), self->margined); uiprivSingleChildConstraintsSetMargined(&(self->constraints), self->margined);
} }
@end @end
@ -136,7 +136,7 @@ static void tabRelayout(uiTab *t)
for (page in t->pages) for (page in t->pages)
[page establishChildConstraints]; [page establishChildConstraints];
// and this gets rid of some weird issues with regards to box alignment // and this gets rid of some weird issues with regards to box alignment
jiggleViewLayout(t->tabview); uiprivJiggleViewLayout(t->tabview);
} }
BOOL uiTabHugsTrailingEdge(uiDarwinControl *c) BOOL uiTabHugsTrailingEdge(uiDarwinControl *c)

View File

@ -87,4 +87,20 @@ extern NSMutableArray *uiprivDelegates;
extern void uiprivInitAlloc(void); extern void uiprivInitAlloc(void);
extern void uiprivUninitAlloc(void); extern void uiprivUninitAlloc(void);
// autolayout.m
extern NSLayoutConstraint *uiprivMkConstraint(id view1, NSLayoutAttribute attr1, NSLayoutRelation relation, id view2, NSLayoutAttribute attr2, CGFloat multiplier, CGFloat c, NSString *desc);
extern void uiprivJiggleViewLayout(NSView *view);
typedef struct uiprivSingleChildConstraints uiprivSingleChildConstraints;
struct uiprivSingleChildConstraints {
NSLayoutConstraint *leadingConstraint;
NSLayoutConstraint *topConstraint;
NSLayoutConstraint *trailingConstraintGreater;
NSLayoutConstraint *trailingConstraintEqual;
NSLayoutConstraint *bottomConstraintGreater;
NSLayoutConstraint *bottomConstraintEqual;
};
extern void uiprivSingleChildConstraintsEstablish(uiprivSingleChildConstraints *c, NSView *contentView, NSView *childView, BOOL hugsTrailing, BOOL hugsBottom, int margined, NSString *desc);
extern void uiprivSingleChildConstraintsRemove(uiprivSingleChildConstraints *c, NSView *cv);
extern void uiprivSingleChildConstraintsSetMargined(uiprivSingleChildConstraints *c, int margined);
#import "OLD_uipriv_darwin.h" #import "OLD_uipriv_darwin.h"

View File

@ -10,7 +10,7 @@ struct uiWindow {
int margined; int margined;
int (*onClosing)(uiWindow *, void *); int (*onClosing)(uiWindow *, void *);
void *onClosingData; void *onClosingData;
struct singleChildConstraints constraints; uiprivSingleChildConstraints constraints;
void (*onContentSizeChanged)(uiWindow *, void *); void (*onContentSizeChanged)(uiWindow *, void *);
void *onContentSizeChangedData; void *onContentSizeChangedData;
BOOL suppressSizeChanged; BOOL suppressSizeChanged;
@ -128,7 +128,7 @@ static void removeConstraints(uiWindow *w)
NSView *cv; NSView *cv;
cv = [w->window contentView]; cv = [w->window contentView];
singleChildConstraintsRemove(&(w->constraints), cv); uiprivSingleChildConstraintsRemove(&(w->constraints), cv);
} }
static void uiWindowDestroy(uiControl *c) static void uiWindowDestroy(uiControl *c)
@ -215,7 +215,7 @@ static void windowRelayout(uiWindow *w)
return; return;
childView = (NSView *) uiControlHandle(w->child); childView = (NSView *) uiControlHandle(w->child);
contentView = [w->window contentView]; contentView = [w->window contentView];
singleChildConstraintsEstablish(&(w->constraints), uiprivSingleChildConstraintsEstablish(&(w->constraints),
contentView, childView, contentView, childView,
uiDarwinControlHugsTrailingEdge(uiDarwinControl(w->child)), uiDarwinControlHugsTrailingEdge(uiDarwinControl(w->child)),
uiDarwinControlHugsBottom(uiDarwinControl(w->child)), uiDarwinControlHugsBottom(uiDarwinControl(w->child)),
@ -354,7 +354,7 @@ int uiWindowMargined(uiWindow *w)
void uiWindowSetMargined(uiWindow *w, int margined) void uiWindowSetMargined(uiWindow *w, int margined)
{ {
w->margined = margined; w->margined = margined;
singleChildConstraintsSetMargined(&(w->constraints), w->margined); uiprivSingleChildConstraintsSetMargined(&(w->constraints), w->margined);
} }
static int defaultOnClosing(uiWindow *w, void *data) static int defaultOnClosing(uiWindow *w, void *data)

View File

@ -90,14 +90,14 @@ static void minMaxAutoLayoutSizes(NSWindow *w, NSSize *min, NSSize *max)
// minimum: encourage the window to be as small as possible // minimum: encourage the window to be as small as possible
contentView = [w contentView]; contentView = [w contentView];
cw = mkConstraint(contentView, NSLayoutAttributeWidth, cw = uiprivMkConstraint(contentView, NSLayoutAttributeWidth,
NSLayoutRelationEqual, NSLayoutRelationEqual,
nil, NSLayoutAttributeNotAnAttribute, nil, NSLayoutAttributeNotAnAttribute,
0, 0, 0, 0,
@"window minimum width finding constraint"); @"window minimum width finding constraint");
[cw setPriority:NSLayoutPriorityDragThatCanResizeWindow]; [cw setPriority:NSLayoutPriorityDragThatCanResizeWindow];
[contentView addConstraint:cw]; [contentView addConstraint:cw];
ch = mkConstraint(contentView, NSLayoutAttributeHeight, ch = uiprivMkConstraint(contentView, NSLayoutAttributeHeight,
NSLayoutRelationEqual, NSLayoutRelationEqual,
nil, NSLayoutAttributeNotAnAttribute, nil, NSLayoutAttributeNotAnAttribute,
0, 0, 0, 0,
@ -110,14 +110,14 @@ static void minMaxAutoLayoutSizes(NSWindow *w, NSSize *min, NSSize *max)
// maximum: encourage the window to be as large as possible // maximum: encourage the window to be as large as possible
contentView = [w contentView]; contentView = [w contentView];
cw = mkConstraint(contentView, NSLayoutAttributeWidth, cw = uiprivMkConstraint(contentView, NSLayoutAttributeWidth,
NSLayoutRelationEqual, NSLayoutRelationEqual,
nil, NSLayoutAttributeNotAnAttribute, nil, NSLayoutAttributeNotAnAttribute,
0, CGFLOAT_MAX, 0, CGFLOAT_MAX,
@"window maximum width finding constraint"); @"window maximum width finding constraint");
[cw setPriority:NSLayoutPriorityDragThatCanResizeWindow]; [cw setPriority:NSLayoutPriorityDragThatCanResizeWindow];
[contentView addConstraint:cw]; [contentView addConstraint:cw];
ch = mkConstraint(contentView, NSLayoutAttributeHeight, ch = uiprivMkConstraint(contentView, NSLayoutAttributeHeight,
NSLayoutRelationEqual, NSLayoutRelationEqual,
nil, NSLayoutAttributeNotAnAttribute, nil, NSLayoutAttributeNotAnAttribute,
0, CGFLOAT_MAX, 0, CGFLOAT_MAX,