diff --git a/redo/osxaltest/main.m b/redo/osxaltest/main.m deleted file mode 100644 index 29e84edc..00000000 --- a/redo/osxaltest/main.m +++ /dev/null @@ -1,100 +0,0 @@ -// 31 july 2015 -#import "osxaltest.h" - -// #qo LDFLAGS: -framework Foundation -framework AppKit - -BOOL spaced = NO; -BOOL firstvert = NO; - -@interface appDelegate : NSObject -@end - -@implementation appDelegate - -- (void)applicationDidFinishLaunching:(NSNotification *)note -{ - tWindow *mainwin; - tBox *box, *hbox; - tButton *button; - tSpinbox *spinbox; - tEntry *entry; - tLabel *label; - - mainwin = [[tWindow alloc] init]; - [mainwin tSetMargined:spaced]; - - box = [[tBox alloc] tInitVertical:firstvert spaced:spaced]; - - spinbox = [[tSpinbox alloc] init]; - [box tAddControl:spinbox stretchy:NO]; - - [mainwin tSetControl:box]; - - hbox = [[tBox alloc] tInitVertical:!firstvert spaced:spaced]; - 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:!firstvert spaced:spaced]; - 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]; - - // TODO in vertical mode the three non-stretchy buttons are smaller than they should be - hbox = [[tBox alloc] tInitVertical:!firstvert spaced:spaced]; - button = [[tButton alloc] tInitWithText:@"Button"]; - [hbox tAddControl:button stretchy:YES]; - button = [[tButton alloc] tInitWithText:@"A"]; - [hbox tAddControl:button stretchy:NO]; - button = [[tButton alloc] tInitWithText:@"BB"]; - [hbox tAddControl:button stretchy:NO]; - button = [[tButton alloc] tInitWithText:@"CCC"]; - [hbox tAddControl:button stretchy:NO]; - [box tAddControl:hbox stretchy:NO]; - - // TODO this isn't stretchy in the proper order - hbox = [[tBox alloc] tInitVertical:!firstvert spaced:spaced]; - spinbox = [[tSpinbox alloc] init]; - [hbox tAddControl:spinbox stretchy:NO]; - spinbox = [[tSpinbox alloc] init]; - [hbox tAddControl:spinbox stretchy:YES]; - [box tAddControl:hbox stretchy:NO]; - - hbox = [[tBox alloc] tInitVertical:!firstvert spaced:spaced]; - entry = [[tEntry alloc] init]; - [hbox tAddControl:entry stretchy:NO]; - entry = [[tEntry alloc] init]; - [hbox tAddControl:entry stretchy:YES]; - [box tAddControl:hbox stretchy:NO]; - - hbox = [[tBox alloc] tInitVertical:!firstvert spaced:spaced]; - label = [[tLabel alloc] init]; - [hbox tAddControl:label stretchy:NO]; - [box tAddControl:hbox stretchy:NO]; - - [mainwin tShow]; -} - -- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)a -{ - return YES; -} - -@end - -int main(int argc, char *argv[]) -{ - NSApplication *app; - - spaced = argc > 1; - - app = [NSApplication sharedApplication]; - [app setActivationPolicy:NSApplicationActivationPolicyRegular]; - [app setDelegate:[appDelegate new]]; - [app run]; - return 0; -} diff --git a/redo/osxaltest/osxaltest.h b/redo/osxaltest/osxaltest.h deleted file mode 100644 index 4f456f64..00000000 --- a/redo/osxaltest/osxaltest.h +++ /dev/null @@ -1,50 +0,0 @@ -// 31 july 2015 -#import -#import - -typedef struct tAutoLayoutParams tAutoLayoutParams; - -// TODO stretchy across both dimensions -// for a vertical box, the horizontal width should be variable -struct tAutoLayoutParams { - NSView *view; - BOOL attachLeft; - BOOL attachTop; - BOOL attachRight; - BOOL attachBottom; - NSString *nonStretchyWidthPredicate; - NSString *nonStretchyHeightPredicate; -}; - -@protocol tControl -@required -- (void)tSetParent:(id)p addToView:(NSView *)v relayout:(BOOL)relayout; -- (void)tFillAutoLayout:(tAutoLayoutParams *)p; -- (void)tRelayout; -@end - -@interface tWindow : NSObject -- (void)tSetControl:(id)cc; -- (void)tSetMargined:(BOOL)m; -- (void)tShow; -@end - -@interface tBox : NSObject -- (id)tInitVertical:(BOOL)vert spaced:(BOOL)sp; -- (void)tAddControl:(id)c stretchy:(BOOL)s; -@end - -@interface tButton : NSObject -- (id)tInitWithText:(NSString *)text; -@end - -@interface tEntry : NSObject -@end - -@interface tLabel : NSObject -@end - -@interface tSpinbox : NSObject -@end - -extern NSString *tAutoLayoutKey(uintmax_t); diff --git a/redo/osxaltest/util.m b/redo/osxaltest/util.m deleted file mode 100644 index 34635ce7..00000000 --- a/redo/osxaltest/util.m +++ /dev/null @@ -1,7 +0,0 @@ -// 1 august 2015 -#import "osxaltest.h" - -NSString *tAutoLayoutKey(uintmax_t n) -{ - return [NSString stringWithFormat:@"view%ju", n]; -} diff --git a/redo/osxaltest/window.m b/redo/osxaltest/window.m deleted file mode 100644 index 89c9b763..00000000 --- a/redo/osxaltest/window.m +++ /dev/null @@ -1,118 +0,0 @@ -// 1 august 2015 -#include "osxaltest.h" - -@implementation NSView (AutoLayoutHelpers) -- (void)tIsAmbiguous:(uintmax_t)indent -{ - NSMutableString *s; - uintmax_t i; - NSUInteger j; - - s = [NSMutableString new]; - for (i = 0; i < indent; i++) - [s appendString:@" "]; - NSLog(@"%@%@ %d", s, [self className], (int) [self hasAmbiguousLayout]); - if ([self hasAmbiguousLayout]) - [[self window] visualizeConstraints:[[self superview] constraints]]; - for (j = 0; j < [[self subviews] count]; j++) - [[[self subviews] objectAtIndex:j] tIsAmbiguous:(indent + 1)]; -} -@end - -@implementation tWindow { - NSWindow *w; - id c; - BOOL margined; -} - -- (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 tSetParent:self addToView:[self->w contentView] relayout:NO]; - [self tRelayout]; -} - -- (void)tSetMargined:(BOOL)m -{ - self->margined = m; - [self tRelayout]; -} - -- (void)tShow -{ - [self->w cascadeTopLeftFromPoint:NSMakePoint(20, 20)]; - [self->w makeKeyAndOrderFront:self]; - [[self->w contentView] tIsAmbiguous:0]; -} - -- (void)tRelayout -{ - NSView *contentView; - tAutoLayoutParams p; - NSDictionary *views; - NSString *margin; - NSMutableString *constraint; - NSArray *constraints; - - if (self->c == nil) - return; - - contentView = [self->w contentView]; - [contentView removeConstraints:[contentView constraints]]; - - [self->c tFillAutoLayout:&p]; - - views = [NSDictionary dictionaryWithObject:p.view forKey:@"view"]; - - margin = @""; - if (self->margined) - margin = @"-"; - - // TODO always append margins even if not attached? - // or if not attached, append ->=0- as well? - constraint = [NSMutableString stringWithString:@"H:"]; - if (p.attachLeft) { - [constraint appendString:@"|"]; - [constraint appendString:margin]; - } - [constraint appendString:@"[view]"]; - if (p.attachRight) { - [constraint appendString:margin]; - [constraint appendString:@"|"]; - } - constraints = [NSLayoutConstraint constraintsWithVisualFormat:constraint options:0 metrics:nil views:views]; - [contentView addConstraints:constraints]; - // TODO do not release constraint; it's autoreleased? - - constraint = [NSMutableString stringWithString:@"V:"]; - if (p.attachTop) { - [constraint appendString:@"|"]; - [constraint appendString:margin]; - } - [constraint appendString:@"[view]"]; - if (p.attachBottom) { - [constraint appendString:margin]; - [constraint appendString:@"|"]; - } - constraints = [NSLayoutConstraint constraintsWithVisualFormat:constraint options:0 metrics:nil views:views]; - [contentView addConstraints:constraints]; - // TODO do not release constraint; it's autoreleased? - - // TODO do not release views; it's autoreleased? - // (for all of these, look up whether the constructor autoreleases) -} - -@end