diff --git a/redo/osxaltest/box.m b/redo/osxaltest/box.m index 2fe12753..f56468db 100644 --- a/redo/osxaltest/box.m +++ b/redo/osxaltest/box.m @@ -76,8 +76,15 @@ pp.vertAttachBottom = subvertbottom; pp.views = p->views; pp.n = p->n; - pp.stretchyVert = self->vertical; - pp.firstStretchy = TRUE; + 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 cur; NSNumber *isStretchy; @@ -85,22 +92,30 @@ first[i] = pp.n; cur = (id) [self->children objectAtIndex:i]; isStretchy = (NSNumber *) [self->stretchy objectAtIndex:i]; - pp.stretchy = [isStretchy boolValue]; if (self->vertical) { + pp.vertStretchy = [isStretchy boolValue]; pp.vertFirst = p->vertFirst && i == 0; pp.vertLast = p->vertLast && i == ([self->children count] - 1); 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 (pp.stretchy && pp.firstStretchy) { - pp.firstStretchy = FALSE; - pp.stretchyTo = first[i]; + 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; @@ -146,6 +161,7 @@ // TODOs: // - lateral dimension: for each view of n+1, make other dimension next to first n // this way, subelement views get positioned right +// - don't pin to end if no controls are stretchy - (void)tRelayout { diff --git a/redo/osxaltest/button.m b/redo/osxaltest/button.m index 47b462c4..45990e97 100644 --- a/redo/osxaltest/button.m +++ b/redo/osxaltest/button.m @@ -39,20 +39,19 @@ key = tAutoLayoutKey(p->n); p->n++; horzpred = @""; - vertpred = @""; - if (p->stretchy) { - NSString *predicate; - - if (p->firstStretchy) + 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... - predicate = @"(>=0)"; + horzpred = @"(>=0)"; else - predicate = [NSString stringWithFormat:@"(==%@)", tAutoLayoutKey(p->stretchyTo)]; - if (p->stretchyVert) - vertpred = predicate; + horzpred = [NSString stringWithFormat:@"(==%@)", tAutoLayoutKey(p->horzStretchyTo)]; + vertpred = @""; + 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 - horzpred = predicate; - } + vertpred = [NSString stringWithFormat:@"(==%@)", tAutoLayoutKey(p->vertStretchyTo)]; [p->horz addObject:[NSString stringWithFormat:@"[%@%@]", key, horzpred]]; [p->horzAttachLeft addObject:[NSNumber numberWithBool:p->horzFirst]]; [p->horzAttachRight addObject:[NSNumber numberWithBool:p->horzLast]]; diff --git a/redo/osxaltest/osxaltest.h b/redo/osxaltest/osxaltest.h index 61b49ebc..90d278ae 100644 --- a/redo/osxaltest/osxaltest.h +++ b/redo/osxaltest/osxaltest.h @@ -19,10 +19,12 @@ struct tAutoLayoutParams { BOOL vertLast; NSMutableDictionary *views; uintmax_t n; - BOOL stretchy; - BOOL stretchyVert; - BOOL firstStretchy; - uintmax_t stretchyTo; + BOOL horzStretchy; + BOOL horzFirstStretchy; + uintmax_t horzStretchyTo; + BOOL vertStretchy; + BOOL vertFirstStretchy; + uintmax_t vertStretchyTo; }; @protocol tControl diff --git a/redo/osxaltest/spinbox.m b/redo/osxaltest/spinbox.m index 409b1a19..b649c268 100644 --- a/redo/osxaltest/spinbox.m +++ b/redo/osxaltest/spinbox.m @@ -83,19 +83,19 @@ key = tAutoLayoutKey(p->n); p->n++; 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 = @""; - if (p->stretchy) { - NSString *predicate; - - if (p->firstStretchy) - predicate = @"(>=0)"; + 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 - predicate = [NSString stringWithFormat:@"(==%@)", tAutoLayoutKey(p->stretchyTo)]; - if (p->stretchyVert) - vertpred = predicate; - else - horzpred = predicate; - } + vertpred = [NSString stringWithFormat:@"(==%@)", tAutoLayoutKey(p->vertStretchyTo)]; [p->horz addObject:[NSString stringWithFormat:@"[%@%@]", key, horzpred]]; [p->horzAttachLeft addObject:[NSNumber numberWithBool:p->horzFirst]]; [p->horzAttachRight addObject:[NSNumber numberWithBool:p->horzLast]]; diff --git a/redo/osxaltest/window.m b/redo/osxaltest/window.m index 5821b48e..95c65c1b 100644 --- a/redo/osxaltest/window.m +++ b/redo/osxaltest/window.m @@ -64,6 +64,10 @@ p.vertLast = YES; p.views = [NSMutableDictionary new]; 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]; margin = @"";