Converted box.m's auto layout code to the new format. Stretchiness isn't handled yet. Next up is box.m's actual view itself.
This commit is contained in:
parent
bdf3bed5f4
commit
f275a9a043
|
@ -49,146 +49,66 @@
|
||||||
// TODO MASSIVE CLEANUP and comments everywhere too
|
// TODO MASSIVE CLEANUP and comments everywhere too
|
||||||
- (void)tFillAutoLayout:(tAutoLayoutParams *)p
|
- (void)tFillAutoLayout:(tAutoLayoutParams *)p
|
||||||
{
|
{
|
||||||
NSMutableArray *subhorz, *subvert;
|
NSMutableDictionary *views;
|
||||||
NSMutableArray *subhorzleft, *subhorzright;
|
__block uintmax_t n;
|
||||||
NSMutableArray *subverttop, *subvertbottom;
|
|
||||||
__block uintmax_t *first;
|
|
||||||
NSUInteger i;
|
|
||||||
tAutoLayoutParams pp;
|
tAutoLayoutParams pp;
|
||||||
void (^buildPrimary)(NSMutableArray *in, BOOL first, BOOL last,
|
__block BOOL anyStretchy;
|
||||||
NSMutableArray *out, NSMutableArray *outstart, NSMutableArray *outend);
|
NSMutableString *constraint;
|
||||||
|
|
||||||
first = (uintmax_t *) malloc([self->children count] * sizeof (uintmax_t));
|
views = [NSMutableDictionary new];
|
||||||
if (first == NULL)
|
n = 0;
|
||||||
abort();
|
anyStretchy = NO;
|
||||||
subhorz = [NSMutableArray new];
|
[self->children enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
||||||
subhorzleft = [NSMutableArray new];
|
id<tControl> c;
|
||||||
subhorzright = [NSMutableArray new];
|
|
||||||
subvert = [NSMutableArray new];
|
|
||||||
subverttop = [NSMutableArray new];
|
|
||||||
subvertbottom = [NSMutableArray new];
|
|
||||||
|
|
||||||
pp.horz = subhorz;
|
|
||||||
pp.horzAttachLeft = subhorzleft;
|
|
||||||
pp.horzAttachRight = subhorzright;
|
|
||||||
pp.vert = subvert;
|
|
||||||
pp.vertAttachTop = subverttop;
|
|
||||||
pp.vertAttachBottom = subvertbottom;
|
|
||||||
pp.views = p->views;
|
|
||||||
pp.n = p->n;
|
|
||||||
if (self->vertical) {
|
|
||||||
pp.vertFirstStretchy = YES;
|
|
||||||
pp.horzStretchy = YES;
|
|
||||||
pp.horzFirstStretchy = YES;
|
|
||||||
} else {
|
|
||||||
pp.horzFirstStretchy = YES;
|
|
||||||
pp.vertStretchy = YES;
|
|
||||||
pp.vertFirstStretchy = YES;
|
|
||||||
}
|
|
||||||
for (i = 0; i < [self->children count]; i++) {
|
|
||||||
id<tControl> cur;
|
|
||||||
NSNumber *isStretchy;
|
NSNumber *isStretchy;
|
||||||
|
|
||||||
first[i] = pp.n;
|
c = (id<tControl>) obj;
|
||||||
cur = (id<tControl>) [self->children objectAtIndex:i];
|
isStretchy = (NSNumber *) [self->stretchy objectAtIndex:index];
|
||||||
isStretchy = (NSNumber *) [self->stretchy objectAtIndex:i];
|
if ([isStretchy boolValue])
|
||||||
if (self->vertical) {
|
anyStretchy = YES;
|
||||||
pp.vertStretchy = [isStretchy boolValue];
|
[c tFillAutoLayout:&pp];
|
||||||
pp.vertFirst = p->vertFirst && i == 0;
|
[views setObjject:pp.view forKey:tAutoLayoutKey(n)];
|
||||||
pp.vertLast = p->vertLast && i == ([self->children count] - 1);
|
n++;
|
||||||
pp.horzFirst = p->horzFirst;
|
|
||||||
pp.horzLast = p->horzLast;
|
|
||||||
} else {
|
|
||||||
pp.horzStretchy = [isStretchy boolValue];
|
|
||||||
pp.horzFirst = p->horzFirst && i == 0;
|
|
||||||
pp.horzLast = p->horzLast && i == ([self->children count] - 1);
|
|
||||||
pp.vertFirst = p->vertFirst;
|
|
||||||
pp.vertLast = p->vertLast;
|
|
||||||
}
|
|
||||||
[cur tFillAutoLayout:&pp];
|
|
||||||
if (self->vertical) {
|
|
||||||
if (pp.vertStretchy && pp.vertFirstStretchy) {
|
|
||||||
pp.vertFirstStretchy = NO;
|
|
||||||
pp.vertStretchyTo = first[i];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (pp.horzStretchy && pp.horzFirstStretchy) {
|
|
||||||
pp.horzFirstStretchy = NO;
|
|
||||||
pp.horzStretchyTo = first[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p->n = pp.n;
|
|
||||||
|
|
||||||
buildPrimary = ^(NSMutableArray *in, BOOL first, BOOL last,
|
|
||||||
NSMutableArray *out, NSMutableArray *outstart, NSMutableArray *outend) {
|
|
||||||
NSMutableString *outstr;
|
|
||||||
|
|
||||||
outstr = [NSMutableString new];
|
|
||||||
[in enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
|
||||||
//TODO if (index != 0)
|
|
||||||
//TODO [outstr appendString:@"-"];
|
|
||||||
[outstr appendString:((NSString *) obj)];
|
|
||||||
}];
|
}];
|
||||||
[out addObject:outstr];
|
|
||||||
[outstart addObject:[NSNumber numberWithBool:first]];
|
|
||||||
[outend addObject:[NSNumber numberWithBool:last]];
|
|
||||||
};
|
|
||||||
|
|
||||||
if (self->vertical) {
|
// first string the views together
|
||||||
buildPrimary(subvert, p->vertFirst, p->vertLast,
|
constraint = [NSMutableString stringWithString:@"|"];
|
||||||
p->vert, p->vertAttachTop, p->vertAttachBottom);
|
for (i = 0; i < n; i++) {
|
||||||
[p->horz addObjectsFromArray:subhorz];
|
[constraint appendString:@"["];
|
||||||
[p->horzAttachLeft addObjectsFromArray:subhorzleft];
|
[constraint appendString:tAutoLayoutKey(n)];
|
||||||
[p->horzAttachRight addObjectsFromArray:subhorzright];
|
[constraint appendString:@"]"];
|
||||||
} 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];
|
|
||||||
}
|
}
|
||||||
|
[constraint appendString:@"|"];
|
||||||
|
// TODO apply constraint
|
||||||
|
[constraint release];
|
||||||
|
|
||||||
// now constrain the lateral dimension
|
// next make the views span the full other dimension
|
||||||
// all children of item i must be next to the first child of item i+1
|
for (i = 0; i < n; i++) {
|
||||||
// this is so sub-boxes are on the same "line"
|
|
||||||
// TODO move this declaration above
|
|
||||||
void (^lateral)(NSMutableArray *, BOOL, BOOL, NSMutableArray *, NSMutableArray *) = ^(NSMutableArray *out, BOOL xfirst, BOOL last, NSMutableArray *outstart, NSMutableArray *outend) {
|
|
||||||
NSUInteger i;
|
|
||||||
uintmax_t j;
|
|
||||||
|
|
||||||
for (i = 0; i < [self->children count] - 1; i++)
|
|
||||||
for (j = first[i]; j < first[i + 1]; j++) {
|
|
||||||
NSString *c1, *c2;
|
|
||||||
NSString *constraint;
|
|
||||||
|
|
||||||
c1 = tAutoLayoutKey(j);
|
|
||||||
c2 = tAutoLayoutKey(first[i + 1]);
|
|
||||||
constraint = [NSString stringWithFormat:@"[%@][%@]", c1, c2];
|
|
||||||
[out addObject:constraint];
|
|
||||||
[outstart addObject:[NSNumber numberWithBool:xfirst]];
|
|
||||||
[outend addObject:[NSNumber numberWithBool:last]];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (self->vertical)
|
if (self->vertical)
|
||||||
lateral(p->vert, p->vertFirst, p->vertLast, p->vertAttachTop, p->vertAttachBottom);
|
constraint = [NSMutableString stringWithString:@"H:|"];
|
||||||
else
|
else
|
||||||
lateral(p->horz, p->horzFirst, p->horzLast, p->horzAttachLeft, p->horzAttachRight);
|
constraint = [NSMutableString stringWithString:@"V:|"];
|
||||||
|
[constraint appendString:tAutoLayoutKey(n)];
|
||||||
[subhorz release];
|
[constraint appendString:@"]|"];
|
||||||
[subhorzleft release];
|
// TODO apply constraint
|
||||||
[subhorzright release];
|
[constraint release];
|
||||||
[subvert release];
|
|
||||||
[subverttop release];
|
|
||||||
[subvertbottom release];
|
|
||||||
free(first);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODOs:
|
[views release];
|
||||||
// - lateral dimension: for each view of n+1, make other dimension next to first n
|
|
||||||
// this way, subelement views get positioned right
|
// and now populate for self
|
||||||
// - don't pin to end if no controls are stretchy
|
p->view = TODO;
|
||||||
|
p->attachLeft = YES;
|
||||||
|
p->attachTop = YES;
|
||||||
|
// don't attach to the end if there weren't any stretchy controls
|
||||||
|
if (self->vertical) {
|
||||||
|
p->attachRight = YES;
|
||||||
|
p->attachBottom = anyStretchy;
|
||||||
|
} else {
|
||||||
|
p->attachRight = anyStretchy;
|
||||||
|
p->attachBottom = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)tRelayout
|
- (void)tRelayout
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue