From f1b372569afe07d0efdfe2aae000a4e63dfe4891 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 2 Aug 2015 19:27:55 -0400 Subject: [PATCH] Tried to do lateral dimension tuning. Didn't work -_- Recursive tBoxes might have to be individual NSViews as well :| Psy in #macdev said things which confirm that Auto Layout does NOT give me Interface Builder metrics for free. This destroys the whole point... --- redo/osxaltest/box.m | 29 ++++++++++++++++++++++++++++- redo/osxaltest/main.m | 13 +++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/redo/osxaltest/box.m b/redo/osxaltest/box.m index f56468db..a4aead4c 100644 --- a/redo/osxaltest/box.m +++ b/redo/osxaltest/box.m @@ -52,7 +52,7 @@ NSMutableArray *subhorz, *subvert; NSMutableArray *subhorzleft, *subhorzright; NSMutableArray *subverttop, *subvertbottom; - uintmax_t *first; + __block uintmax_t *first; NSUInteger i; tAutoLayoutParams pp; void (^buildPrimary)(NSMutableArray *in, BOOL first, BOOL last, @@ -149,6 +149,33 @@ [p->vertAttachBottom addObjectsFromArray:subvertbottom]; } + // now constrain the lateral dimension + // all children of item i must be next to the first child of item i+1 + // 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) + lateral(p->vert, p->vertFirst, p->vertLast, p->vertAttachTop, p->vertAttachBottom); + else + lateral(p->horz, p->horzFirst, p->horzLast, p->horzAttachLeft, p->horzAttachRight); + [subhorz release]; [subhorzleft release]; [subhorzright release]; diff --git a/redo/osxaltest/main.m b/redo/osxaltest/main.m index a64675e0..14f295bb 100644 --- a/redo/osxaltest/main.m +++ b/redo/osxaltest/main.m @@ -3,7 +3,8 @@ // #qo LDFLAGS: -framework Foundation -framework AppKit -BOOL margined = NO; +BOOL spaced = NO; +BOOL firstvert = YES; @interface appDelegate : NSObject @end @@ -18,23 +19,23 @@ BOOL margined = NO; tSpinbox *spinbox; mainwin = [[tWindow alloc] init]; - [mainwin tSetMargined:margined]; + [mainwin tSetMargined:spaced]; - box = [[tBox alloc] tInitVertical:YES]; + box = [[tBox alloc] tInitVertical:firstvert]; spinbox = [[tSpinbox alloc] init]; [box tAddControl:spinbox stretchy:NO]; [mainwin tSetControl:box]; - hbox = [[tBox alloc] tInitVertical:NO]; + hbox = [[tBox alloc] tInitVertical:!firstvert]; button = [[tButton alloc] tInitWithText:@"Button"]; [hbox tAddControl:button stretchy:YES]; button = [[tButton alloc] tInitWithText:@"Button"]; [hbox tAddControl:button stretchy:YES]; [box tAddControl:hbox stretchy:NO]; - hbox = [[tBox alloc] tInitVertical:NO]; + hbox = [[tBox alloc] tInitVertical:!firstvert]; button = [[tButton alloc] tInitWithText:@"Button"]; [hbox tAddControl:button stretchy:YES]; button = [[tButton alloc] tInitWithText:@"Button"]; @@ -55,7 +56,7 @@ int main(int argc, char *argv[]) { NSApplication *app; - margined = argc > 1; + spaced = argc > 1; app = [NSApplication sharedApplication]; [app setActivationPolicy:NSApplicationActivationPolicyRegular];