2015-08-01 16:19:45 -05:00
|
|
|
// 31 july 2015
|
|
|
|
#import "osxaltest.h"
|
|
|
|
|
2015-08-01 23:10:30 -05:00
|
|
|
// leave a whole lot of space around the alignment rect, just to be safe
|
|
|
|
@interface tSpinboxContainer : NSView
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation tSpinboxContainer
|
|
|
|
|
|
|
|
- (NSEdgeInsets)alignmentRectInsets
|
|
|
|
{
|
|
|
|
return NSEdgeInsetsMake(50, 50, 50, 50);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-08-01 16:19:45 -05:00
|
|
|
@implementation tSpinbox {
|
2015-08-02 08:10:17 -05:00
|
|
|
tSpinboxContainer *c;
|
2015-08-01 16:19:45 -05:00
|
|
|
NSTextField *t;
|
|
|
|
NSStepper *s;
|
2015-08-01 20:41:36 -05:00
|
|
|
id<tControl> parent;
|
2015-08-01 16:19:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self) {
|
2015-08-02 08:31:49 -05:00
|
|
|
NSMutableDictionary *views;
|
|
|
|
NSArray *constraints;
|
|
|
|
|
2015-08-02 08:10:17 -05:00
|
|
|
self->c = [[tSpinboxContainer alloc] initWithFrame:NSZeroRect];
|
2015-08-02 08:31:49 -05:00
|
|
|
[self->c setTranslatesAutoresizingMaskIntoConstraints:NO];
|
2015-08-02 08:10:17 -05:00
|
|
|
|
2015-08-01 16:19:45 -05:00
|
|
|
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];
|
2015-08-02 08:10:17 -05:00
|
|
|
[self->c addSubview:self->t];
|
2015-08-01 16:19:45 -05:00
|
|
|
|
|
|
|
self->s = [[NSStepper alloc] initWithFrame:NSZeroRect];
|
|
|
|
[self->s setIncrement:1];
|
|
|
|
[self->s setValueWraps:NO];
|
|
|
|
[self->s setAutorepeat:YES];
|
|
|
|
[self->s setTranslatesAutoresizingMaskIntoConstraints:NO];
|
2015-08-02 08:10:17 -05:00
|
|
|
[self->c addSubview:self->s];
|
2015-08-01 20:41:36 -05:00
|
|
|
|
2015-08-02 08:31:49 -05:00
|
|
|
views = [NSMutableDictionary new];
|
|
|
|
[views setObject:self->t forKey:@"t"];
|
|
|
|
[views setObject:self->s forKey:@"s"];
|
|
|
|
|
|
|
|
constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[t]-[s]|" options:0 metrics:nil views:views];
|
|
|
|
[self->c addConstraints:constraints];
|
|
|
|
constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[t]|" options:0 metrics:nil views:views];
|
|
|
|
[self->c addConstraints:constraints];
|
|
|
|
constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[s]|" options:0 metrics:nil views:views];
|
|
|
|
[self->c addConstraints:constraints];
|
|
|
|
|
|
|
|
[views release];
|
|
|
|
|
2015-08-01 20:41:36 -05:00
|
|
|
self->parent = nil;
|
2015-08-01 16:19:45 -05:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-08-01 20:41:36 -05:00
|
|
|
- (void)tSetParent:(id<tControl>)p addToView:(NSView *)v
|
2015-08-01 16:19:45 -05:00
|
|
|
{
|
2015-08-01 20:41:36 -05:00
|
|
|
self->parent = p;
|
2015-08-02 08:10:17 -05:00
|
|
|
[v addSubview:self->c];
|
2015-08-01 16:19:45 -05:00
|
|
|
}
|
|
|
|
|
2015-08-02 10:25:39 -05:00
|
|
|
- (void)tFillAutoLayout:(tAutoLayoutParams *)p
|
2015-08-01 16:19:45 -05:00
|
|
|
{
|
2015-08-02 08:10:17 -05:00
|
|
|
NSString *key;
|
2015-08-02 11:52:24 -05:00
|
|
|
NSString *horzpred, *vertpred;
|
2015-08-01 17:05:50 -05:00
|
|
|
|
2015-08-02 10:25:39 -05:00
|
|
|
key = tAutoLayoutKey(p->n);
|
|
|
|
p->n++;
|
2015-08-02 11:52:24 -05:00
|
|
|
horzpred = @"(==96)"; // TODO only the entry
|
|
|
|
vertpred = @"";
|
|
|
|
if (p->stretchy) {
|
|
|
|
NSString *predicate;
|
|
|
|
|
|
|
|
if (p->firstStretchy)
|
|
|
|
predicate = @"(>=0)";
|
|
|
|
else
|
|
|
|
predicate = [NSString stringWithFormat:@"(==%@)", tAutoLayoutKey(p->stretchyTo)];
|
|
|
|
if (p->stretchyVert)
|
|
|
|
vertpred = predicate;
|
|
|
|
else
|
|
|
|
horzpred = predicate;
|
|
|
|
}
|
|
|
|
[p->horz addObject:[NSString stringWithFormat:@"[%@%@]", key, horzpred]];
|
2015-08-02 14:03:30 -05:00
|
|
|
[p->horzAttachLeft addObject:[NSNumtber numberWithBool:p->horzFirst]];
|
|
|
|
[p->horzAttachRight addObject:[NSNumber numberWithBool:p->horzLast]];
|
2015-08-02 11:52:24 -05:00
|
|
|
[p->vert addObject:[NSString stringWithFormat:@"[%@%@]", key, vertpred]];
|
2015-08-02 14:03:30 -05:00
|
|
|
[p->vertAttachTop addObject:[NSNumber numberWithBool:p->vertFirst]];
|
|
|
|
[p->vertAttachBottom addObject:[NSNumber numberWithBool:p->vertLast]];
|
2015-08-02 10:25:39 -05:00
|
|
|
[p->views setObject:self->c forKey:key];
|
2015-08-01 16:19:45 -05:00
|
|
|
}
|
|
|
|
|
2015-08-01 21:13:41 -05:00
|
|
|
- (void)tRelayout
|
|
|
|
{
|
|
|
|
if (self->parent != nil)
|
|
|
|
[self->parent tRelayout];
|
|
|
|
}
|
|
|
|
|
2015-08-01 16:19:45 -05:00
|
|
|
@end
|