Fixed crashing. Made relayouts optional in tSetParent. Rewrote the tBox auto layout code a fair bit, thinking crashing was caused by stack overflow (it was not).

This commit is contained in:
Pietro Gagliardi 2015-08-02 18:16:44 -04:00
parent 4a97a3cdb9
commit ebae310ff1
5 changed files with 42 additions and 53 deletions

View File

@ -25,14 +25,14 @@
- (void)tAddControl:(id<tControl>)c stretchy:(BOOL)s - (void)tAddControl:(id<tControl>)c stretchy:(BOOL)s
{ {
if (self->sv != nil) if (self->sv != nil)
[c tSetParent:self->parent addToView:self->sv]; [c tSetParent:self addToView:self->sv relayout:NO];
[self->children addObject:c]; [self->children addObject:c];
[self->stretchy addObject:[NSNumber numberWithBool:s]]; [self->stretchy addObject:[NSNumber numberWithBool:s]];
// TODO mark as needing relayout // TODO mark as needing relayout
[self tRelayout]; [self tRelayout];
} }
- (void)tSetParent:(id<tControl>)p addToView:(NSView *)v - (void)tSetParent:(id<tControl>)p addToView:(NSView *)v relayout:(BOOL)relayout
{ {
self->parent = p; self->parent = p;
self->sv = v; self->sv = v;
@ -40,8 +40,9 @@
id<tControl> c; id<tControl> c;
c = (id<tControl>) obj; c = (id<tControl>) obj;
[c tSetParent:self->parent addToView:self->sv]; [c tSetParent:self addToView:self->sv relayout:NO];
}]; }];
if (relayout)
[self tRelayout]; [self tRelayout];
} }
@ -53,14 +54,9 @@
NSMutableArray *subverttop, *subvertbottom; NSMutableArray *subverttop, *subvertbottom;
uintmax_t *first; uintmax_t *first;
NSUInteger i; NSUInteger i;
NSMutableString *out;
tAutoLayoutParams pp; tAutoLayoutParams pp;
NSMutableArray *primaryin, *primaryout; void (^buildPrimary)(NSMutableArray *in, BOOL first, BOOL last,
BOOL primaryinstart, primaryinend; NSMutableArray *out, NSMutableArray *outstart, NSMutableArray *outend);
NSMutableArray *primaryoutstart, *primaryoutend;
NSMutableArray *secondaryin, *secondaryout;
NSMutableArray *secondaryinstart, *secondaryinend;
NSMutableArray *secondaryoutstart, *secondaryoutend;
first = (uintmax_t *) malloc([self->children count] * sizeof (uintmax_t)); first = (uintmax_t *) malloc([self->children count] * sizeof (uintmax_t));
if (first == NULL) if (first == NULL)
@ -109,44 +105,34 @@
} }
p->n = pp.n; p->n = pp.n;
out = [NSMutableString new]; buildPrimary = ^(NSMutableArray *in, BOOL first, BOOL last,
primaryin = subhorz; NSMutableArray *out, NSMutableArray *outstart, NSMutableArray *outend) {
primaryinstart = p->horzFirst; NSMutableString *outstr;
primaryinend = p->horzLast;
primaryout = p->horz; outstr = [NSMutableString new];
primaryoutstart = p->horzAttachLeft; [in enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
primaryoutend = p->horzAttachRight;
secondaryin = subvert;
secondaryinstart = subverttop;
secondaryinend = subvertbottom;
secondaryout = p->vert;
secondaryoutstart = p->vertAttachTop;
secondaryoutend = p->vertAttachBottom;
if (self->vertical) {
primaryin = subvert;
primaryinstart = p->vertFirst;
primaryinend = p->vertLast;
primaryout = p->vert;
primaryoutstart = p->vertAttachTop;
primaryoutend = p->vertAttachBottom;
secondaryin = subhorz;
secondaryinstart = subhorzleft;
secondaryinend = subhorzright;
secondaryout = p->horz;
secondaryoutstart = p->horzAttachLeft;
secondaryoutend = p->horzAttachRight;
}
[primaryin enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
//TODO if (index != 0) //TODO if (index != 0)
//TODO [out appendString:@"-"]; //TODO [outstr appendString:@"-"];
[out appendString:((NSString *) obj)]; [outstr appendString:((NSString *) obj)];
}]; }];
[primaryout addObject:out]; [out addObject:outstr];
[primaryoutstart addObject:[NSNumber numberWithBool:primaryinstart]]; [outstart addObject:[NSNumber numberWithBool:first]];
[primaryoutend addObject:[NSNumber numberWithBool:primaryinend]]; [outend addObject:[NSNumber numberWithBool:last]];
[secondaryout addObjectsFromArray:secondaryin]; };
[secondaryoutstart addObjectsFromArray:secondaryinstart];
[secondaryoutend addObjectsFromArray:secondaryinend]; if (self->vertical) {
buildPrimary(subvert, p->vertFirst, p->vertLast,
p->vert, p->vertAttachTop, p->vertAttachBottom);
[p->horz addObjectsFromArray:subhorz];
[p->horzAttachLeft addObjectsFromArray:subhorzleft];
[p->horzAttachRight addObjectsFromArray:subhorzright];
} else {
buildPrimary(subhorz, p->horzFirst, p->horzLast,
p->horz, p->horzAttachLeft, p->horzAttachRight);
[p->vert addObjectsFromArray:subvert];
[p->vertAttachTop addObjectsFromArray:subverttop];
[p->vertAttachBottom addObjectsFromArray:subvertbottom];
}
[subhorz release]; [subhorz release];
[subhorzleft release]; [subhorzleft release];

View File

@ -23,10 +23,11 @@
return self; return self;
} }
- (void)tSetParent:(id<tControl>)p addToView:(NSView *)v - (void)tSetParent:(id<tControl>)p addToView:(NSView *)v relayout:(BOOL)relayout
{ {
self->parent = p; self->parent = p;
[v addSubview:self->b]; [v addSubview:self->b];
if (relayout)
[self tRelayout]; [self tRelayout];
} }

View File

@ -25,7 +25,7 @@ struct tAutoLayoutParams {
@protocol tControl @protocol tControl
@required @required
- (void)tSetParent:(id<tControl>)p addToView:(NSView *)v; - (void)tSetParent:(id<tControl>)p addToView:(NSView *)v relayout:(BOOL)relayout;
- (void)tFillAutoLayout:(tAutoLayoutParams *)p; - (void)tFillAutoLayout:(tAutoLayoutParams *)p;
- (void)tRelayout; - (void)tRelayout;
@end @end

View File

@ -67,10 +67,12 @@
return self; return self;
} }
- (void)tSetParent:(id<tControl>)p addToView:(NSView *)v - (void)tSetParent:(id<tControl>)p addToView:(NSView *)v relayout:(BOOL)relayout
{ {
self->parent = p; self->parent = p;
[v addSubview:self->c]; [v addSubview:self->c];
if (relayout)
[self tRelayout];
} }
- (void)tFillAutoLayout:(tAutoLayoutParams *)p - (void)tFillAutoLayout:(tAutoLayoutParams *)p

View File

@ -23,7 +23,7 @@
- (void)tSetControl:(id<tControl>)cc - (void)tSetControl:(id<tControl>)cc
{ {
self->c = cc; self->c = cc;
[self->c tSetParent:self addToView:[self->w contentView]]; [self->c tSetParent:self addToView:[self->w contentView] relayout:NO];
[self tRelayout]; [self tRelayout];
} }