2015-07-31 22:25:59 -05:00
|
|
|
// 31 july 2015
|
|
|
|
#import "osxaltest.h"
|
|
|
|
|
2015-08-01 13:22:45 -05:00
|
|
|
@implementation tBox {
|
2015-07-31 22:25:59 -05:00
|
|
|
NSMutableArray *children;
|
2015-08-01 21:38:01 -05:00
|
|
|
NSMutableArray *stretchy;
|
2015-07-31 22:25:59 -05:00
|
|
|
NSView *sv;
|
2015-08-01 01:16:35 -05:00
|
|
|
BOOL vertical;
|
2015-08-01 20:41:36 -05:00
|
|
|
id<tControl> parent;
|
2015-07-31 22:25:59 -05:00
|
|
|
}
|
|
|
|
|
2015-08-01 13:22:45 -05:00
|
|
|
- (id)tInitVertical:(BOOL)vert
|
2015-07-31 22:25:59 -05:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self) {
|
|
|
|
self->children = [NSMutableArray new];
|
2015-08-01 21:38:01 -05:00
|
|
|
self->stretchy = [NSMutableArray new];
|
2015-07-31 22:25:59 -05:00
|
|
|
self->sv = nil;
|
2015-08-01 01:16:35 -05:00
|
|
|
self->vertical = vert;
|
2015-08-01 20:41:36 -05:00
|
|
|
self->parent = nil;
|
2015-07-31 22:25:59 -05:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-08-01 13:22:45 -05:00
|
|
|
- (void)tAddControl:(id<tControl>)c stretchy:(BOOL)s
|
2015-07-31 22:25:59 -05:00
|
|
|
{
|
2015-08-01 14:08:33 -05:00
|
|
|
if (self->sv != nil)
|
2015-08-02 17:16:44 -05:00
|
|
|
[c tSetParent:self addToView:self->sv relayout:NO];
|
2015-08-01 14:08:33 -05:00
|
|
|
[self->children addObject:c];
|
2015-08-01 21:38:01 -05:00
|
|
|
[self->stretchy addObject:[NSNumber numberWithBool:s]];
|
2015-08-01 14:08:33 -05:00
|
|
|
// TODO mark as needing relayout
|
2015-08-01 21:13:41 -05:00
|
|
|
[self tRelayout];
|
2015-07-31 22:25:59 -05:00
|
|
|
}
|
|
|
|
|
2015-08-02 17:16:44 -05:00
|
|
|
- (void)tSetParent:(id<tControl>)p addToView:(NSView *)v relayout:(BOOL)relayout
|
2015-07-31 22:25:59 -05:00
|
|
|
{
|
2015-08-01 20:41:36 -05:00
|
|
|
self->parent = p;
|
2015-07-31 22:25:59 -05:00
|
|
|
self->sv = v;
|
2015-08-01 01:16:35 -05:00
|
|
|
[self->children enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
2015-08-01 14:08:33 -05:00
|
|
|
id<tControl> c;
|
2015-08-01 01:16:35 -05:00
|
|
|
|
2015-08-01 14:08:33 -05:00
|
|
|
c = (id<tControl>) obj;
|
2015-08-02 17:16:44 -05:00
|
|
|
[c tSetParent:self addToView:self->sv relayout:NO];
|
2015-08-01 01:16:35 -05:00
|
|
|
}];
|
2015-08-02 17:16:44 -05:00
|
|
|
if (relayout)
|
|
|
|
[self tRelayout];
|
2015-07-31 22:25:59 -05:00
|
|
|
}
|
|
|
|
|
2015-08-02 15:55:21 -05:00
|
|
|
// TODO MASSIVE CLEANUP and comments everywhere too
|
2015-08-02 10:25:39 -05:00
|
|
|
- (void)tFillAutoLayout:(tAutoLayoutParams *)p
|
2015-08-01 01:16:35 -05:00
|
|
|
{
|
2015-08-02 21:29:35 -05:00
|
|
|
NSMutableDictionary *views;
|
|
|
|
__block uintmax_t n;
|
2015-08-02 10:25:39 -05:00
|
|
|
tAutoLayoutParams pp;
|
2015-08-02 21:29:35 -05:00
|
|
|
__block BOOL anyStretchy;
|
|
|
|
NSMutableString *constraint;
|
2015-08-01 01:16:35 -05:00
|
|
|
|
2015-08-02 21:29:35 -05:00
|
|
|
views = [NSMutableDictionary new];
|
|
|
|
n = 0;
|
|
|
|
anyStretchy = NO;
|
|
|
|
[self->children enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
|
|
|
id<tControl> c;
|
2015-08-02 11:52:24 -05:00
|
|
|
NSNumber *isStretchy;
|
2015-08-01 01:16:35 -05:00
|
|
|
|
2015-08-02 21:29:35 -05:00
|
|
|
c = (id<tControl>) obj;
|
|
|
|
isStretchy = (NSNumber *) [self->stretchy objectAtIndex:index];
|
|
|
|
if ([isStretchy boolValue])
|
|
|
|
anyStretchy = YES;
|
|
|
|
[c tFillAutoLayout:&pp];
|
|
|
|
[views setObjject:pp.view forKey:tAutoLayoutKey(n)];
|
|
|
|
n++;
|
|
|
|
}];
|
2015-08-02 10:25:39 -05:00
|
|
|
|
2015-08-02 21:29:35 -05:00
|
|
|
// first string the views together
|
|
|
|
constraint = [NSMutableString stringWithString:@"|"];
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
[constraint appendString:@"["];
|
|
|
|
[constraint appendString:tAutoLayoutKey(n)];
|
|
|
|
[constraint appendString:@"]"];
|
|
|
|
}
|
|
|
|
[constraint appendString:@"|"];
|
|
|
|
// TODO apply constraint
|
|
|
|
[constraint release];
|
|
|
|
|
|
|
|
// next make the views span the full other dimension
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (self->vertical)
|
|
|
|
constraint = [NSMutableString stringWithString:@"H:|"];
|
|
|
|
else
|
|
|
|
constraint = [NSMutableString stringWithString:@"V:|"];
|
|
|
|
[constraint appendString:tAutoLayoutKey(n)];
|
|
|
|
[constraint appendString:@"]|"];
|
|
|
|
// TODO apply constraint
|
|
|
|
[constraint release];
|
|
|
|
}
|
2015-08-02 17:16:44 -05:00
|
|
|
|
2015-08-02 21:29:35 -05:00
|
|
|
[views release];
|
2015-08-02 17:16:44 -05:00
|
|
|
|
2015-08-02 21:29:35 -05:00
|
|
|
// and now populate for self
|
|
|
|
p->view = TODO;
|
|
|
|
p->attachLeft = YES;
|
|
|
|
p->attachTop = YES;
|
|
|
|
// don't attach to the end if there weren't any stretchy controls
|
2015-08-02 11:22:24 -05:00
|
|
|
if (self->vertical) {
|
2015-08-02 21:29:35 -05:00
|
|
|
p->attachRight = YES;
|
|
|
|
p->attachBottom = anyStretchy;
|
2015-08-02 17:16:44 -05:00
|
|
|
} else {
|
2015-08-02 21:29:35 -05:00
|
|
|
p->attachRight = anyStretchy;
|
|
|
|
p->attachBottom = YES;
|
2015-08-02 11:22:24 -05:00
|
|
|
}
|
2015-08-01 01:16:35 -05:00
|
|
|
}
|
2015-07-31 22:25:59 -05:00
|
|
|
|
2015-08-01 21:13:41 -05:00
|
|
|
- (void)tRelayout
|
|
|
|
{
|
|
|
|
if (self->parent != nil)
|
|
|
|
[self->parent tRelayout];
|
|
|
|
}
|
|
|
|
|
2015-07-31 22:25:59 -05:00
|
|
|
@end
|