Resolved that TODO.

This commit is contained in:
Pietro Gagliardi 2015-08-02 18:54:33 -04:00
parent 03212b6b02
commit 2fe193563e
5 changed files with 53 additions and 32 deletions

View File

@ -76,8 +76,15 @@
pp.vertAttachBottom = subvertbottom; pp.vertAttachBottom = subvertbottom;
pp.views = p->views; pp.views = p->views;
pp.n = p->n; pp.n = p->n;
pp.stretchyVert = self->vertical; if (self->vertical) {
pp.firstStretchy = TRUE; 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++) { for (i = 0; i < [self->children count]; i++) {
id<tControl> cur; id<tControl> cur;
NSNumber *isStretchy; NSNumber *isStretchy;
@ -85,22 +92,30 @@
first[i] = pp.n; first[i] = pp.n;
cur = (id<tControl>) [self->children objectAtIndex:i]; cur = (id<tControl>) [self->children objectAtIndex:i];
isStretchy = (NSNumber *) [self->stretchy objectAtIndex:i]; isStretchy = (NSNumber *) [self->stretchy objectAtIndex:i];
pp.stretchy = [isStretchy boolValue];
if (self->vertical) { if (self->vertical) {
pp.vertStretchy = [isStretchy boolValue];
pp.vertFirst = p->vertFirst && i == 0; pp.vertFirst = p->vertFirst && i == 0;
pp.vertLast = p->vertLast && i == ([self->children count] - 1); pp.vertLast = p->vertLast && i == ([self->children count] - 1);
pp.horzFirst = p->horzFirst; pp.horzFirst = p->horzFirst;
pp.horzLast = p->horzLast; pp.horzLast = p->horzLast;
} else { } else {
pp.horzStretchy = [isStretchy boolValue];
pp.horzFirst = p->horzFirst && i == 0; pp.horzFirst = p->horzFirst && i == 0;
pp.horzLast = p->horzLast && i == ([self->children count] - 1); pp.horzLast = p->horzLast && i == ([self->children count] - 1);
pp.vertFirst = p->vertFirst; pp.vertFirst = p->vertFirst;
pp.vertLast = p->vertLast; pp.vertLast = p->vertLast;
} }
[cur tFillAutoLayout:&pp]; [cur tFillAutoLayout:&pp];
if (pp.stretchy && pp.firstStretchy) { if (self->vertical) {
pp.firstStretchy = FALSE; if (pp.vertStretchy && pp.vertFirstStretchy) {
pp.stretchyTo = first[i]; pp.vertFirstStretchy = NO;
pp.vertStretchyTo = first[i];
}
} else {
if (pp.horzStretchy && pp.horzFirstStretchy) {
pp.horzFirstStretchy = NO;
pp.horzStretchyTo = first[i];
}
} }
} }
p->n = pp.n; p->n = pp.n;
@ -146,6 +161,7 @@
// TODOs: // TODOs:
// - lateral dimension: for each view of n+1, make other dimension next to first n // - lateral dimension: for each view of n+1, make other dimension next to first n
// this way, subelement views get positioned right // this way, subelement views get positioned right
// - don't pin to end if no controls are stretchy
- (void)tRelayout - (void)tRelayout
{ {

View File

@ -39,20 +39,19 @@
key = tAutoLayoutKey(p->n); key = tAutoLayoutKey(p->n);
p->n++; p->n++;
horzpred = @""; horzpred = @"";
vertpred = @""; if (p->horzStretchy)
if (p->stretchy) { if (p->horzFirstStretchy)
NSString *predicate;
if (p->firstStretchy)
// TODO is this unnecessary? it seems like I need to do other things instead of this to ensure stretchiness... // TODO is this unnecessary? it seems like I need to do other things instead of this to ensure stretchiness...
predicate = @"(>=0)"; horzpred = @"(>=0)";
else else
predicate = [NSString stringWithFormat:@"(==%@)", tAutoLayoutKey(p->stretchyTo)]; horzpred = [NSString stringWithFormat:@"(==%@)", tAutoLayoutKey(p->horzStretchyTo)];
if (p->stretchyVert) vertpred = @"";
vertpred = predicate; if (p->vertStretchy)
if (p->vertFirstStretchy)
// TODO is this unnecessary? it seems like I need to do other things instead of this to ensure stretchiness...
vertpred = @"(>=0)";
else else
horzpred = predicate; vertpred = [NSString stringWithFormat:@"(==%@)", tAutoLayoutKey(p->vertStretchyTo)];
}
[p->horz addObject:[NSString stringWithFormat:@"[%@%@]", key, horzpred]]; [p->horz addObject:[NSString stringWithFormat:@"[%@%@]", key, horzpred]];
[p->horzAttachLeft addObject:[NSNumber numberWithBool:p->horzFirst]]; [p->horzAttachLeft addObject:[NSNumber numberWithBool:p->horzFirst]];
[p->horzAttachRight addObject:[NSNumber numberWithBool:p->horzLast]]; [p->horzAttachRight addObject:[NSNumber numberWithBool:p->horzLast]];

View File

@ -19,10 +19,12 @@ struct tAutoLayoutParams {
BOOL vertLast; BOOL vertLast;
NSMutableDictionary *views; NSMutableDictionary *views;
uintmax_t n; uintmax_t n;
BOOL stretchy; BOOL horzStretchy;
BOOL stretchyVert; BOOL horzFirstStretchy;
BOOL firstStretchy; uintmax_t horzStretchyTo;
uintmax_t stretchyTo; BOOL vertStretchy;
BOOL vertFirstStretchy;
uintmax_t vertStretchyTo;
}; };
@protocol tControl @protocol tControl

View File

@ -83,19 +83,19 @@
key = tAutoLayoutKey(p->n); key = tAutoLayoutKey(p->n);
p->n++; p->n++;
horzpred = @"(==96)"; // TODO only the entry horzpred = @"(==96)"; // TODO only the entry
if (p->horzStretchy)
if (p->horzFirstStretchy)
// TODO is this unnecessary? it seems like I need to do other things instead of this to ensure stretchiness...
horzpred = @"(>=0)";
else
horzpred = [NSString stringWithFormat:@"(==%@)", tAutoLayoutKey(p->horzStretchyTo)];
vertpred = @""; vertpred = @"";
if (p->stretchy) { if (p->vertStretchy)
NSString *predicate; if (p->vertFirstStretchy)
// TODO is this unnecessary? it seems like I need to do other things instead of this to ensure stretchiness...
if (p->firstStretchy) vertpred = @"(>=0)";
predicate = @"(>=0)";
else else
predicate = [NSString stringWithFormat:@"(==%@)", tAutoLayoutKey(p->stretchyTo)]; vertpred = [NSString stringWithFormat:@"(==%@)", tAutoLayoutKey(p->vertStretchyTo)];
if (p->stretchyVert)
vertpred = predicate;
else
horzpred = predicate;
}
[p->horz addObject:[NSString stringWithFormat:@"[%@%@]", key, horzpred]]; [p->horz addObject:[NSString stringWithFormat:@"[%@%@]", key, horzpred]];
[p->horzAttachLeft addObject:[NSNumber numberWithBool:p->horzFirst]]; [p->horzAttachLeft addObject:[NSNumber numberWithBool:p->horzFirst]];
[p->horzAttachRight addObject:[NSNumber numberWithBool:p->horzLast]]; [p->horzAttachRight addObject:[NSNumber numberWithBool:p->horzLast]];

View File

@ -64,6 +64,10 @@
p.vertLast = YES; p.vertLast = YES;
p.views = [NSMutableDictionary new]; p.views = [NSMutableDictionary new];
p.n = 0; p.n = 0;
p.horzStretchy = YES; // assumption for the sole control to avoid fixed size hacks
p.horzFirstStretchy = YES;
p.vertStretchy = YES;
p.vertFirstStretchy = YES;
[self->c tFillAutoLayout:&p]; [self->c tFillAutoLayout:&p];
margin = @""; margin = @"";