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;
|
|
|
|
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];
|
|
|
|
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-01 20:41:36 -05:00
|
|
|
[c tSetParent:self->parent addToView:self->sv];
|
2015-08-01 14:08:33 -05:00
|
|
|
[self->children addObject:c];
|
|
|
|
// TODO mark as needing relayout
|
2015-07-31 22:25:59 -05:00
|
|
|
}
|
|
|
|
|
2015-08-01 20:41:36 -05:00
|
|
|
- (void)tSetParent:(id<tControl>)p addToView:(NSView *)v
|
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-01 20:41:36 -05:00
|
|
|
[c tSetParent:self->parent addToView:self->sv];
|
2015-08-01 01:16:35 -05:00
|
|
|
}];
|
2015-07-31 22:25:59 -05:00
|
|
|
}
|
|
|
|
|
2015-08-01 17:05:50 -05:00
|
|
|
- (void)tFillAutoLayoutHorz:(NSMutableArray *)horz
|
|
|
|
vert:(NSMutableArray *)vert
|
|
|
|
extra:(NSMutableArray *)extra
|
|
|
|
extraVert:(NSMutableArray *)extraVert
|
|
|
|
views:(NSMutableDictionary *)views
|
|
|
|
first:(uintmax_t *)n
|
2015-08-01 01:16:35 -05:00
|
|
|
{
|
2015-08-01 17:05:50 -05:00
|
|
|
NSMutableArray *subhorz, *subvert;
|
|
|
|
uintmax_t *first;
|
|
|
|
NSUInteger i;
|
2015-08-01 17:33:17 -05:00
|
|
|
NSMutableString *out;
|
2015-08-01 01:16:35 -05:00
|
|
|
|
2015-08-01 17:05:50 -05:00
|
|
|
first = (uintmax_t *) malloc([self->children count] * sizeof (uintmax_t));
|
|
|
|
if (first == NULL)
|
|
|
|
abort();
|
|
|
|
subhorz = [NSMutableArray new];
|
|
|
|
subvert = [NSMutableArray new];
|
|
|
|
for (i = 0; i < [self->children count]; i++) {
|
|
|
|
id<tControl> cur;
|
2015-08-01 01:16:35 -05:00
|
|
|
|
2015-08-01 17:05:50 -05:00
|
|
|
first[i] = *n;
|
|
|
|
cur = (id<tControl>) [self->children objectAtIndex:i];
|
|
|
|
[cur tFillAutoLayoutHorz:subhorz vert:subvert
|
|
|
|
extra:extra extraVert:extraVert
|
|
|
|
views:views first:n];
|
|
|
|
}
|
2015-08-01 17:33:17 -05:00
|
|
|
// TODO vertical
|
|
|
|
out = [NSMutableString new];
|
|
|
|
[subhorz enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
|
|
|
//TODO if (index != 0)
|
|
|
|
//TODO [out appendString:@"-"];
|
|
|
|
[out appendString:((NSString *) obj)];
|
|
|
|
}];
|
|
|
|
[horz addObject:out];
|
|
|
|
[vert addObjectsFromArray:subvert];
|
2015-08-01 17:05:50 -05:00
|
|
|
[subhorz release];
|
|
|
|
[subvert release];
|
|
|
|
free(first);
|
2015-08-01 01:16:35 -05:00
|
|
|
}
|
2015-07-31 22:25:59 -05:00
|
|
|
|
2015-08-01 17:05:50 -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-07-31 22:25:59 -05:00
|
|
|
@end
|