Revert "Started implementing the previous commit's changes in a more permanent way: set REAL hugging priorities and implemented them on uiBox."
This reverts commit 07930279c0
.
This commit is contained in:
parent
f413456b60
commit
32ef7c3fd3
92
darwin/box.m
92
darwin/box.m
|
@ -11,6 +11,8 @@
|
||||||
@interface boxChild : NSObject
|
@interface boxChild : NSObject
|
||||||
@property uiControl *c;
|
@property uiControl *c;
|
||||||
@property BOOL stretchy;
|
@property BOOL stretchy;
|
||||||
|
@property NSLayoutPriority oldHorzHuggingPri;
|
||||||
|
@property NSLayoutPriority oldVertHuggingPri;
|
||||||
- (NSView *)view;
|
- (NSView *)view;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -22,8 +24,7 @@
|
||||||
|
|
||||||
NSLayoutConstraint *first;
|
NSLayoutConstraint *first;
|
||||||
NSMutableArray *inBetweens;
|
NSMutableArray *inBetweens;
|
||||||
NSLayoutConstraint *last;
|
NSLayoutConstraint *last, *last2;
|
||||||
NSLayoutConstraint *lastHugging;
|
|
||||||
NSMutableArray *otherConstraints;
|
NSMutableArray *otherConstraints;
|
||||||
|
|
||||||
NSLayoutAttribute primaryStart;
|
NSLayoutAttribute primaryStart;
|
||||||
|
@ -33,9 +34,6 @@
|
||||||
NSLayoutAttribute primarySize;
|
NSLayoutAttribute primarySize;
|
||||||
NSLayoutConstraintOrientation primaryOrientation;
|
NSLayoutConstraintOrientation primaryOrientation;
|
||||||
NSLayoutConstraintOrientation secondaryOrientation;
|
NSLayoutConstraintOrientation secondaryOrientation;
|
||||||
|
|
||||||
NSLayoutPriority horzHuggingPri;
|
|
||||||
NSLayoutPriority vertHuggingPri;
|
|
||||||
}
|
}
|
||||||
- (id)initWithVertical:(BOOL)vert b:(uiBox *)bb;
|
- (id)initWithVertical:(BOOL)vert b:(uiBox *)bb;
|
||||||
- (void)onDestroy;
|
- (void)onDestroy;
|
||||||
|
@ -47,7 +45,6 @@
|
||||||
- (void)delete:(uintmax_t)n;
|
- (void)delete:(uintmax_t)n;
|
||||||
- (int)isPadded;
|
- (int)isPadded;
|
||||||
- (void)setPadded:(int)p;
|
- (void)setPadded:(int)p;
|
||||||
- (void)setRealHuggingPriority:(NSLayoutPriority)priority forOrientation:(NSLayoutConstraintOrientation)orientation;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
struct uiBox {
|
struct uiBox {
|
||||||
|
@ -94,10 +91,6 @@ struct uiBox {
|
||||||
self->primaryOrientation = NSLayoutConstraintOrientationHorizontal;
|
self->primaryOrientation = NSLayoutConstraintOrientationHorizontal;
|
||||||
self->secondaryOrientation = NSLayoutConstraintOrientationVertical;
|
self->secondaryOrientation = NSLayoutConstraintOrientationVertical;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO required?
|
|
||||||
self->horzHuggingPri = NSLayoutPriorityDefaultHigh;
|
|
||||||
self->vertHuggingPri = NSLayoutPriorityDefaultHigh;
|
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -107,12 +100,11 @@ struct uiBox {
|
||||||
boxChild *bc;
|
boxChild *bc;
|
||||||
uintmax_t i, n;
|
uintmax_t i, n;
|
||||||
|
|
||||||
// TODO if guard these
|
|
||||||
[self removeOurConstraints];
|
[self removeOurConstraints];
|
||||||
[self->first release];
|
[self->first release];
|
||||||
[self->inBetweens release];
|
[self->inBetweens release];
|
||||||
[self->last release];
|
[self->last release];
|
||||||
[self->lastHugging release];
|
[self->last2 release];
|
||||||
[self->otherConstraints release];
|
[self->otherConstraints release];
|
||||||
|
|
||||||
n = [self->children count];
|
n = [self->children count];
|
||||||
|
@ -127,14 +119,11 @@ struct uiBox {
|
||||||
|
|
||||||
- (void)removeOurConstraints
|
- (void)removeOurConstraints
|
||||||
{
|
{
|
||||||
// TODO if guard these
|
|
||||||
[self removeConstraint:self->first];
|
[self removeConstraint:self->first];
|
||||||
[self removeConstraints:self->inBetweens];
|
[self removeConstraints:self->inBetweens];
|
||||||
[self->inBetweens removeAllObjects];
|
|
||||||
[self removeConstraint:self->last];
|
[self removeConstraint:self->last];
|
||||||
[self removeConstraint:self->last2];
|
[self removeConstraint:self->last2];
|
||||||
[self removeConstraints:self->otherConstraints];
|
[self removeConstraints:self->otherConstraints];
|
||||||
[self->otherConstraints removeAllObjects];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)forAll:(void (^)(uintmax_t i, boxChild *b))closure
|
- (void)forAll:(void (^)(uintmax_t i, boxChild *b))closure
|
||||||
|
@ -211,7 +200,7 @@ struct uiBox {
|
||||||
prev = next;
|
prev = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// end the primary direction with the <= constraint
|
// and finally end the primary direction
|
||||||
self->last = mkConstraint(prev, self->primaryEnd,
|
self->last = mkConstraint(prev, self->primaryEnd,
|
||||||
NSLayoutRelationLessThanOrEqual,
|
NSLayoutRelationLessThanOrEqual,
|
||||||
self, self->primaryEnd,
|
self, self->primaryEnd,
|
||||||
|
@ -220,19 +209,29 @@ struct uiBox {
|
||||||
[self addConstraint:self->last];
|
[self addConstraint:self->last];
|
||||||
[self->last retain];
|
[self->last retain];
|
||||||
|
|
||||||
// end the primary direction with the == hugging constraint, with the appropriate priority
|
// if there is a stretchy control, add the no-stretchy view
|
||||||
self->lastHugging = mkConstraint(prev, self->primaryEnd,
|
self->last2 = mkConstraint(prev, self->primaryEnd,
|
||||||
NSLayoutRelationEqual,
|
NSLayoutRelationEqual,
|
||||||
self, self->primaryEnd,
|
self, self->primaryEnd,
|
||||||
1, 0,
|
1, 0,
|
||||||
@"uiBox last2 primary constraint");
|
@"uiBox last2 primary constraint");
|
||||||
priority = NSLayoutPriorityRequired;
|
priority = NSLayoutPriorityRequired;
|
||||||
if (self->vertical)
|
if (!hasStretchy) {
|
||||||
[self->lastHugging setPriority:self->vertHuggingPri];
|
BOOL shouldExpand = NO;
|
||||||
else
|
uiControl *parent;
|
||||||
[self->lastHugging setPriority:self->horzHuggingPri];
|
|
||||||
[self addConstraint:self->lastHugging];
|
parent = uiControlParent(uiControl(self->b));
|
||||||
[self->lastHugging retain];
|
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
|
// next: assemble the views in the secondary direction
|
||||||
// each of them will span the secondary direction
|
// each of them will span the secondary direction
|
||||||
|
@ -243,10 +242,6 @@ struct uiBox {
|
||||||
self, self->secondaryStart,
|
self, self->secondaryStart,
|
||||||
1, 0,
|
1, 0,
|
||||||
@"uiBox start secondary constraint");
|
@"uiBox start secondary constraint");
|
||||||
if (self->vertical)
|
|
||||||
[c setPriority:self->horzHuggingPri];
|
|
||||||
else
|
|
||||||
[c setPriority:self->vertHuggingPri];
|
|
||||||
[self addConstraint:c];
|
[self addConstraint:c];
|
||||||
[self->otherConstraints addObject:c];
|
[self->otherConstraints addObject:c];
|
||||||
c = mkConstraint(prev, self->secondaryEnd,
|
c = mkConstraint(prev, self->secondaryEnd,
|
||||||
|
@ -254,10 +249,6 @@ struct uiBox {
|
||||||
self, self->secondaryEnd,
|
self, self->secondaryEnd,
|
||||||
1, 0,
|
1, 0,
|
||||||
@"uiBox start secondary constraint");
|
@"uiBox start secondary constraint");
|
||||||
if (self->vertical)
|
|
||||||
[c setPriority:self->horzHuggingPri];
|
|
||||||
else
|
|
||||||
[c setPriority:self->vertHuggingPri];
|
|
||||||
[self addConstraint:c];
|
[self addConstraint:c];
|
||||||
[self->otherConstraints addObject:c];
|
[self->otherConstraints addObject:c];
|
||||||
}
|
}
|
||||||
|
@ -283,10 +274,14 @@ struct uiBox {
|
||||||
- (void)append:(uiControl *)c stretchy:(int)stretchy
|
- (void)append:(uiControl *)c stretchy:(int)stretchy
|
||||||
{
|
{
|
||||||
boxChild *bc;
|
boxChild *bc;
|
||||||
|
NSView *childView;
|
||||||
|
|
||||||
bc = [boxChild new];
|
bc = [boxChild new];
|
||||||
bc.c = c;
|
bc.c = c;
|
||||||
bc.stretchy = stretchy;
|
bc.stretchy = stretchy;
|
||||||
|
childView = [bc view];
|
||||||
|
bc.oldHorzHuggingPri = horzHuggingPri(childView);
|
||||||
|
bc.oldVertHuggingPri = vertHuggingPri(childView);
|
||||||
|
|
||||||
uiControlSetParent(bc.c, uiControl(self->b));
|
uiControlSetParent(bc.c, uiControl(self->b));
|
||||||
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), self);
|
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), self);
|
||||||
|
@ -295,12 +290,12 @@ struct uiBox {
|
||||||
// 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)
|
||||||
uiDarwinControlSetRealHuggingPriority(uiDarwinControl(bc.c), NSLayoutPriorityDefaultLow, self->primaryOrientation);
|
setHuggingPri(childView, NSLayoutPriorityDefaultLow, self->primaryOrientation);
|
||||||
else
|
else
|
||||||
// TODO will default high work?
|
// TODO will default high work?
|
||||||
uiDarwinControlSetRealHuggingPriority(uiDarwinControl(bc.c), 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
|
||||||
uiDarwinControlSetRealHuggingPriority(uiDarwinControl(bc.cc), NSLayoutPriorityDefaultLow, self->secondaryOrientation);
|
setHuggingPri(childView, NSLayoutPriorityDefaultLow, self->secondaryOrientation);
|
||||||
|
|
||||||
[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
|
||||||
|
@ -311,12 +306,17 @@ struct uiBox {
|
||||||
- (void)delete:(uintmax_t)n
|
- (void)delete:(uintmax_t)n
|
||||||
{
|
{
|
||||||
boxChild *bc;
|
boxChild *bc;
|
||||||
|
NSView *removedView;
|
||||||
|
|
||||||
bc = [self child:n];
|
bc = [self child:n];
|
||||||
|
removedView = [bc view];
|
||||||
|
|
||||||
uiControlSetParent(bc.c, NULL);
|
uiControlSetParent(bc.c, NULL);
|
||||||
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), nil);
|
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), nil);
|
||||||
|
|
||||||
|
setHorzHuggingPri(removedView, bc.oldHorzHuggingPri);
|
||||||
|
setVertHuggingPri(removedView, bc.oldVertHuggingPri);
|
||||||
|
|
||||||
[self->children removeObjectAtIndex:n];
|
[self->children removeObjectAtIndex:n];
|
||||||
|
|
||||||
[self setNeedsUpdateConstraints:YES];
|
[self setNeedsUpdateConstraints:YES];
|
||||||
|
@ -347,15 +347,6 @@ struct uiBox {
|
||||||
// TODO call anything?
|
// TODO call anything?
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setRealHuggingPriority:(NSLayoutPriority)priority forOrientation:(NSLayoutConstraintOrientation)orientation
|
|
||||||
{
|
|
||||||
if (orientation == NSLayoutConstraintOrientationVertical)
|
|
||||||
self->vertHuggingPri = priority;
|
|
||||||
else
|
|
||||||
self->horzHuggingPri = priority;
|
|
||||||
[self setNeedsUpdateConstraints:YES];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
static void uiBoxDestroy(uiControl *c)
|
static void uiBoxDestroy(uiControl *c)
|
||||||
|
@ -391,11 +382,20 @@ static void uiBoxSyncEnableState(uiDarwinControl *c, int enabled)
|
||||||
|
|
||||||
uiDarwinControlDefaultSetSuperview(uiBox, view)
|
uiDarwinControlDefaultSetSuperview(uiBox, view)
|
||||||
|
|
||||||
static void uiBoxSetRealHuggingPriority(uiDarwinControl *c, NSLayoutPriority priority, NSLayoutConstraintOrientation orientation)
|
static BOOL uiBoxChildrenShouldAllowSpaceAtTrailingEdge(uiDarwinControl *c)
|
||||||
{
|
{
|
||||||
uiBox *b = uiBox(c);
|
uiBox *b = uiBox(c);
|
||||||
|
|
||||||
[b->view setRealHuggingPriority:priority forOrientation:orientation];
|
// 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)
|
||||||
|
|
|
@ -11,9 +11,14 @@ void uiDarwinControlSetSuperview(uiDarwinControl *c, NSView *superview)
|
||||||
(*(c->SetSuperview))(c, superview);
|
(*(c->SetSuperview))(c, superview);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiDarwinControlSetRealHuggingPriority(uiDarwinControl *c, NSLayoutPriority priority, NSLayoutConstraintOrientation orientation)
|
BOOL uiDarwinControlChildrenShouldAllowSpaceAtTrailingEdge(uiDarwinControl *c)
|
||||||
{
|
{
|
||||||
(*(c->SetRealHuggingPriority))(c, priority, orientation);
|
return (*(c->ChildrenShouldAllowSpaceAtTrailingEdge))(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL uiDarwinControlChildrenShouldAllowSpaceAtBottom(uiDarwinControl *c)
|
||||||
|
{
|
||||||
|
return (*(c->ChildrenShouldAllowSpaceAtBottom))(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiDarwinSetControlFont(NSControl *c, NSControlSize size)
|
void uiDarwinSetControlFont(NSControl *c, NSControlSize size)
|
||||||
|
|
23
ui_darwin.h
23
ui_darwin.h
|
@ -19,13 +19,15 @@ struct uiDarwinControl {
|
||||||
BOOL visible;
|
BOOL visible;
|
||||||
void (*SyncEnableState)(uiDarwinControl *, int);
|
void (*SyncEnableState)(uiDarwinControl *, int);
|
||||||
void (*SetSuperview)(uiDarwinControl *, NSView *);
|
void (*SetSuperview)(uiDarwinControl *, NSView *);
|
||||||
void (*SetRealHuggingPriority)(uiDarwinControl *, NSLayoutPriority, NSLayoutConstraintOrientation);
|
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 void uiDarwinControlSetRealHuggingPriority(uiDarwinControl *, NSLayoutPriority, NSLayoutConstraintOrientation);
|
_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) \
|
||||||
|
@ -106,10 +108,15 @@ _UI_EXTERN void uiDarwinControlSetRealHuggingPriority(uiDarwinControl *, NSLayou
|
||||||
else \
|
else \
|
||||||
[superview addSubview:type(c)->handlefield]; \
|
[superview addSubview:type(c)->handlefield]; \
|
||||||
}
|
}
|
||||||
#define uiDarwinControlDefaultSetRealHuggingPriority(type, handlefield) \
|
#define uiDarwinControlDefaultChildrenShouldAllowSpaceAtTrailingEdge(type, handlefield) \
|
||||||
static void type ## SetRealHuggingPriority(uiDarwinControl *c, NSLayoutPriority priority, NSLayoutConstraintOrientation orientation) \
|
static BOOL type ## ChildrenShouldAllowSpaceAtTrailingEdge(uiDarwinControl *c) \
|
||||||
{ \
|
{ \
|
||||||
[type(c)->handlefield setContentHuggingPriority:priority forOrientation:orientation]; \
|
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) \
|
||||||
|
@ -125,7 +132,8 @@ _UI_EXTERN void uiDarwinControlSetRealHuggingPriority(uiDarwinControl *, NSLayou
|
||||||
uiDarwinControlDefaultDisable(type, handlefield) \
|
uiDarwinControlDefaultDisable(type, handlefield) \
|
||||||
uiDarwinControlDefaultSyncEnableState(type, handlefield) \
|
uiDarwinControlDefaultSyncEnableState(type, handlefield) \
|
||||||
uiDarwinControlDefaultSetSuperview(type, handlefield) \
|
uiDarwinControlDefaultSetSuperview(type, handlefield) \
|
||||||
uiDarwinControlDefaultSetRealHuggingPriority(type, handlefield)
|
uiDarwinControlDefaultChildrenShouldAllowSpaceAtTrailingEdge(type, handlefield) \
|
||||||
|
uiDarwinControlDefaultChildrenShouldAllowSpaceAtBottom(type, handlefield)
|
||||||
|
|
||||||
#define uiDarwinControlAllDefaults(type, handlefield) \
|
#define uiDarwinControlAllDefaults(type, handlefield) \
|
||||||
uiDarwinControlDefaultDestroy(type, handlefield) \
|
uiDarwinControlDefaultDestroy(type, handlefield) \
|
||||||
|
@ -147,7 +155,8 @@ _UI_EXTERN void uiDarwinControlSetRealHuggingPriority(uiDarwinControl *, NSLayou
|
||||||
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)->SetRealHuggingPriority = type ## SetRealHuggingPriority; \
|
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