diff --git a/redo/osxaltest/button.m b/redo/osxaltest/button.m index 29924957..26562ef7 100644 --- a/redo/osxaltest/button.m +++ b/redo/osxaltest/button.m @@ -15,6 +15,7 @@ [self->b setBordered:YES]; [self->b setBezelStyle:NSRoundedBezelStyle]; [self->b setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]]; + [self->b setTranslatesAutoresizingMaskIntoConstraints:NO]; } return self; } @@ -31,4 +32,15 @@ return n; } +- (void)tFillAutoLayoutHorz:(NSMutableString *)horz + vert:(NSMutableString *)vert + extra:(NSMutableArray *)extra + extraVert:(NSMutableArray *)extraVert + views:(NSMutableDictionary *)views +{ + [horz setString:@"[view0]"]; + [vert setString:@"[view0]"]; + [views setObject:self->b forKey:@"view0"]; +} + @end diff --git a/redo/osxaltest/osxaltest.h b/redo/osxaltest/osxaltest.h index 9fdd9fda..1dc0d9c4 100644 --- a/redo/osxaltest/osxaltest.h +++ b/redo/osxaltest/osxaltest.h @@ -5,7 +5,12 @@ @protocol tControl @required - (void)tAddToView:(NSView *)v; -- (uintmax_t)tAddToAutoLayoutDictionary:(NSMutableDictionary *)views keyNumber:(uintmax_t)n; +//TODO- (uintmax_t)tAddToAutoLayoutDictionary:(NSMutableDictionary *)views keyNumber:(uintmax_t)n; +- (void)tFillAutoLayoutHorz:(NSMutableString *)horz + vert:(NSMutableString *)vert + extra:(NSMutableArray *)extra + extraVert:(NSMutableArray *)extraVert + views:(NSMutableDictionary *)views; @end @interface tWindow : NSObject diff --git a/redo/osxaltest/window.m b/redo/osxaltest/window.m new file mode 100644 index 00000000..5cef681c --- /dev/null +++ b/redo/osxaltest/window.m @@ -0,0 +1,71 @@ +// 1 august 2015 +#include "osxaltest.h" + +@implementation tWindow { + NSWindow *w; + id c; +} + +- (id)init +{ + self = [super init]; + if (self) { + self->w = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 320, 240) + styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask) + backing:NSBackingStoreBuffered + defer:YES]; + [self->w setTitle:@"Auto Layout Test"]; + } + return self; +} + +- (void)tSetControl:(id)cc +{ + self->c = cc; + [self->c tAddToView:[self->w contentView]]; + [self tRelayout]; +} + +- (void)tShow +{ + [self->w cascadeTopLeftFromPoint:NSMakePoint(20, 20)]; + [self->w makeKeyAndOrderFront:self]; +} + +- (void)tRelayout +{ + NSView *contentView; + NSMutableString *horz, *vert; + NSMutableArray *extra, *extraVert; + NSMutableDictionary *views; + NSInteger i; + + contentView = [self->w contentView]; + [contentView removeConstraints:[contentView constraints]]; + horz = [NSMutableString new]; + vert = [NSMutableString new]; + extra = [NSMutableArray new]; + extraVert = [NSMutableArray new]; + views = [NSMutableDictionary new]; + [self->c tFillAutoLayoutHorz:horz vert:vert extra:extra extraVert:extraVert views:views]; + [extra addObject:[NSString stringWithFormat:@"|%@|", horz]]; + [extraVert addObject:@NO]; + [extra addObject:[NSString stringWithFormat:@"|%@|", vert]]; + [extraVert addObject:@YES]; + for (i = 0; i < [extra count]; i++) { + NSString *constraint; + NSNumber *vertical; + NSArray *constraints; + + vertical = (NSNumber *) [extraVert objectAtIndex:i]; + if ([vertical boolValue]) + constraint = [NSString stringWithFormat:@"V:%@", [extra objectAtIndex:i]]; + else + constraint = [NSString stringWithFormat:@"H:%@", [extra objectAtIndex:i]]; + constraints = [NSLayoutConstraint constraintsWithVisualFormat:constraint options:0 metrics:nil views:views]; + [contentView addConstraints:constraints]; + } + // TODO release everything +} + +@end