Migrated uiBox. Now to test.
This commit is contained in:
parent
89425f0fa7
commit
f66b5a8873
190
darwin/box.m
190
darwin/box.m
|
@ -11,10 +11,8 @@
|
||||||
@interface boxChild : NSObject
|
@interface boxChild : NSObject
|
||||||
@property uiControl *c;
|
@property uiControl *c;
|
||||||
@property BOOL stretchy;
|
@property BOOL stretchy;
|
||||||
#if 0 /* TODO */
|
@property NSLayoutPriority oldPrimaryHuggingPri;
|
||||||
@property NSLayoutPriority oldHorzHuggingPri;
|
@property NSLayoutPriority oldSecondaryHuggingPri;
|
||||||
@property NSLayoutPriority oldVertHuggingPri;
|
|
||||||
#endif
|
|
||||||
- (NSView *)view;
|
- (NSView *)view;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -23,8 +21,13 @@
|
||||||
NSMutableArray *children;
|
NSMutableArray *children;
|
||||||
BOOL vertical;
|
BOOL vertical;
|
||||||
int padded;
|
int padded;
|
||||||
|
uintmax_t nStretchy;
|
||||||
|
|
||||||
|
NSLayoutConstraint *first;
|
||||||
|
NSMutableArray *inBetweens;
|
||||||
|
NSLayoutConstraint *last;
|
||||||
|
NSMutableArray *otherConstraints;
|
||||||
|
|
||||||
#if 0 /* TODO */
|
|
||||||
NSLayoutAttribute primaryStart;
|
NSLayoutAttribute primaryStart;
|
||||||
NSLayoutAttribute primaryEnd;
|
NSLayoutAttribute primaryEnd;
|
||||||
NSLayoutAttribute secondaryStart;
|
NSLayoutAttribute secondaryStart;
|
||||||
|
@ -32,7 +35,6 @@
|
||||||
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;
|
||||||
|
@ -43,6 +45,8 @@
|
||||||
- (void)delete:(uintmax_t)n;
|
- (void)delete:(uintmax_t)n;
|
||||||
- (int)isPadded;
|
- (int)isPadded;
|
||||||
- (void)setPadded:(int)p;
|
- (void)setPadded:(int)p;
|
||||||
|
- (BOOL)hugsTrailing;
|
||||||
|
- (BOOL)hugsBottom;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
struct uiBox {
|
struct uiBox {
|
||||||
|
@ -69,8 +73,8 @@ struct uiBox {
|
||||||
self->b = bb;
|
self->b = bb;
|
||||||
self->vertical = vert;
|
self->vertical = vert;
|
||||||
self->children = [NSMutableArray new];
|
self->children = [NSMutableArray new];
|
||||||
|
self->nStretchy = 0;
|
||||||
|
|
||||||
#if 0 /* TODO */
|
|
||||||
if (self->vertical) {
|
if (self->vertical) {
|
||||||
self->primaryStart = NSLayoutAttributeTop;
|
self->primaryStart = NSLayoutAttributeTop;
|
||||||
self->primaryEnd = NSLayoutAttributeBottom;
|
self->primaryEnd = NSLayoutAttributeBottom;
|
||||||
|
@ -88,7 +92,6 @@ struct uiBox {
|
||||||
self->primaryOrientation = NSLayoutConstraintOrientationHorizontal;
|
self->primaryOrientation = NSLayoutConstraintOrientationHorizontal;
|
||||||
self->secondaryOrientation = NSLayoutConstraintOrientationVertical;
|
self->secondaryOrientation = NSLayoutConstraintOrientationVertical;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -98,6 +101,8 @@ struct uiBox {
|
||||||
boxChild *bc;
|
boxChild *bc;
|
||||||
|
|
||||||
[self removeOurConstraints];
|
[self removeOurConstraints];
|
||||||
|
[self->inBetweens release];
|
||||||
|
[self->otherConstraints release];
|
||||||
|
|
||||||
for (bc in self->children) {
|
for (bc in self->children) {
|
||||||
uiControlSetParent(bc.c, NULL);
|
uiControlSetParent(bc.c, NULL);
|
||||||
|
@ -109,7 +114,24 @@ struct uiBox {
|
||||||
|
|
||||||
- (void)removeOurConstraints
|
- (void)removeOurConstraints
|
||||||
{
|
{
|
||||||
// TODO
|
if (self->first != nil) {
|
||||||
|
[self removeConstraint:self->first];
|
||||||
|
[self->first release];
|
||||||
|
self->first = nil;
|
||||||
|
}
|
||||||
|
if ([self->inBetweens count] != 0) {
|
||||||
|
[self removeConstraints:self->inBetweens];
|
||||||
|
[self->inBetweens removeAllObjects];
|
||||||
|
}
|
||||||
|
if (self->last != nil) {
|
||||||
|
[self removeConstraint:self->last];
|
||||||
|
[self->last release];
|
||||||
|
self->last = nil;
|
||||||
|
}
|
||||||
|
if ([self->otherConstraints count] != 0) {
|
||||||
|
[self removeConstraints:self->otherConstraints];
|
||||||
|
[self->otherConstraints removeAllObjects];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)syncEnableStates:(int)enabled
|
- (void)syncEnableStates:(int)enabled
|
||||||
|
@ -130,67 +152,148 @@ struct uiBox {
|
||||||
// TODO something about spinbox hugging
|
// TODO something about spinbox hugging
|
||||||
- (void)updateConstraints
|
- (void)updateConstraints
|
||||||
{
|
{
|
||||||
|
boxChild *bc;
|
||||||
|
CGFloat padding;
|
||||||
|
NSView *prev;
|
||||||
|
NSLayoutConstraint *c;
|
||||||
|
|
||||||
[super updateConstraints];
|
[super updateConstraints];
|
||||||
|
if ([self->children count] == 0)
|
||||||
|
return;
|
||||||
|
padding = [self paddingAmount];
|
||||||
|
|
||||||
|
// first arrange in the primary direction
|
||||||
|
prev = nil;
|
||||||
|
for (bc in self->children) {
|
||||||
|
if (prev == nil) { // first view
|
||||||
|
self->first = mkConstraint(self, self->primaryStart,
|
||||||
|
NSLayoutRelationEqual,
|
||||||
|
[bc view], self->primaryStart,
|
||||||
|
1, 0,
|
||||||
|
@"uiBox first primary constraint");
|
||||||
|
[self addConstraint:self->first];
|
||||||
|
[self->first retain];
|
||||||
|
prev = [bc view];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// not the first; link it
|
||||||
|
c = mkConstraint(prev, self->primaryEnd,
|
||||||
|
NSLayoutRelationEqual,
|
||||||
|
[bc view], self->primaryStart,
|
||||||
|
1, padding,
|
||||||
|
@"uiBox in-between primary constraint");
|
||||||
|
[self addConstraint:c];
|
||||||
|
[self->inBetweens addObject:c];
|
||||||
|
prev = [bc view];
|
||||||
|
}
|
||||||
|
self->last = mkConstraint(prev, self->primaryEnd,
|
||||||
|
NSLayoutRelationEqual,
|
||||||
|
self, self->primaryEnd,
|
||||||
|
1, 0,
|
||||||
|
@"uiBox last primary constraint");
|
||||||
|
[self addConstraint:self->last];
|
||||||
|
[self->last retain];
|
||||||
|
|
||||||
|
// then arrange in the secondary direction
|
||||||
|
for (bc in self->children) {
|
||||||
|
c = mkConstraint(self, b->secondaryStart,
|
||||||
|
NSLayoutRelationEqual,
|
||||||
|
[bc view], b->secondaryStart,
|
||||||
|
1, 0,
|
||||||
|
@"uiBox secondary start constraint");
|
||||||
|
[self->otherConstraints addObject:c];
|
||||||
|
c = mkConstraint([bc view], b->secondaryEnd,
|
||||||
|
NSLayoutRelationEqual,
|
||||||
|
self, b->secondaryEnd,
|
||||||
|
1, 0,
|
||||||
|
@"uiBox secondary end constraint");
|
||||||
|
[self->otherConstraints addObject:c];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO stretchies
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)append:(uiControl *)c stretchy:(int)stretchy
|
- (void)append:(uiControl *)c stretchy:(int)stretchy
|
||||||
{
|
{
|
||||||
boxChild *bc;
|
boxChild *bc;
|
||||||
NSView *childView;
|
NSView *childView;
|
||||||
|
NSLayoutPriority priority;
|
||||||
|
uintmax_t oldnStretchy;
|
||||||
|
|
||||||
bc = [boxChild new];
|
bc = [boxChild new];
|
||||||
bc.c = c;
|
bc.c = c;
|
||||||
bc.stretchy = stretchy;
|
bc.stretchy = stretchy;
|
||||||
childView = [bc view];
|
childView = [bc view];
|
||||||
#if 0 /* TODO */
|
bc.oldPrimaryHuggingPri = [childView contentHuggingPriorityForOrientation:self->primaryOrientation];
|
||||||
bc.oldHorzHuggingPri = horzHuggingPri(childView);
|
bc.oldSecondaryHuggingPri = [childView contentHuggingPriorityForOrientation:self->secondaryOrientation];
|
||||||
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 (bc.stretchy)
|
||||||
setHuggingPri(childView, NSLayoutPriorityDefaultLow, self->primaryOrientation);
|
priority = NSLayoutPriorityDefaultLow;
|
||||||
else
|
else
|
||||||
// TODO will default high work?
|
// TODO will default high work?
|
||||||
setHuggingPri(childView, NSLayoutPriorityRequired, self->primaryOrientation);
|
priority = NSLayoutPriorityRequired;
|
||||||
|
[childView setContentHuggingPriority:priority forOrientation: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);
|
[childView setContentHuggingPriority:NSLayoutPriorityDefaultLow forOrientation:self->secondaryOrientation];
|
||||||
#endif
|
|
||||||
|
|
||||||
[self->children addObject:bc];
|
[self->children addObject:bc];
|
||||||
[bc release]; // we don't need the initial reference now
|
|
||||||
|
|
||||||
[self removeOurConstraints];
|
[self removeOurConstraints];
|
||||||
[self setNeedsUpdateConstraints:YES];
|
[self setNeedsUpdateConstraints:YES];
|
||||||
|
if (bc.stretchy) {
|
||||||
|
oldnStretchy = self->nStretchy;
|
||||||
|
self->nStretchy++;
|
||||||
|
if (oldnStretchy == 0) {
|
||||||
|
// TODO isolate into its own function?
|
||||||
|
uiControl *parent;
|
||||||
|
|
||||||
|
parent = uiControlParent(uiControl(self->b));
|
||||||
|
if (parent != NULL)
|
||||||
|
uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl(parent));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[bc release]; // we don't need the initial reference now
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)delete:(uintmax_t)n
|
- (void)delete:(uintmax_t)n
|
||||||
{
|
{
|
||||||
boxChild *bc;
|
boxChild *bc;
|
||||||
NSView *removedView;
|
NSView *removedView;
|
||||||
|
int stretchy;
|
||||||
|
|
||||||
// TODO separate into a method?
|
// TODO separate into a method?
|
||||||
bc = (boxChild *) [self->children objectAtIndex:n];
|
bc = (boxChild *) [self->children objectAtIndex:n];
|
||||||
removedView = [bc view];
|
removedView = [bc view];
|
||||||
|
stretchy = bc.stretchy;
|
||||||
|
|
||||||
uiControlSetParent(bc.c, NULL);
|
uiControlSetParent(bc.c, NULL);
|
||||||
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), nil);
|
uiDarwinControlSetSuperview(uiDarwinControl(bc.c), nil);
|
||||||
|
|
||||||
#if 0 /* TODO */
|
[removedView setContentHuggingPriority:bc.oldPrimaryHuggingPri forOrientation:self->primaryOrientation];
|
||||||
setHorzHuggingPri(removedView, bc.oldHorzHuggingPri);
|
[removedView setContentHuggingPriority:bc.oldSecondaryHuggingPri forOrientation:self->secondaryOrientation];
|
||||||
setVertHuggingPri(removedView, bc.oldVertHuggingPri);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
[self->children removeObjectAtIndex:n];
|
[self->children removeObjectAtIndex:n];
|
||||||
|
|
||||||
[self removeOurConstraints];
|
[self removeOurConstraints];
|
||||||
[self setNeedsUpdateConstraints:YES];
|
[self setNeedsUpdateConstraints:YES];
|
||||||
|
if (stretchy) {
|
||||||
|
self->nStretchy--;
|
||||||
|
if (self->nStretchy == 0) {
|
||||||
|
// TODO isolate into its own function?
|
||||||
|
uiControl *parent;
|
||||||
|
|
||||||
|
parent = uiControlParent(uiControl(self->b));
|
||||||
|
if (parent != NULL)
|
||||||
|
uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl(parent));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)isPadded
|
- (int)isPadded
|
||||||
|
@ -205,13 +308,25 @@ struct uiBox {
|
||||||
|
|
||||||
self->padded = p;
|
self->padded = p;
|
||||||
padding = [self paddingAmount];
|
padding = [self paddingAmount];
|
||||||
#if 0 /* TODO */
|
|
||||||
for (c in self->inBetweens)
|
for (c in self->inBetweens)
|
||||||
[c setConstant:padding];
|
[c setConstant:padding];
|
||||||
#endif
|
|
||||||
// TODO call anything?
|
// TODO call anything?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)hugsTrailing
|
||||||
|
{
|
||||||
|
if (self->vertical) // always hug if vertical
|
||||||
|
return YES;
|
||||||
|
return self->nStretchy != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)hugsBottom
|
||||||
|
{
|
||||||
|
if (!self->vertical) // always hug if horizontal
|
||||||
|
return YES;
|
||||||
|
return self->nStretchy != 0;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
static void uiBoxDestroy(uiControl *c)
|
static void uiBoxDestroy(uiControl *c)
|
||||||
|
@ -245,6 +360,29 @@ static void uiBoxSyncEnableState(uiDarwinControl *c, int enabled)
|
||||||
|
|
||||||
uiDarwinControlDefaultSetSuperview(uiBox, view)
|
uiDarwinControlDefaultSetSuperview(uiBox, view)
|
||||||
|
|
||||||
|
static BOOL uiBoxHugsTrailing(uiDarwinControl *c)
|
||||||
|
{
|
||||||
|
uiBox *b = uiBox(c);
|
||||||
|
|
||||||
|
return [b->view hugsTrailing];
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL uiBoxHugsBottom(uiDarwinControl *c)
|
||||||
|
{
|
||||||
|
uiBox *b = uiBox(c);
|
||||||
|
|
||||||
|
return [b->view hugsBottom];
|
||||||
|
}
|
||||||
|
|
||||||
|
static void uiBoxChildEdgeHuggingChanged(uiDarwinControl *c)
|
||||||
|
{
|
||||||
|
uiBox *b = uiBox(c);
|
||||||
|
|
||||||
|
[b->view removeOurConstraints];
|
||||||
|
[b->view setNeedsUpdateConstraints:YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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];
|
||||||
|
|
Loading…
Reference in New Issue