libui/redo/osxaltest/button.m

71 lines
1.8 KiB
Mathematica
Raw Normal View History

2015-07-31 22:06:29 -05:00
// 31 july 2015
#import "osxaltest.h"
2015-08-01 13:22:45 -05:00
@implementation tButton {
2015-07-31 22:06:29 -05:00
NSButton *b;
id<tControl> parent;
2015-07-31 22:06:29 -05:00
}
2015-08-01 13:22:45 -05:00
- (id)tInitWithText:(NSString *)text
2015-07-31 22:06:29 -05:00
{
self = [super init];
if (self) {
self->b = [[NSButton alloc] initWithFrame:NSZeroRect];
[self->b setTitle:text];
[self->b setButtonType:NSMomentaryPushInButton];
[self->b setBordered:YES];
[self->b setBezelStyle:NSRoundedBezelStyle];
[self->b setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]];
[self->b setTranslatesAutoresizingMaskIntoConstraints:NO];
self->parent = nil;
2015-07-31 22:06:29 -05:00
}
return self;
}
- (void)tSetParent:(id<tControl>)p addToView:(NSView *)v
2015-07-31 22:06:29 -05:00
{
self->parent = p;
2015-07-31 22:06:29 -05:00
[v addSubview:self->b];
[self tRelayout];
2015-07-31 22:06:29 -05:00
}
- (void)tFillAutoLayout:(tAutoLayoutParams *)p
{
NSString *key;
2015-08-02 11:52:24 -05:00
NSString *horzpred, *vertpred;
key = tAutoLayoutKey(p->n);
p->n++;
2015-08-02 11:52:24 -05:00
horzpred = @"";
vertpred = @"";
if (p->stretchy) {
NSString *predicate;
if (p->firstStretchy)
// TODO is this unnecessary? it seems like I need to do other things instead of this to ensure stretchiness...
predicate = @"(>=0)";
else
predicate = [NSString stringWithFormat:@"(==%@)", tAutoLayoutKey(p->stretchyTo)];
if (p->stretchyVert)
vertpred = predicate;
else
horzpred = predicate;
}
[p->horz addObject:[NSString stringWithFormat:@"[%@%@]", key, horzpred]];
[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]];
[p->vertAttachTop addObject:[NSNumber numberWithBool:p->vertFirst]];
[p->vertAttachBottom addObject:[NSNumber numberWithBool:p->vertLast]];
[p->views setObject:self->b forKey:key];
}
- (void)tRelayout
{
if (self->parent != nil)
[self->parent tRelayout];
}
2015-07-31 22:06:29 -05:00
@end