From 4dc63828e4ed8bac1ae22ea1505ae9b387fc18ec Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 1 Aug 2015 17:19:45 -0400 Subject: [PATCH] Added spinboxes to the test. We're going to need multiple horizontals and verticals. --- redo/osxaltest/main.m | 8 ++++-- redo/osxaltest/osxaltest.h | 3 ++ redo/osxaltest/spinbox.m | 58 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 redo/osxaltest/spinbox.m diff --git a/redo/osxaltest/main.m b/redo/osxaltest/main.m index d1bff409..e6df285d 100644 --- a/redo/osxaltest/main.m +++ b/redo/osxaltest/main.m @@ -14,12 +14,16 @@ BOOL margined = NO; { tWindow *mainwin; tButton *button; + tSpinbox *spinbox; mainwin = [[tWindow alloc] init]; [mainwin tSetMargined:margined]; - button = [[tButton alloc] tInitWithText:@"Button"]; - [mainwin tSetControl:button]; +// button = [[tButton alloc] tInitWithText:@"Button"]; +// [mainwin tSetControl:button]; + + spinbox = [[tSpinbox alloc] init]; + [mainwin tSetControl:spinbox]; [mainwin tShow]; } diff --git a/redo/osxaltest/osxaltest.h b/redo/osxaltest/osxaltest.h index b75b556d..a0e7d93c 100644 --- a/redo/osxaltest/osxaltest.h +++ b/redo/osxaltest/osxaltest.h @@ -32,4 +32,7 @@ - (id)tInitWithText:(NSString *)text; @end +@interface tSpinbox : NSObject +@end + extern NSString *tAutoLayoutKey(uintmax_t); diff --git a/redo/osxaltest/spinbox.m b/redo/osxaltest/spinbox.m new file mode 100644 index 00000000..da6d8570 --- /dev/null +++ b/redo/osxaltest/spinbox.m @@ -0,0 +1,58 @@ +// 31 july 2015 +#import "osxaltest.h" + +@implementation tSpinbox { + NSTextField *t; + NSStepper *s; +} + +- (id)init +{ + self = [super init]; + if (self) { + self->t = [[NSTextField alloc] initWithFrame:NSZeroRect]; + [self->t setSelectable:YES]; + [self->t setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]]; + [self->t setBordered:NO]; + [self->t setBezelStyle:NSTextFieldSquareBezel]; + [self->t setBezeled:YES]; + [[self->t cell] setLineBreakMode:NSLineBreakByClipping]; + [[self->t cell] setScrollable:YES]; + [self->t setTranslatesAutoresizingMaskIntoConstraints:NO]; + + self->s = [[NSStepper alloc] initWithFrame:NSZeroRect]; + [self->s setIncrement:1]; + [self->s setValueWraps:NO]; + [self->s setAutorepeat:YES]; + [self->s setTranslatesAutoresizingMaskIntoConstraints:NO]; + } + return self; +} + +- (void)tAddToView:(NSView *)v +{ + [v addSubview:self->t]; + [v addSubview:self->s]; +} + +- (uintmax_t)tAddToAutoLayoutDictionary:(NSMutableDictionary *)views keyNumber:(uintmax_t)n +{ + [views setObject:self->t forKey:tAutoLayoutKey(n)]; + [views setObject:self->s forKey:tAutoLayoutKey(n + 1)]; + n += 2; + return n; +} + +- (void)tFillAutoLayoutHorz:(NSMutableString *)horz + vert:(NSMutableString *)vert + extra:(NSMutableArray *)extra + extraVert:(NSMutableArray *)extraVert + views:(NSMutableDictionary *)views +{ + [horz setString:@"[view0]-[view1]"]; + [vert setString:@"[view0]"]; + [views setObject:self->t forKey:@"view0"]; + [views setObject:self->s forKey:@"view1"]; +} + +@end