From 554454f036dd2e543a25827094938722f4361a6b Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 1 Aug 2015 15:44:06 -0400 Subject: [PATCH] Added margined to tWindow. --- redo/osxaltest/main.m | 5 +++++ redo/osxaltest/osxaltest.h | 1 + redo/osxaltest/window.m | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/redo/osxaltest/main.m b/redo/osxaltest/main.m index 3b45119f..d1bff409 100644 --- a/redo/osxaltest/main.m +++ b/redo/osxaltest/main.m @@ -3,6 +3,8 @@ // #qo LDFLAGS: -framework Foundation -framework AppKit +BOOL margined = NO; + @interface appDelegate : NSObject @end @@ -14,6 +16,7 @@ tButton *button; mainwin = [[tWindow alloc] init]; + [mainwin tSetMargined:margined]; button = [[tButton alloc] tInitWithText:@"Button"]; [mainwin tSetControl:button]; @@ -32,6 +35,8 @@ int main(int argc, char *argv[]) { NSApplication *app; + margined = argc > 1; + app = [NSApplication sharedApplication]; [app setActivationPolicy:NSApplicationActivationPolicyRegular]; [app setDelegate:[appDelegate new]]; diff --git a/redo/osxaltest/osxaltest.h b/redo/osxaltest/osxaltest.h index 1dc0d9c4..b75b556d 100644 --- a/redo/osxaltest/osxaltest.h +++ b/redo/osxaltest/osxaltest.h @@ -15,6 +15,7 @@ @interface tWindow : NSObject - (void)tSetControl:(id)cc; +- (void)tSetMargined:(BOOL)m; - (void)tShow; // TODO this should probably in tControl - (void)tRelayout; diff --git a/redo/osxaltest/window.m b/redo/osxaltest/window.m index 5cef681c..d04d9c78 100644 --- a/redo/osxaltest/window.m +++ b/redo/osxaltest/window.m @@ -4,6 +4,7 @@ @implementation tWindow { NSWindow *w; id c; + BOOL margined; } - (id)init @@ -26,6 +27,12 @@ [self tRelayout]; } +- (void)tSetMargined:(BOOL)m +{ + self->margined = m; + [self tRelayout]; +} + - (void)tShow { [self->w cascadeTopLeftFromPoint:NSMakePoint(20, 20)]; @@ -39,7 +46,10 @@ NSMutableArray *extra, *extraVert; NSMutableDictionary *views; NSInteger i; + NSString *margin; + if (self->c == nil) + return; contentView = [self->w contentView]; [contentView removeConstraints:[contentView constraints]]; horz = [NSMutableString new]; @@ -48,9 +58,12 @@ extraVert = [NSMutableArray new]; views = [NSMutableDictionary new]; [self->c tFillAutoLayoutHorz:horz vert:vert extra:extra extraVert:extraVert views:views]; - [extra addObject:[NSString stringWithFormat:@"|%@|", horz]]; + margin = @""; + if (self->margined) + margin = @"-"; + [extra addObject:[NSString stringWithFormat:@"|%@%@%@|", margin, horz, margin]]; [extraVert addObject:@NO]; - [extra addObject:[NSString stringWithFormat:@"|%@|", vert]]; + [extra addObject:[NSString stringWithFormat:@"|%@%@%@|", margin, vert, margin]]; [extraVert addObject:@YES]; for (i = 0; i < [extra count]; i++) { NSString *constraint;