Nuked ALL the existing Auto Layout stuff. Let's do this again, and this time, do it *right*.
This commit is contained in:
parent
d110a836ba
commit
8fb8b0eeba
|
@ -17,139 +17,3 @@ NSLayoutConstraint *mkConstraint(id view1, NSLayoutAttribute attr1, NSLayoutRela
|
||||||
[((id) constraint) setIdentifier:desc];
|
[((id) constraint) setIdentifier:desc];
|
||||||
return constraint;
|
return constraint;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setHuggingPri(NSView *view, NSLayoutPriority priority, NSLayoutConstraintOrientation orientation)
|
|
||||||
{
|
|
||||||
[view setContentHuggingPriority:priority forOrientation:orientation];
|
|
||||||
}
|
|
||||||
|
|
||||||
NSLayoutPriority horzHuggingPri(NSView *view)
|
|
||||||
{
|
|
||||||
return [view contentHuggingPriorityForOrientation:NSLayoutConstraintOrientationHorizontal];
|
|
||||||
}
|
|
||||||
|
|
||||||
void setHorzHuggingPri(NSView *view, NSLayoutPriority priority)
|
|
||||||
{
|
|
||||||
[view setContentHuggingPriority:priority forOrientation:NSLayoutConstraintOrientationHorizontal];
|
|
||||||
}
|
|
||||||
|
|
||||||
NSLayoutPriority vertHuggingPri(NSView *view)
|
|
||||||
{
|
|
||||||
return [view contentHuggingPriorityForOrientation:NSLayoutConstraintOrientationVertical];
|
|
||||||
}
|
|
||||||
|
|
||||||
void setVertHuggingPri(NSView *view, NSLayoutPriority priority)
|
|
||||||
{
|
|
||||||
[view setContentHuggingPriority:priority forOrientation:NSLayoutConstraintOrientationVertical];
|
|
||||||
}
|
|
||||||
|
|
||||||
// precondition: subview is a subview of superview already
|
|
||||||
void layoutSingleView(NSView *superview, NSView *subview, int margined, NSString *desc)
|
|
||||||
{
|
|
||||||
NSLayoutConstraint *constraint;
|
|
||||||
CGFloat margin;
|
|
||||||
|
|
||||||
[superview removeConstraints:[superview constraints]];
|
|
||||||
|
|
||||||
// don't hug if needed (this fixes things like the Disabled Tab on Page 2 of the test program not being the one that resizes with the window
|
|
||||||
setHorzHuggingPri(subview, NSLayoutPriorityDefaultLow);
|
|
||||||
setVertHuggingPri(subview, NSLayoutPriorityDefaultLow);
|
|
||||||
|
|
||||||
margin = 0;
|
|
||||||
if (margined)
|
|
||||||
margin = 20; // TODO named constant
|
|
||||||
|
|
||||||
constraint = mkConstraint(subview, NSLayoutAttributeLeading,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
superview, NSLayoutAttributeLeading,
|
|
||||||
1, margin,
|
|
||||||
[desc stringByAppendingString:@" single child horizontal leading"]);
|
|
||||||
[superview addConstraint:constraint];
|
|
||||||
|
|
||||||
constraint = mkConstraint(superview, NSLayoutAttributeTrailing,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
subview, NSLayoutAttributeTrailing,
|
|
||||||
1, margin,
|
|
||||||
[desc stringByAppendingString:@" single child horizontal trailing"]);
|
|
||||||
[superview addConstraint:constraint];
|
|
||||||
|
|
||||||
constraint = mkConstraint(subview, NSLayoutAttributeTop,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
superview, NSLayoutAttributeTop,
|
|
||||||
1, margin,
|
|
||||||
[desc stringByAppendingString:@" single child top"]);
|
|
||||||
[superview addConstraint:constraint];
|
|
||||||
|
|
||||||
constraint = mkConstraint(superview, NSLayoutAttributeBottom,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
subview, NSLayoutAttributeBottom,
|
|
||||||
1, margin,
|
|
||||||
[desc stringByAppendingString:@" single child bottom"]);
|
|
||||||
[superview addConstraint:constraint];
|
|
||||||
}
|
|
||||||
|
|
||||||
// via https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithScrollViews.html#//apple_ref/doc/uid/TP40010853-CH24-SW1
|
|
||||||
NSMutableArray *layoutScrollViewContents(NSScrollView *sv, BOOL noHScroll, BOOL noVScroll, NSString *desc)
|
|
||||||
{
|
|
||||||
NSView *dv;
|
|
||||||
NSLayoutConstraint *constraint;
|
|
||||||
NSMutableArray *array;
|
|
||||||
|
|
||||||
dv = [sv documentView];
|
|
||||||
|
|
||||||
array = [NSMutableArray new];
|
|
||||||
|
|
||||||
constraint = mkConstraint(dv, NSLayoutAttributeLeading,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
sv, NSLayoutAttributeLeading,
|
|
||||||
1, 0,
|
|
||||||
[desc stringByAppendingString:@" scroll view horizontal leading"]);
|
|
||||||
[array addObject:constraint];
|
|
||||||
[sv addConstraint:constraint];
|
|
||||||
|
|
||||||
constraint = mkConstraint(dv, NSLayoutAttributeTrailing,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
sv, NSLayoutAttributeTrailing,
|
|
||||||
1, 0,
|
|
||||||
[desc stringByAppendingString:@" scroll view horizontal trailing"]);
|
|
||||||
[array addObject:constraint];
|
|
||||||
[sv addConstraint:constraint];
|
|
||||||
|
|
||||||
constraint = mkConstraint(dv, NSLayoutAttributeTop,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
sv, NSLayoutAttributeTop,
|
|
||||||
1, 0,
|
|
||||||
[desc stringByAppendingString:@" scroll view top"]);
|
|
||||||
[array addObject:constraint];
|
|
||||||
[sv addConstraint:constraint];
|
|
||||||
|
|
||||||
constraint = mkConstraint(dv, NSLayoutAttributeBottom,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
sv, NSLayoutAttributeBottom,
|
|
||||||
1, 0,
|
|
||||||
[desc stringByAppendingString:@" scroll view bottom"]);
|
|
||||||
[array addObject:constraint];
|
|
||||||
[sv addConstraint:constraint];
|
|
||||||
|
|
||||||
if (noHScroll) {
|
|
||||||
constraint = mkConstraint(dv, NSLayoutAttributeWidth,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
sv, NSLayoutAttributeWidth,
|
|
||||||
1, 0,
|
|
||||||
[desc stringByAppendingString:@" scroll view width"]);
|
|
||||||
[array addObject:constraint];
|
|
||||||
[sv addConstraint:constraint];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (noVScroll) {
|
|
||||||
constraint = mkConstraint(dv, NSLayoutAttributeHeight,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
sv, NSLayoutAttributeHeight,
|
|
||||||
1, 0,
|
|
||||||
[desc stringByAppendingString:@" scroll view height"]);
|
|
||||||
[array addObject:constraint];
|
|
||||||
[sv addConstraint:constraint];
|
|
||||||
}
|
|
||||||
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
219
darwin/box.m
219
darwin/box.m
|
@ -11,8 +11,10 @@
|
||||||
@interface boxChild : NSObject
|
@interface boxChild : NSObject
|
||||||
@property uiControl *c;
|
@property uiControl *c;
|
||||||
@property BOOL stretchy;
|
@property BOOL stretchy;
|
||||||
|
#if 0 /* TODO */
|
||||||
@property NSLayoutPriority oldHorzHuggingPri;
|
@property NSLayoutPriority oldHorzHuggingPri;
|
||||||
@property NSLayoutPriority oldVertHuggingPri;
|
@property NSLayoutPriority oldVertHuggingPri;
|
||||||
|
#endif
|
||||||
- (NSView *)view;
|
- (NSView *)view;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -22,11 +24,7 @@
|
||||||
BOOL vertical;
|
BOOL vertical;
|
||||||
int padded;
|
int padded;
|
||||||
|
|
||||||
NSLayoutConstraint *first;
|
#if 0 /* TODO */
|
||||||
NSMutableArray *inBetweens;
|
|
||||||
NSLayoutConstraint *last, *last2;
|
|
||||||
NSMutableArray *otherConstraints;
|
|
||||||
|
|
||||||
NSLayoutAttribute primaryStart;
|
NSLayoutAttribute primaryStart;
|
||||||
NSLayoutAttribute primaryEnd;
|
NSLayoutAttribute primaryEnd;
|
||||||
NSLayoutAttribute secondaryStart;
|
NSLayoutAttribute secondaryStart;
|
||||||
|
@ -34,13 +32,13 @@
|
||||||
NSLayoutAttribute primarySize;
|
NSLayoutAttribute primarySize;
|
||||||
NSLayoutConstraintOrientation primaryOrientation;
|
NSLayoutConstraintOrientation primaryOrientation;
|
||||||
NSLayoutConstraintOrientation secondaryOrientation;
|
NSLayoutConstraintOrientation secondaryOrientation;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
- (id)initWithVertical:(BOOL)vert b:(uiBox *)bb;
|
- (id)initWithVertical:(BOOL)vert b:(uiBox *)bb;
|
||||||
- (void)onDestroy;
|
- (void)onDestroy;
|
||||||
- (void)removeOurConstraints;
|
- (void)removeOurConstraints;
|
||||||
- (void)forAll:(void (^)(uintmax_t i, boxChild *b))closure;
|
- (void)syncEnableStates:(int)enabled;
|
||||||
- (boxChild *)child:(uintmax_t)i;
|
- (CGFloat)paddingAmount;
|
||||||
- (BOOL)isVertical;
|
|
||||||
- (void)append:(uiControl *)c stretchy:(int)stretchy;
|
- (void)append:(uiControl *)c stretchy:(int)stretchy;
|
||||||
- (void)delete:(uintmax_t)n;
|
- (void)delete:(uintmax_t)n;
|
||||||
- (int)isPadded;
|
- (int)isPadded;
|
||||||
|
@ -71,9 +69,8 @@ struct uiBox {
|
||||||
self->b = bb;
|
self->b = bb;
|
||||||
self->vertical = vert;
|
self->vertical = vert;
|
||||||
self->children = [NSMutableArray new];
|
self->children = [NSMutableArray new];
|
||||||
self->inBetweens = [NSMutableArray new];
|
|
||||||
self->otherConstraints = [NSMutableArray new];
|
|
||||||
|
|
||||||
|
#if 0 /* TODO */
|
||||||
if (self->vertical) {
|
if (self->vertical) {
|
||||||
self->primaryStart = NSLayoutAttributeTop;
|
self->primaryStart = NSLayoutAttributeTop;
|
||||||
self->primaryEnd = NSLayoutAttributeBottom;
|
self->primaryEnd = NSLayoutAttributeBottom;
|
||||||
|
@ -91,6 +88,7 @@ struct uiBox {
|
||||||
self->primaryOrientation = NSLayoutConstraintOrientationHorizontal;
|
self->primaryOrientation = NSLayoutConstraintOrientationHorizontal;
|
||||||
self->secondaryOrientation = NSLayoutConstraintOrientationVertical;
|
self->secondaryOrientation = NSLayoutConstraintOrientationVertical;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -98,18 +96,10 @@ struct uiBox {
|
||||||
- (void)onDestroy
|
- (void)onDestroy
|
||||||
{
|
{
|
||||||
boxChild *bc;
|
boxChild *bc;
|
||||||
uintmax_t i, n;
|
|
||||||
|
|
||||||
[self removeOurConstraints];
|
[self removeOurConstraints];
|
||||||
[self->first release];
|
|
||||||
[self->inBetweens release];
|
|
||||||
[self->last release];
|
|
||||||
[self->last2 release];
|
|
||||||
[self->otherConstraints release];
|
|
||||||
|
|
||||||
n = [self->children count];
|
for (bc in self->children) {
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
bc = [self child:i];
|
|
||||||
uiControlSetParent(bc.c, NULL);
|
uiControlSetParent(bc.c, NULL);
|
||||||
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), nil);
|
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), nil);
|
||||||
uiControlDestroy(bc.c);
|
uiControlDestroy(bc.c);
|
||||||
|
@ -119,156 +109,28 @@ struct uiBox {
|
||||||
|
|
||||||
- (void)removeOurConstraints
|
- (void)removeOurConstraints
|
||||||
{
|
{
|
||||||
[self removeConstraint:self->first];
|
// TODO
|
||||||
[self removeConstraints:self->inBetweens];
|
|
||||||
[self removeConstraint:self->last];
|
|
||||||
[self removeConstraint:self->last2];
|
|
||||||
[self removeConstraints:self->otherConstraints];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)forAll:(void (^)(uintmax_t i, boxChild *b))closure
|
- (void)syncEnableStates:(int)enabled
|
||||||
{
|
{
|
||||||
uintmax_t i, n;
|
boxChild *bc;
|
||||||
|
|
||||||
n = [self->children count];
|
for (bc in self->children)
|
||||||
for (i = 0; i < n; i++)
|
uiDarwinControlSyncEnableState(uiDarwinControl(bc.c), enabled);
|
||||||
closure(i, [self child:i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (boxChild *)child:(uintmax_t)i
|
- (CGFloat)paddingAmount
|
||||||
{
|
{
|
||||||
return (boxChild *) [self->children objectAtIndex:i];
|
if (!self->padded)
|
||||||
}
|
return 0.0;
|
||||||
|
return 8.0; // TODO named constant
|
||||||
- (BOOL)isVertical
|
|
||||||
{
|
|
||||||
return self->vertical;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO something about spinbox hugging
|
// TODO something about spinbox hugging
|
||||||
- (void)updateConstraints
|
- (void)updateConstraints
|
||||||
{
|
{
|
||||||
uintmax_t i, n;
|
|
||||||
BOOL hasStretchy;
|
|
||||||
NSView *firstStretchy = nil;
|
|
||||||
CGFloat padding;
|
|
||||||
NSView *prev, *next;
|
|
||||||
NSLayoutConstraint *c;
|
|
||||||
NSLayoutPriority priority;
|
|
||||||
|
|
||||||
[super updateConstraints];
|
[super updateConstraints];
|
||||||
[self removeOurConstraints];
|
|
||||||
|
|
||||||
n = [self->children count];
|
|
||||||
if (n == 0)
|
|
||||||
return;
|
|
||||||
padding = 0;
|
|
||||||
if (self->padded)
|
|
||||||
padding = 8.0; // TODO named constant
|
|
||||||
|
|
||||||
// first, attach the first view to the leading
|
|
||||||
prev = [[self child:0] view];
|
|
||||||
self->first = mkConstraint(prev, self->primaryStart,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
self, self->primaryStart,
|
|
||||||
1, 0,
|
|
||||||
@"uiBox first primary constraint");
|
|
||||||
[self addConstraint:self->first];
|
|
||||||
[self->first retain];
|
|
||||||
|
|
||||||
// next, assemble the views in the primary direction
|
|
||||||
// they all go in a straight line
|
|
||||||
// also figure out whether we have stretchy controls, and which is the first
|
|
||||||
if ([self child:0].stretchy) {
|
|
||||||
hasStretchy = YES;
|
|
||||||
firstStretchy = prev;
|
|
||||||
} else
|
|
||||||
hasStretchy = NO;
|
|
||||||
for (i = 1; i < n; i++) {
|
|
||||||
next = [[self child:i] view];
|
|
||||||
if (!hasStretchy && [self child:i].stretchy) {
|
|
||||||
hasStretchy = YES;
|
|
||||||
firstStretchy = next;
|
|
||||||
}
|
|
||||||
c = mkConstraint(next, self->primaryStart,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
prev, self->primaryEnd,
|
|
||||||
1, padding,
|
|
||||||
@"uiBox later primary constraint");
|
|
||||||
[self addConstraint:c];
|
|
||||||
[self->inBetweens addObject:c];
|
|
||||||
prev = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
// and finally end the primary direction
|
|
||||||
self->last = mkConstraint(prev, self->primaryEnd,
|
|
||||||
NSLayoutRelationLessThanOrEqual,
|
|
||||||
self, self->primaryEnd,
|
|
||||||
1, 0,
|
|
||||||
@"uiBox last primary constraint");
|
|
||||||
[self addConstraint:self->last];
|
|
||||||
[self->last retain];
|
|
||||||
|
|
||||||
// if there is a stretchy control, add the no-stretchy view
|
|
||||||
self->last2 = mkConstraint(prev, self->primaryEnd,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
self, self->primaryEnd,
|
|
||||||
1, 0,
|
|
||||||
@"uiBox last2 primary constraint");
|
|
||||||
priority = NSLayoutPriorityRequired;
|
|
||||||
if (!hasStretchy) {
|
|
||||||
BOOL shouldExpand = NO;
|
|
||||||
uiControl *parent;
|
|
||||||
|
|
||||||
parent = uiControlParent(uiControl(self->b));
|
|
||||||
if (parent != nil)
|
|
||||||
if (self->vertical)
|
|
||||||
shouldExpand = uiDarwinControlChildrenShouldAllowSpaceAtBottom(uiDarwinControl(parent));
|
|
||||||
else
|
|
||||||
shouldExpand = uiDarwinControlChildrenShouldAllowSpaceAtTrailingEdge(uiDarwinControl(parent));
|
|
||||||
if (shouldExpand)
|
|
||||||
priority = NSLayoutPriorityDefaultLow;
|
|
||||||
}
|
|
||||||
[self->last2 setPriority:priority];
|
|
||||||
[self addConstraint:self->last2];
|
|
||||||
[self->last2 retain];
|
|
||||||
|
|
||||||
// next: assemble the views in the secondary direction
|
|
||||||
// each of them will span the secondary direction
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
prev = [[self child:i] view];
|
|
||||||
c = mkConstraint(prev, self->secondaryStart,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
self, self->secondaryStart,
|
|
||||||
1, 0,
|
|
||||||
@"uiBox start secondary constraint");
|
|
||||||
[self addConstraint:c];
|
|
||||||
[self->otherConstraints addObject:c];
|
|
||||||
c = mkConstraint(prev, self->secondaryEnd,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
self, self->secondaryEnd,
|
|
||||||
1, 0,
|
|
||||||
@"uiBox end secondary constraint");
|
|
||||||
[self addConstraint:c];
|
|
||||||
[self->otherConstraints addObject:c];
|
|
||||||
}
|
|
||||||
|
|
||||||
// finally, set sizes for stretchy controls
|
|
||||||
if (hasStretchy)
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
if (![self child:i].stretchy)
|
|
||||||
continue;
|
|
||||||
prev = [[self child:i] view];
|
|
||||||
if (prev == firstStretchy)
|
|
||||||
continue;
|
|
||||||
c = mkConstraint(prev, self->primarySize,
|
|
||||||
NSLayoutRelationEqual,
|
|
||||||
firstStretchy, self->primarySize,
|
|
||||||
1, 0,
|
|
||||||
@"uiBox stretchy sizing");
|
|
||||||
[self addConstraint:c];
|
|
||||||
[self->otherConstraints addObject:c];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)append:(uiControl *)c stretchy:(int)stretchy
|
- (void)append:(uiControl *)c stretchy:(int)stretchy
|
||||||
|
@ -280,13 +142,16 @@ struct uiBox {
|
||||||
bc.c = c;
|
bc.c = c;
|
||||||
bc.stretchy = stretchy;
|
bc.stretchy = stretchy;
|
||||||
childView = [bc view];
|
childView = [bc view];
|
||||||
|
#if 0 /* TODO */
|
||||||
bc.oldHorzHuggingPri = horzHuggingPri(childView);
|
bc.oldHorzHuggingPri = horzHuggingPri(childView);
|
||||||
bc.oldVertHuggingPri = vertHuggingPri(childView);
|
bc.oldVertHuggingPri = vertHuggingPri(childView);
|
||||||
|
#endif
|
||||||
|
|
||||||
uiControlSetParent(bc.c, uiControl(self->b));
|
uiControlSetParent(bc.c, uiControl(self->b));
|
||||||
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), self);
|
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), self);
|
||||||
uiDarwinControlSyncEnableState(uiDarwinControl(bc.c), uiControlEnabledToUser(uiControl(self->b)));
|
uiDarwinControlSyncEnableState(uiDarwinControl(bc.c), uiControlEnabledToUser(uiControl(self->b)));
|
||||||
|
|
||||||
|
#if 0 /*TODO */
|
||||||
// if a control is stretchy, it should not hug in the primary direction
|
// if a control is stretchy, it should not hug in the primary direction
|
||||||
// otherwise, it should *forcibly* hug
|
// otherwise, it should *forcibly* hug
|
||||||
if (stretchy)
|
if (stretchy)
|
||||||
|
@ -296,10 +161,12 @@ struct uiBox {
|
||||||
setHuggingPri(childView, NSLayoutPriorityRequired, self->primaryOrientation);
|
setHuggingPri(childView, NSLayoutPriorityRequired, self->primaryOrientation);
|
||||||
// make sure controls don't hug their secondary direction so they fill the width of the view
|
// make sure controls don't hug their secondary direction so they fill the width of the view
|
||||||
setHuggingPri(childView, NSLayoutPriorityDefaultLow, self->secondaryOrientation);
|
setHuggingPri(childView, NSLayoutPriorityDefaultLow, self->secondaryOrientation);
|
||||||
|
#endif
|
||||||
|
|
||||||
[self->children addObject:bc];
|
[self->children addObject:bc];
|
||||||
[bc release]; // we don't need the initial reference now
|
[bc release]; // we don't need the initial reference now
|
||||||
|
|
||||||
|
[self removeOurConstraints];
|
||||||
[self setNeedsUpdateConstraints:YES];
|
[self setNeedsUpdateConstraints:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,17 +175,21 @@ struct uiBox {
|
||||||
boxChild *bc;
|
boxChild *bc;
|
||||||
NSView *removedView;
|
NSView *removedView;
|
||||||
|
|
||||||
bc = [self child:n];
|
// TODO separate into a method?
|
||||||
|
bc = (boxChild *) [self->children objectAtIndex:n];
|
||||||
removedView = [bc view];
|
removedView = [bc view];
|
||||||
|
|
||||||
uiControlSetParent(bc.c, NULL);
|
uiControlSetParent(bc.c, NULL);
|
||||||
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), nil);
|
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), nil);
|
||||||
|
|
||||||
|
#if 0 /* TODO */
|
||||||
setHorzHuggingPri(removedView, bc.oldHorzHuggingPri);
|
setHorzHuggingPri(removedView, bc.oldHorzHuggingPri);
|
||||||
setVertHuggingPri(removedView, bc.oldVertHuggingPri);
|
setVertHuggingPri(removedView, bc.oldVertHuggingPri);
|
||||||
|
#endif
|
||||||
|
|
||||||
[self->children removeObjectAtIndex:n];
|
[self->children removeObjectAtIndex:n];
|
||||||
|
|
||||||
|
[self removeOurConstraints];
|
||||||
[self setNeedsUpdateConstraints:YES];
|
[self setNeedsUpdateConstraints:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,20 +201,14 @@ struct uiBox {
|
||||||
- (void)setPadded:(int)p
|
- (void)setPadded:(int)p
|
||||||
{
|
{
|
||||||
CGFloat padding;
|
CGFloat padding;
|
||||||
uintmax_t i, n;
|
|
||||||
NSLayoutConstraint *c;
|
NSLayoutConstraint *c;
|
||||||
|
|
||||||
self->padded = p;
|
self->padded = p;
|
||||||
|
padding = [self paddingAmount];
|
||||||
// TODO split into method (using above code)
|
#if 0 /* TODO */
|
||||||
padding = 0;
|
for (c in self->inBetweens)
|
||||||
if (self->padded)
|
|
||||||
padding = 8.0;
|
|
||||||
n = [self->inBetweens count];
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
c = (NSLayoutConstraint *) [self->inBetweens objectAtIndex:i];
|
|
||||||
[c setConstant:padding];
|
[c setConstant:padding];
|
||||||
}
|
#endif
|
||||||
// TODO call anything?
|
// TODO call anything?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,29 +240,11 @@ static void uiBoxSyncEnableState(uiDarwinControl *c, int enabled)
|
||||||
|
|
||||||
if (uiDarwinShouldStopSyncEnableState(uiDarwinControl(b), enabled))
|
if (uiDarwinShouldStopSyncEnableState(uiDarwinControl(b), enabled))
|
||||||
return;
|
return;
|
||||||
[b->view forAll:^(uintmax_t i, boxChild *bc) {
|
[b->view syncEnableStates:enabled];
|
||||||
uiDarwinControlSyncEnableState(uiDarwinControl(bc.c), enabled);
|
|
||||||
}];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uiDarwinControlDefaultSetSuperview(uiBox, view)
|
uiDarwinControlDefaultSetSuperview(uiBox, view)
|
||||||
|
|
||||||
static BOOL uiBoxChildrenShouldAllowSpaceAtTrailingEdge(uiDarwinControl *c)
|
|
||||||
{
|
|
||||||
uiBox *b = uiBox(c);
|
|
||||||
|
|
||||||
// return NO if this box is horizontal so nested horizontal boxes don't lead to ambiguity
|
|
||||||
return [b->view isVertical];
|
|
||||||
}
|
|
||||||
|
|
||||||
static BOOL uiBoxChildrenShouldAllowSpaceAtBottom(uiDarwinControl *c)
|
|
||||||
{
|
|
||||||
uiBox *b = uiBox(c);
|
|
||||||
|
|
||||||
// return NO if this box is vertical so nested vertical boxes don't lead to ambiguity
|
|
||||||
return ![b->view isVertical];
|
|
||||||
}
|
|
||||||
|
|
||||||
void uiBoxAppend(uiBox *b, uiControl *c, int stretchy)
|
void uiBoxAppend(uiBox *b, uiControl *c, int stretchy)
|
||||||
{
|
{
|
||||||
[b->view append:c stretchy:stretchy];
|
[b->view append:c stretchy:stretchy];
|
||||||
|
|
|
@ -11,16 +11,6 @@ void uiDarwinControlSetSuperview(uiDarwinControl *c, NSView *superview)
|
||||||
(*(c->SetSuperview))(c, superview);
|
(*(c->SetSuperview))(c, superview);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL uiDarwinControlChildrenShouldAllowSpaceAtTrailingEdge(uiDarwinControl *c)
|
|
||||||
{
|
|
||||||
return (*(c->ChildrenShouldAllowSpaceAtTrailingEdge))(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL uiDarwinControlChildrenShouldAllowSpaceAtBottom(uiDarwinControl *c)
|
|
||||||
{
|
|
||||||
return (*(c->ChildrenShouldAllowSpaceAtBottom))(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
void uiDarwinSetControlFont(NSControl *c, NSControlSize size)
|
void uiDarwinSetControlFont(NSControl *c, NSControlSize size)
|
||||||
{
|
{
|
||||||
[c setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:size]]];
|
[c setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:size]]];
|
||||||
|
|
|
@ -70,29 +70,6 @@ static void uiGroupSyncEnableState(uiDarwinControl *c, int enabled)
|
||||||
|
|
||||||
uiDarwinControlDefaultSetSuperview(uiGroup, box)
|
uiDarwinControlDefaultSetSuperview(uiGroup, box)
|
||||||
|
|
||||||
static BOOL uiGroupChildrenShouldAllowSpaceAtTrailingEdge(uiDarwinControl *c)
|
|
||||||
{
|
|
||||||
uiControl *parent;
|
|
||||||
|
|
||||||
// TODO figure out why this works
|
|
||||||
parent = uiControlParent(uiControl(c));
|
|
||||||
if (parent != NULL)
|
|
||||||
return uiDarwinControlChildrenShouldAllowSpaceAtTrailingEdge(uiDarwinControl(parent));
|
|
||||||
// always allow growth if not
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BOOL uiGroupChildrenShouldAllowSpaceAtBottom(uiDarwinControl *c)
|
|
||||||
{
|
|
||||||
uiControl *parent;
|
|
||||||
|
|
||||||
parent = uiControlParent(uiControl(c));
|
|
||||||
if (parent != NULL)
|
|
||||||
return uiDarwinControlChildrenShouldAllowSpaceAtBottom(uiDarwinControl(parent));
|
|
||||||
// always allow growth if not
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void groupRelayout(uiGroup *g)
|
static void groupRelayout(uiGroup *g)
|
||||||
{
|
{
|
||||||
uiDarwinControl *cc;
|
uiDarwinControl *cc;
|
||||||
|
@ -104,7 +81,7 @@ static void groupRelayout(uiGroup *g)
|
||||||
childView = (NSView *) uiControlHandle(g->child);
|
childView = (NSView *) uiControlHandle(g->child);
|
||||||
// first relayout the child
|
// first relayout the child
|
||||||
//TODO (*(cc->Relayout))(cc);
|
//TODO (*(cc->Relayout))(cc);
|
||||||
layoutSingleView([g->box contentView], childView, g->margined, @"uiGroup");
|
//TODO layoutSingleView([g->box contentView], childView, g->margined, @"uiGroup");
|
||||||
// we need to explicitly tell the NSBox to recompute its own size based on the new content layout
|
// we need to explicitly tell the NSBox to recompute its own size based on the new content layout
|
||||||
[g->box sizeToFit];
|
[g->box sizeToFit];
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ uiMultilineEntry *uiNewMultilineEntry(void)
|
||||||
[e->sv setDocumentView:e->tv];
|
[e->sv setDocumentView:e->tv];
|
||||||
[e->tv setTranslatesAutoresizingMaskIntoConstraints:NO];
|
[e->tv setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||||
// we don't need to save the NSMutableArray
|
// we don't need to save the NSMutableArray
|
||||||
[layoutScrollViewContents(e->sv, YES, NO, @"uiMultilineEntry") release];
|
//TODO [layoutScrollViewContents(e->sv, YES, NO, @"uiMultilineEntry") release];
|
||||||
|
|
||||||
//TODO:void printinfo(NSScrollView *sv, NSTextView *tv);
|
//TODO:void printinfo(NSScrollView *sv, NSTextView *tv);
|
||||||
//printinfo(e->sv, e->tv);
|
//printinfo(e->sv, e->tv);
|
||||||
|
|
14
darwin/tab.m
14
darwin/tab.m
|
@ -56,18 +56,6 @@ uiDarwinControlDefaultSyncEnableState(uiTab, tabview)
|
||||||
|
|
||||||
uiDarwinControlDefaultSetSuperview(uiTab, tabview)
|
uiDarwinControlDefaultSetSuperview(uiTab, tabview)
|
||||||
|
|
||||||
static BOOL uiTabChildrenShouldAllowSpaceAtTrailingEdge(uiDarwinControl *c)
|
|
||||||
{
|
|
||||||
// always allow growth
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BOOL uiTabChildrenShouldAllowSpaceAtBottom(uiDarwinControl *c)
|
|
||||||
{
|
|
||||||
// always allow growth
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tabRelayout(uiTab *t)
|
static void tabRelayout(uiTab *t)
|
||||||
{
|
{
|
||||||
NSUInteger i;
|
NSUInteger i;
|
||||||
|
@ -90,7 +78,7 @@ static void tabRelayout(uiTab *t)
|
||||||
cc = uiDarwinControl(child);
|
cc = uiDarwinControl(child);
|
||||||
//TODO (*(cc->Relayout))(cc);
|
//TODO (*(cc->Relayout))(cc);
|
||||||
// then lay out the page
|
// then lay out the page
|
||||||
layoutSingleView(view, childView, [margined intValue], @"uiTab");
|
//TODO layoutSingleView(view, childView, [margined intValue], @"uiTab");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,14 +57,6 @@ extern void uninitAlloc(void);
|
||||||
|
|
||||||
// autolayout.m
|
// autolayout.m
|
||||||
extern NSLayoutConstraint *mkConstraint(id view1, NSLayoutAttribute attr1, NSLayoutRelation relation, id view2, NSLayoutAttribute attr2, CGFloat multiplier, CGFloat c, NSString *desc);
|
extern NSLayoutConstraint *mkConstraint(id view1, NSLayoutAttribute attr1, NSLayoutRelation relation, id view2, NSLayoutAttribute attr2, CGFloat multiplier, CGFloat c, NSString *desc);
|
||||||
extern NSLayoutPriority horzHuggingPri(NSView *view);
|
|
||||||
extern void setHuggingPri(NSView *view, NSLayoutPriority priority, NSLayoutConstraintOrientation orientation);
|
|
||||||
extern NSLayoutPriority horzHuggingPri(NSView *view);
|
|
||||||
extern void setHorzHuggingPri(NSView *view, NSLayoutPriority priority);
|
|
||||||
extern NSLayoutPriority vertHuggingPri(NSView *view);
|
|
||||||
extern void setVertHuggingPri(NSView *view, NSLayoutPriority priority);
|
|
||||||
extern void layoutSingleView(NSView *superview, NSView *subview, int margined, NSString *desc);
|
|
||||||
extern NSMutableArray *layoutScrollViewContents(NSScrollView *sv, BOOL noHScroll, BOOL noVScroll, NSString *desc);
|
|
||||||
|
|
||||||
// map.m
|
// map.m
|
||||||
extern struct mapTable *newMap(void);
|
extern struct mapTable *newMap(void);
|
||||||
|
|
|
@ -141,18 +141,6 @@ static void uiWindowSetSuperview(uiDarwinControl *c, NSView *superview)
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL uiWindowChildrenShouldAllowSpaceAtTrailingEdge(uiDarwinControl *c)
|
|
||||||
{
|
|
||||||
// always allow growth
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BOOL uiWindowChildrenShouldAllowSpaceAtBottom(uiDarwinControl *c)
|
|
||||||
{
|
|
||||||
// always allow growth
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void windowRelayout(uiWindow *w)
|
static void windowRelayout(uiWindow *w)
|
||||||
{
|
{
|
||||||
uiDarwinControl *cc;
|
uiDarwinControl *cc;
|
||||||
|
@ -167,7 +155,7 @@ static void windowRelayout(uiWindow *w)
|
||||||
// first relayout the child
|
// first relayout the child
|
||||||
//TODO (*(cc->Relayout))(cc);
|
//TODO (*(cc->Relayout))(cc);
|
||||||
// now relayout ourselves
|
// now relayout ourselves
|
||||||
layoutSingleView(contentView, childView, w->margined, @"uiWindow");
|
//TODO layoutSingleView(contentView, childView, w->margined, @"uiWindow");
|
||||||
}
|
}
|
||||||
|
|
||||||
char *uiWindowTitle(uiWindow *w)
|
char *uiWindowTitle(uiWindow *w)
|
||||||
|
|
20
ui_darwin.h
20
ui_darwin.h
|
@ -19,15 +19,11 @@ struct uiDarwinControl {
|
||||||
BOOL visible;
|
BOOL visible;
|
||||||
void (*SyncEnableState)(uiDarwinControl *, int);
|
void (*SyncEnableState)(uiDarwinControl *, int);
|
||||||
void (*SetSuperview)(uiDarwinControl *, NSView *);
|
void (*SetSuperview)(uiDarwinControl *, NSView *);
|
||||||
BOOL (*ChildrenShouldAllowSpaceAtTrailingEdge)(uiDarwinControl *);
|
|
||||||
BOOL (*ChildrenShouldAllowSpaceAtBottom)(uiDarwinControl *);
|
|
||||||
};
|
};
|
||||||
#define uiDarwinControl(this) ((uiDarwinControl *) (this))
|
#define uiDarwinControl(this) ((uiDarwinControl *) (this))
|
||||||
// TODO document
|
// TODO document
|
||||||
_UI_EXTERN void uiDarwinControlSyncEnableState(uiDarwinControl *, int);
|
_UI_EXTERN void uiDarwinControlSyncEnableState(uiDarwinControl *, int);
|
||||||
_UI_EXTERN void uiDarwinControlSetSuperview(uiDarwinControl *, NSView *);
|
_UI_EXTERN void uiDarwinControlSetSuperview(uiDarwinControl *, NSView *);
|
||||||
_UI_EXTERN BOOL uiDarwinControlChildrenShouldAllowSpaceAtTrailingEdge(uiDarwinControl *);
|
|
||||||
_UI_EXTERN BOOL uiDarwinControlChildrenShouldAllowSpaceAtBottom(uiDarwinControl *);
|
|
||||||
|
|
||||||
#define uiDarwinControlDefaultDestroy(type, handlefield) \
|
#define uiDarwinControlDefaultDestroy(type, handlefield) \
|
||||||
static void type ## Destroy(uiControl *c) \
|
static void type ## Destroy(uiControl *c) \
|
||||||
|
@ -108,16 +104,6 @@ _UI_EXTERN BOOL uiDarwinControlChildrenShouldAllowSpaceAtBottom(uiDarwinControl
|
||||||
else \
|
else \
|
||||||
[superview addSubview:type(c)->handlefield]; \
|
[superview addSubview:type(c)->handlefield]; \
|
||||||
}
|
}
|
||||||
#define uiDarwinControlDefaultChildrenShouldAllowSpaceAtTrailingEdge(type, handlefield) \
|
|
||||||
static BOOL type ## ChildrenShouldAllowSpaceAtTrailingEdge(uiDarwinControl *c) \
|
|
||||||
{ \
|
|
||||||
return NO; /* TODO irrelevant */ \
|
|
||||||
}
|
|
||||||
#define uiDarwinControlDefaultChildrenShouldAllowSpaceAtBottom(type, handlefield) \
|
|
||||||
static BOOL type ## ChildrenShouldAllowSpaceAtBottom(uiDarwinControl *c) \
|
|
||||||
{ \
|
|
||||||
return NO; /* TODO irrelevant */ \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define uiDarwinControlAllDefaultsExceptDestroy(type, handlefield) \
|
#define uiDarwinControlAllDefaultsExceptDestroy(type, handlefield) \
|
||||||
uiDarwinControlDefaultHandle(type, handlefield) \
|
uiDarwinControlDefaultHandle(type, handlefield) \
|
||||||
|
@ -131,9 +117,7 @@ _UI_EXTERN BOOL uiDarwinControlChildrenShouldAllowSpaceAtBottom(uiDarwinControl
|
||||||
uiDarwinControlDefaultEnable(type, handlefield) \
|
uiDarwinControlDefaultEnable(type, handlefield) \
|
||||||
uiDarwinControlDefaultDisable(type, handlefield) \
|
uiDarwinControlDefaultDisable(type, handlefield) \
|
||||||
uiDarwinControlDefaultSyncEnableState(type, handlefield) \
|
uiDarwinControlDefaultSyncEnableState(type, handlefield) \
|
||||||
uiDarwinControlDefaultSetSuperview(type, handlefield) \
|
uiDarwinControlDefaultSetSuperview(type, handlefield)
|
||||||
uiDarwinControlDefaultChildrenShouldAllowSpaceAtTrailingEdge(type, handlefield) \
|
|
||||||
uiDarwinControlDefaultChildrenShouldAllowSpaceAtBottom(type, handlefield)
|
|
||||||
|
|
||||||
#define uiDarwinControlAllDefaults(type, handlefield) \
|
#define uiDarwinControlAllDefaults(type, handlefield) \
|
||||||
uiDarwinControlDefaultDestroy(type, handlefield) \
|
uiDarwinControlDefaultDestroy(type, handlefield) \
|
||||||
|
@ -155,8 +139,6 @@ _UI_EXTERN BOOL uiDarwinControlChildrenShouldAllowSpaceAtBottom(uiDarwinControl
|
||||||
uiControl(var)->Disable = type ## Disable; \
|
uiControl(var)->Disable = type ## Disable; \
|
||||||
uiDarwinControl(var)->SyncEnableState = type ## SyncEnableState; \
|
uiDarwinControl(var)->SyncEnableState = type ## SyncEnableState; \
|
||||||
uiDarwinControl(var)->SetSuperview = type ## SetSuperview; \
|
uiDarwinControl(var)->SetSuperview = type ## SetSuperview; \
|
||||||
uiDarwinControl(var)->ChildrenShouldAllowSpaceAtTrailingEdge = type ## ChildrenShouldAllowSpaceAtTrailingEdge; \
|
|
||||||
uiDarwinControl(var)->ChildrenShouldAllowSpaceAtBottom = type ## ChildrenShouldAllowSpaceAtBottom; \
|
|
||||||
uiDarwinControl(var)->visible = YES; \
|
uiDarwinControl(var)->visible = YES; \
|
||||||
uiDarwinControl(var)->enabled = YES;
|
uiDarwinControl(var)->enabled = YES;
|
||||||
// TODO document
|
// TODO document
|
||||||
|
|
Loading…
Reference in New Issue