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
extern int sendAreaEvents(NSEvent *);

View File

@ -1,7 +1,7 @@
// 15 august 2015
#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;
@ -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)
// 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
void jiggleViewLayout(NSView *view)
void uiprivJiggleViewLayout(NSView *view)
{
[view setNeedsLayout:YES];
[view layoutSubtreeIfNeeded];
@ -42,13 +42,13 @@ static CGFloat margins(int margined)
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;
margin = margins(margined);
c->leadingConstraint = mkConstraint(contentView, NSLayoutAttributeLeading,
c->leadingConstraint = uiprivMkConstraint(contentView, NSLayoutAttributeLeading,
NSLayoutRelationEqual,
childView, NSLayoutAttributeLeading,
1, -margin,
@ -56,7 +56,7 @@ void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *c
[contentView addConstraint:c->leadingConstraint];
[c->leadingConstraint retain];
c->topConstraint = mkConstraint(contentView, NSLayoutAttributeTop,
c->topConstraint = uiprivMkConstraint(contentView, NSLayoutAttributeTop,
NSLayoutRelationEqual,
childView, NSLayoutAttributeTop,
1, -margin,
@ -64,7 +64,7 @@ void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *c
[contentView addConstraint:c->topConstraint];
[c->topConstraint retain];
c->trailingConstraintGreater = mkConstraint(contentView, NSLayoutAttributeTrailing,
c->trailingConstraintGreater = uiprivMkConstraint(contentView, NSLayoutAttributeTrailing,
NSLayoutRelationGreaterThanOrEqual,
childView, NSLayoutAttributeTrailing,
1, margin,
@ -74,7 +74,7 @@ void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *c
[contentView addConstraint:c->trailingConstraintGreater];
[c->trailingConstraintGreater retain];
c->trailingConstraintEqual = mkConstraint(contentView, NSLayoutAttributeTrailing,
c->trailingConstraintEqual = uiprivMkConstraint(contentView, NSLayoutAttributeTrailing,
NSLayoutRelationEqual,
childView, NSLayoutAttributeTrailing,
1, margin,
@ -84,7 +84,7 @@ void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *c
[contentView addConstraint:c->trailingConstraintEqual];
[c->trailingConstraintEqual retain];
c->bottomConstraintGreater = mkConstraint(contentView, NSLayoutAttributeBottom,
c->bottomConstraintGreater = uiprivMkConstraint(contentView, NSLayoutAttributeBottom,
NSLayoutRelationGreaterThanOrEqual,
childView, NSLayoutAttributeBottom,
1, margin,
@ -94,7 +94,7 @@ void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *c
[contentView addConstraint:c->bottomConstraintGreater];
[c->bottomConstraintGreater retain];
c->bottomConstraintEqual = mkConstraint(contentView, NSLayoutAttributeBottom,
c->bottomConstraintEqual = uiprivMkConstraint(contentView, NSLayoutAttributeBottom,
NSLayoutRelationEqual,
childView, NSLayoutAttributeBottom,
1, margin,
@ -105,7 +105,7 @@ void singleChildConstraintsEstablish(struct singleChildConstraints *c, NSView *c
[c->bottomConstraintEqual retain];
}
void singleChildConstraintsRemove(struct singleChildConstraints *c, NSView *cv)
void uiprivSingleChildConstraintsRemove(uiprivSingleChildConstraints *c, NSView *cv)
{
if (c->leadingConstraint != nil) {
[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;

View File

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

View File

@ -66,25 +66,25 @@ struct uiForm {
[self.label setContentCompressionResistancePriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationVertical];
[self addSubview:self.label];
self.leading = mkConstraint(self.label, NSLayoutAttributeLeading,
self.leading = uiprivMkConstraint(self.label, NSLayoutAttributeLeading,
NSLayoutRelationGreaterThanOrEqual,
self, NSLayoutAttributeLeading,
1, 0,
@"uiForm label leading");
[self addConstraint:self.leading];
self.top = mkConstraint(self.label, NSLayoutAttributeTop,
self.top = uiprivMkConstraint(self.label, NSLayoutAttributeTop,
NSLayoutRelationEqual,
self, NSLayoutAttributeTop,
1, 0,
@"uiForm label top");
[self addConstraint:self.top];
self.trailing = mkConstraint(self.label, NSLayoutAttributeTrailing,
self.trailing = uiprivMkConstraint(self.label, NSLayoutAttributeTrailing,
NSLayoutRelationEqual,
self, NSLayoutAttributeTrailing,
1, 0,
@"uiForm label trailing");
[self addConstraint:self.trailing];
self.bottom = mkConstraint(self.label, NSLayoutAttributeBottom,
self.bottom = uiprivMkConstraint(self.label, NSLayoutAttributeBottom,
NSLayoutRelationEqual,
self, NSLayoutAttributeBottom,
1, 0,
@ -224,7 +224,7 @@ struct uiForm {
if (!uiControlVisible(fc.c))
continue;
if (prev == nil) { // first view
self->first = mkConstraint(self, NSLayoutAttributeTop,
self->first = uiprivMkConstraint(self, NSLayoutAttributeTop,
NSLayoutRelationEqual,
[fc view], NSLayoutAttributeTop,
1, 0,
@ -236,7 +236,7 @@ struct uiForm {
continue;
}
// not the first; link it
c = mkConstraint(prev, NSLayoutAttributeBottom,
c = uiprivMkConstraint(prev, NSLayoutAttributeBottom,
NSLayoutRelationEqual,
[fc view], NSLayoutAttributeTop,
1, -padding,
@ -244,14 +244,14 @@ struct uiForm {
[self addConstraint:c];
[self->inBetweens addObject:c];
// and make the same width
c = mkConstraint(prev, NSLayoutAttributeWidth,
c = uiprivMkConstraint(prev, NSLayoutAttributeWidth,
NSLayoutRelationEqual,
[fc view], NSLayoutAttributeWidth,
1, 0,
@"uiForm control width constraint");
[self addConstraint:c];
[self->widths addObject:c];
c = mkConstraint(prevlabel, NSLayoutAttributeWidth,
c = uiprivMkConstraint(prevlabel, NSLayoutAttributeWidth,
NSLayoutRelationEqual,
fc, NSLayoutAttributeWidth,
1, 0,
@ -263,7 +263,7 @@ struct uiForm {
}
if (prev == nil) // all hidden; act as if nothing there
return;
self->last = mkConstraint(prev, NSLayoutAttributeBottom,
self->last = uiprivMkConstraint(prev, NSLayoutAttributeBottom,
NSLayoutRelationEqual,
self, NSLayoutAttributeBottom,
1, 0,
@ -275,7 +275,7 @@ struct uiForm {
for (fc in self->children) {
if (!uiControlVisible(fc.c))
continue;
c = mkConstraint(self, NSLayoutAttributeLeading,
c = uiprivMkConstraint(self, NSLayoutAttributeLeading,
NSLayoutRelationEqual,
fc, NSLayoutAttributeLeading,
1, 0,
@ -284,7 +284,7 @@ struct uiForm {
[self->leadings addObject:c];
// 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
c = mkConstraint(self, NSLayoutAttributeLeading,
c = uiprivMkConstraint(self, NSLayoutAttributeLeading,
NSLayoutRelationEqual,
[fc view], NSLayoutAttributeLeading,
1, 0,
@ -292,14 +292,14 @@ struct uiForm {
[c setPriority:NSLayoutPriorityDefaultHigh];
[self addConstraint:c];
[self->leadings addObject:c];
c = mkConstraint(fc, NSLayoutAttributeTrailing,
c = uiprivMkConstraint(fc, NSLayoutAttributeTrailing,
NSLayoutRelationEqual,
[fc view], NSLayoutAttributeLeading,
1, -padding,
@"uiForm middle constraint");
[self addConstraint:c];
[self->middles addObject:c];
c = mkConstraint([fc view], NSLayoutAttributeTrailing,
c = uiprivMkConstraint([fc view], NSLayoutAttributeTrailing,
NSLayoutRelationEqual,
self, NSLayoutAttributeTrailing,
1, 0,
@ -307,7 +307,7 @@ struct uiForm {
[self addConstraint:c];
[self->trailings addObject:c];
// TODO
c = mkConstraint(fc, NSLayoutAttributeBottom,
c = uiprivMkConstraint(fc, NSLayoutAttributeBottom,
NSLayoutRelationLessThanOrEqual,
self, NSLayoutAttributeBottom,
1, 0,
@ -327,7 +327,7 @@ struct uiForm {
prev = [fc view];
continue;
}
c = mkConstraint([fc view], NSLayoutAttributeHeight,
c = uiprivMkConstraint([fc view], NSLayoutAttributeHeight,
NSLayoutRelationEqual,
prev, NSLayoutAttributeHeight,
1, 0,
@ -376,7 +376,7 @@ struct uiForm {
attribute = NSLayoutAttributeBaseline;
if ([[fc view] isKindOfClass:[NSScrollView class]])
attribute = NSLayoutAttributeTop;
fc.baseline = mkConstraint(fc.label, attribute,
fc.baseline = uiprivMkConstraint(fc.label, attribute,
NSLayoutRelationEqual,
[fc view], attribute,
1, 0,

View File

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

View File

@ -8,7 +8,7 @@ struct uiGroup {
NSLayoutPriority oldHorzHuggingPri;
NSLayoutPriority oldVertHuggingPri;
int margined;
struct singleChildConstraints constraints;
uiprivSingleChildConstraints constraints;
NSLayoutPriority horzHuggingPri;
NSLayoutPriority vertHuggingPri;
};
@ -16,7 +16,7 @@ struct uiGroup {
static void removeConstraints(uiGroup *g)
{
// 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)
@ -64,14 +64,14 @@ static void groupRelayout(uiGroup *g)
if (g->child == NULL)
return;
childView = (NSView *) uiControlHandle(g->child);
singleChildConstraintsEstablish(&(g->constraints),
uiprivSingleChildConstraintsEstablish(&(g->constraints),
[g->box contentView], childView,
uiDarwinControlHugsTrailingEdge(uiDarwinControl(g->child)),
uiDarwinControlHugsBottom(uiDarwinControl(g->child)),
g->margined,
@"uiGroup");
// 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
@ -168,7 +168,7 @@ int uiGroupMargined(uiGroup *g)
void uiGroupSetMargined(uiGroup *g, int margined)
{
g->margined = margined;
singleChildConstraintsSetMargined(&(g->constraints), g->margined);
uiprivSingleChildConstraintsSetMargined(&(g->constraints), g->margined);
}
uiGroup *uiNewGroup(const char *title)

View File

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

View File

@ -70,37 +70,37 @@ static CGFloat stepperYDelta(void)
[self addSubview:self->tf];
[self addSubview:self->stepper];
[self addConstraint:mkConstraint(self->tf, NSLayoutAttributeLeading,
[self addConstraint:uiprivMkConstraint(self->tf, NSLayoutAttributeLeading,
NSLayoutRelationEqual,
self, NSLayoutAttributeLeading,
1, 0,
@"uiSpinbox left edge")];
[self addConstraint:mkConstraint(self->stepper, NSLayoutAttributeTrailing,
[self addConstraint:uiprivMkConstraint(self->stepper, NSLayoutAttributeTrailing,
NSLayoutRelationEqual,
self, NSLayoutAttributeTrailing,
1, 0,
@"uiSpinbox right edge")];
[self addConstraint:mkConstraint(self->tf, NSLayoutAttributeTop,
[self addConstraint:uiprivMkConstraint(self->tf, NSLayoutAttributeTop,
NSLayoutRelationEqual,
self, NSLayoutAttributeTop,
1, 0,
@"uiSpinbox top edge text field")];
[self addConstraint:mkConstraint(self->tf, NSLayoutAttributeBottom,
[self addConstraint:uiprivMkConstraint(self->tf, NSLayoutAttributeBottom,
NSLayoutRelationEqual,
self, NSLayoutAttributeBottom,
1, 0,
@"uiSpinbox bottom edge text field")];
[self addConstraint:mkConstraint(self->stepper, NSLayoutAttributeTop,
[self addConstraint:uiprivMkConstraint(self->stepper, NSLayoutAttributeTop,
NSLayoutRelationEqual,
self, NSLayoutAttributeTop,
1, stepperYDelta(),
@"uiSpinbox top edge stepper")];
[self addConstraint:mkConstraint(self->stepper, NSLayoutAttributeBottom,
[self addConstraint:uiprivMkConstraint(self->stepper, NSLayoutAttributeBottom,
NSLayoutRelationEqual,
self, NSLayoutAttributeBottom,
1, stepperYDelta(),
@"uiSpinbox bottom edge stepper")];
[self addConstraint:mkConstraint(self->tf, NSLayoutAttributeTrailing,
[self addConstraint:uiprivMkConstraint(self->tf, NSLayoutAttributeTrailing,
NSLayoutRelationEqual,
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)

View File

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

View File

@ -87,4 +87,20 @@ extern NSMutableArray *uiprivDelegates;
extern void uiprivInitAlloc(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"

View File

@ -10,7 +10,7 @@ struct uiWindow {
int margined;
int (*onClosing)(uiWindow *, void *);
void *onClosingData;
struct singleChildConstraints constraints;
uiprivSingleChildConstraints constraints;
void (*onContentSizeChanged)(uiWindow *, void *);
void *onContentSizeChangedData;
BOOL suppressSizeChanged;
@ -128,7 +128,7 @@ static void removeConstraints(uiWindow *w)
NSView *cv;
cv = [w->window contentView];
singleChildConstraintsRemove(&(w->constraints), cv);
uiprivSingleChildConstraintsRemove(&(w->constraints), cv);
}
static void uiWindowDestroy(uiControl *c)
@ -215,7 +215,7 @@ static void windowRelayout(uiWindow *w)
return;
childView = (NSView *) uiControlHandle(w->child);
contentView = [w->window contentView];
singleChildConstraintsEstablish(&(w->constraints),
uiprivSingleChildConstraintsEstablish(&(w->constraints),
contentView, childView,
uiDarwinControlHugsTrailingEdge(uiDarwinControl(w->child)),
uiDarwinControlHugsBottom(uiDarwinControl(w->child)),
@ -354,7 +354,7 @@ int uiWindowMargined(uiWindow *w)
void uiWindowSetMargined(uiWindow *w, int margined)
{
w->margined = margined;
singleChildConstraintsSetMargined(&(w->constraints), w->margined);
uiprivSingleChildConstraintsSetMargined(&(w->constraints), w->margined);
}
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
contentView = [w contentView];
cw = mkConstraint(contentView, NSLayoutAttributeWidth,
cw = uiprivMkConstraint(contentView, NSLayoutAttributeWidth,
NSLayoutRelationEqual,
nil, NSLayoutAttributeNotAnAttribute,
0, 0,
@"window minimum width finding constraint");
[cw setPriority:NSLayoutPriorityDragThatCanResizeWindow];
[contentView addConstraint:cw];
ch = mkConstraint(contentView, NSLayoutAttributeHeight,
ch = uiprivMkConstraint(contentView, NSLayoutAttributeHeight,
NSLayoutRelationEqual,
nil, NSLayoutAttributeNotAnAttribute,
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
contentView = [w contentView];
cw = mkConstraint(contentView, NSLayoutAttributeWidth,
cw = uiprivMkConstraint(contentView, NSLayoutAttributeWidth,
NSLayoutRelationEqual,
nil, NSLayoutAttributeNotAnAttribute,
0, CGFLOAT_MAX,
@"window maximum width finding constraint");
[cw setPriority:NSLayoutPriorityDragThatCanResizeWindow];
[contentView addConstraint:cw];
ch = mkConstraint(contentView, NSLayoutAttributeHeight,
ch = uiprivMkConstraint(contentView, NSLayoutAttributeHeight,
NSLayoutRelationEqual,
nil, NSLayoutAttributeNotAnAttribute,
0, CGFLOAT_MAX,