2015-07-31 22:25:59 -05:00
|
|
|
// 31 july 2015
|
|
|
|
#import "osxaltest.h"
|
|
|
|
|
|
|
|
@interface tBox : NSObject<tControl> {
|
|
|
|
NSMutableArray *children;
|
|
|
|
NSView *sv;
|
2015-08-01 01:16:35 -05:00
|
|
|
BOOL vertical;
|
2015-07-31 22:25:59 -05:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation tBox
|
|
|
|
|
2015-08-01 01:16:35 -05:00
|
|
|
- (id)initVertical:(BOOL)vert
|
2015-07-31 22:25:59 -05:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self) {
|
|
|
|
self->children = [NSMutableArray new];
|
|
|
|
self->sv = nil;
|
2015-08-01 01:16:35 -05:00
|
|
|
self->vertical = vert;
|
2015-07-31 22:25:59 -05:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)addControl:(NSObject<tControl> *)c stretchy:(BOOL)s
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tAddToView:(NSView *)v
|
|
|
|
{
|
|
|
|
self->sv = v;
|
2015-08-01 01:16:35 -05:00
|
|
|
[self->children enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
|
|
|
NSView *vv;
|
|
|
|
|
|
|
|
vv = (NSView *) obj;
|
|
|
|
[v addSubview:vv];
|
|
|
|
}];
|
2015-07-31 22:25:59 -05:00
|
|
|
}
|
|
|
|
|
2015-08-01 11:43:54 -05:00
|
|
|
- (uintmax_t)tAddToAutoLayoutDictionary:(NSMutableDictionary *)views keyNumber:(uintmax_t)nn
|
2015-07-31 22:25:59 -05:00
|
|
|
{
|
2015-08-01 11:43:54 -05:00
|
|
|
__block uintmax_t n = nn;
|
|
|
|
|
2015-08-01 01:16:35 -05:00
|
|
|
[self->children enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
2015-08-01 11:43:54 -05:00
|
|
|
id<tControl> c;
|
2015-08-01 01:16:35 -05:00
|
|
|
|
2015-08-01 11:43:54 -05:00
|
|
|
c = (id<tControl>) obj;
|
2015-08-01 01:16:35 -05:00
|
|
|
n = [c tAddToAutoLayoutDictionary:views keyNumber:n];
|
|
|
|
}];
|
|
|
|
return n;
|
2015-07-31 22:25:59 -05:00
|
|
|
}
|
|
|
|
|
2015-08-01 11:43:54 -05:00
|
|
|
- (NSString *)tBuildAutoLayoutConstraintsKeyNumber:(uintmax_t)nn
|
2015-08-01 01:16:35 -05:00
|
|
|
{
|
|
|
|
NSMutableString *constraints;
|
2015-08-01 11:43:54 -05:00
|
|
|
__block uintmax_t n = nn;
|
2015-08-01 01:16:35 -05:00
|
|
|
|
|
|
|
if (self->vertical)
|
|
|
|
constraints = [NSMutableString stringWithString:@"V:"];
|
|
|
|
else
|
|
|
|
constraints = [NSMutableString stringWithString:@"H:"];
|
|
|
|
[constraints appendString:@"|"];
|
|
|
|
[self->children enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
|
|
|
NSString *thisView;
|
|
|
|
|
|
|
|
// TODO have every control do this
|
|
|
|
[constraints appendString:tAutoLayoutKey(n)];
|
|
|
|
n++;
|
|
|
|
}];
|
|
|
|
[constraints appendString:@"|"];
|
|
|
|
return constraints;
|
2015-08-01 01:28:10 -05:00
|
|
|
// TODOs:
|
|
|
|
// - lateral dimension: for each view of n+1, make other dimension next to first n
|
|
|
|
// this way, subelement views get positioned right
|
2015-08-01 01:16:35 -05:00
|
|
|
}
|
2015-07-31 22:25:59 -05:00
|
|
|
|
|
|
|
@end
|