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-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];
|
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-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-08-01 21:13:41 -05:00
|
|
|
[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-01 17:05:50 -05:00
|
|
|
NSMutableArray *subhorz, *subvert;
|
2015-08-02 13:49:10 -05:00
|
|
|
NSMutableArray *subhorzleft, *subhorzright;
|
|
|
|
NSMutableArray *subverttop, *subvertbottom;
|
2015-08-01 17:05:50 -05:00
|
|
|
uintmax_t *first;
|
|
|
|
NSUInteger i;
|
2015-08-01 17:33:17 -05:00
|
|
|
NSMutableString *out;
|
2015-08-02 10:25:39 -05:00
|
|
|
tAutoLayoutParams pp;
|
2015-08-02 11:22:24 -05:00
|
|
|
NSMutableArray *primaryin, *primaryout;
|
2015-08-02 15:55:21 -05:00
|
|
|
BOOL primaryinstart, primaryinend;
|
|
|
|
NSMutableArray *primaryoutstart, *primaryoutend;
|
2015-08-02 11:22:24 -05:00
|
|
|
NSMutableArray *secondaryin, *secondaryout;
|
2015-08-02 15:55:21 -05:00
|
|
|
NSMutableArray *secondaryinstart, *secondaryinend;
|
|
|
|
NSMutableArray *secondaryoutstart, *secondaryoutend;
|
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];
|
2015-08-02 13:49:10 -05:00
|
|
|
subhorzleft = [NSMutableArray new];
|
|
|
|
subhorzright = [NSMutableArray new];
|
2015-08-01 17:05:50 -05:00
|
|
|
subvert = [NSMutableArray new];
|
2015-08-02 13:49:10 -05:00
|
|
|
subverttop = [NSMutableArray new];
|
|
|
|
subvertbottom = [NSMutableArray new];
|
2015-08-02 10:25:39 -05:00
|
|
|
|
|
|
|
pp.horz = subhorz;
|
2015-08-02 13:49:10 -05:00
|
|
|
pp.horzAttachLeft = subhorzleft;
|
|
|
|
pp.horzAttachRight = subhorzright;
|
2015-08-02 10:25:39 -05:00
|
|
|
pp.vert = subvert;
|
2015-08-02 13:49:10 -05:00
|
|
|
pp.vertAttachTop = subverttop;
|
|
|
|
pp.vertAttachBottom = subvertbottom;
|
2015-08-02 10:25:39 -05:00
|
|
|
pp.views = p->views;
|
|
|
|
pp.n = p->n;
|
2015-08-02 11:35:48 -05:00
|
|
|
pp.stretchyVert = self->vertical;
|
|
|
|
pp.firstStretchy = TRUE;
|
2015-08-01 17:05:50 -05:00
|
|
|
for (i = 0; i < [self->children count]; i++) {
|
|
|
|
id<tControl> cur;
|
2015-08-02 11:52:24 -05:00
|
|
|
NSNumber *isStretchy;
|
2015-08-01 01:16:35 -05:00
|
|
|
|
2015-08-02 10:25:39 -05:00
|
|
|
first[i] = pp.n;
|
2015-08-01 17:05:50 -05:00
|
|
|
cur = (id<tControl>) [self->children objectAtIndex:i];
|
2015-08-02 11:52:24 -05:00
|
|
|
isStretchy = (NSNumber *) [self->stretchy objectAtIndex:i];
|
|
|
|
pp.stretchy = [isStretchy boolValue];
|
2015-08-02 15:55:21 -05:00
|
|
|
if (self->vertical) {
|
|
|
|
pp.vertFirst = p->vertFirst && i == 0;
|
|
|
|
pp.vertLast = p->vertLast && i == ([self->children count] - 1);
|
|
|
|
pp.horzFirst = p->horzFirst;
|
|
|
|
pp.horzLast = p->horzLast;
|
|
|
|
} else {
|
|
|
|
pp.horzFirst = p->horzFirst && i == 0;
|
|
|
|
pp.horzLast = p->horzLast && i == ([self->children count] - 1);
|
|
|
|
pp.vertFirst = p->vertFirst;
|
|
|
|
pp.vertLast = p->vertLast;
|
|
|
|
}
|
2015-08-02 10:25:39 -05:00
|
|
|
[cur tFillAutoLayout:&pp];
|
2015-08-02 11:35:48 -05:00
|
|
|
if (pp.stretchy && pp.firstStretchy) {
|
|
|
|
pp.firstStretchy = FALSE;
|
|
|
|
pp.stretchyTo = first[i];
|
|
|
|
}
|
2015-08-01 17:05:50 -05:00
|
|
|
}
|
2015-08-02 10:25:39 -05:00
|
|
|
p->n = pp.n;
|
|
|
|
|
2015-08-01 17:33:17 -05:00
|
|
|
out = [NSMutableString new];
|
2015-08-02 11:22:24 -05:00
|
|
|
primaryin = subhorz;
|
2015-08-02 15:55:21 -05:00
|
|
|
primaryinstart = p->horzFirst;
|
|
|
|
primaryinend = p->horzLast;
|
2015-08-02 11:22:24 -05:00
|
|
|
primaryout = p->horz;
|
2015-08-02 15:55:21 -05:00
|
|
|
primaryoutstart = p->horzAttachLeft;
|
|
|
|
primaryoutend = p->horzAttachRight;
|
2015-08-02 11:22:24 -05:00
|
|
|
secondaryin = subvert;
|
2015-08-02 15:55:21 -05:00
|
|
|
secondaryinstart = subverttop;
|
|
|
|
secondaryinend = subvertbottom;
|
2015-08-02 11:22:24 -05:00
|
|
|
secondaryout = p->vert;
|
2015-08-02 15:55:21 -05:00
|
|
|
secondaryoutstart = p->vertAttachTop;
|
|
|
|
secondaryoutend = p->vertAttachBottom;
|
2015-08-02 11:22:24 -05:00
|
|
|
if (self->vertical) {
|
|
|
|
primaryin = subvert;
|
2015-08-02 15:55:21 -05:00
|
|
|
primaryinstart = p->vertFirst;
|
|
|
|
primaryinend = p->vertLast;
|
2015-08-02 11:22:24 -05:00
|
|
|
primaryout = p->vert;
|
2015-08-02 15:55:21 -05:00
|
|
|
primaryoutstart = p->vertAttachTop;
|
|
|
|
primaryoutend = p->vertAttachBottom;
|
2015-08-02 11:22:24 -05:00
|
|
|
secondaryin = subhorz;
|
2015-08-02 15:55:21 -05:00
|
|
|
secondaryinstart = subhorzleft;
|
|
|
|
secondaryinend = subhorzright;
|
2015-08-02 11:22:24 -05:00
|
|
|
secondaryout = p->horz;
|
2015-08-02 15:55:21 -05:00
|
|
|
secondaryoutstart = p->horzAttachLeft;
|
|
|
|
secondaryoutend = p->horzAttachRight;
|
2015-08-02 11:22:24 -05:00
|
|
|
}
|
|
|
|
[primaryin enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
2015-08-01 17:33:17 -05:00
|
|
|
//TODO if (index != 0)
|
|
|
|
//TODO [out appendString:@"-"];
|
|
|
|
[out appendString:((NSString *) obj)];
|
|
|
|
}];
|
2015-08-02 11:22:24 -05:00
|
|
|
[primaryout addObject:out];
|
2015-08-02 15:55:21 -05:00
|
|
|
[primaryoutstart addObject:[NSNumber numberWithBool:primaryinstart]];
|
|
|
|
[primaryoutend addObject:[NSNumber numberWithBool:primaryinend]];
|
2015-08-02 11:22:24 -05:00
|
|
|
[secondaryout addObjectsFromArray:secondaryin];
|
2015-08-02 15:55:21 -05:00
|
|
|
[secondaryoutstart addObjectsFromArray:secondaryinstart];
|
|
|
|
[secondaryoutend addObjectsFromArray:secondaryinend];
|
2015-08-02 10:25:39 -05:00
|
|
|
|
2015-08-01 17:05:50 -05:00
|
|
|
[subhorz release];
|
2015-08-02 13:49:10 -05:00
|
|
|
[subhorzleft release];
|
|
|
|
[subhorzright release];
|
2015-08-01 17:05:50 -05:00
|
|
|
[subvert release];
|
2015-08-02 13:49:10 -05:00
|
|
|
[subverttop release];
|
|
|
|
[subvertbottom release];
|
2015-08-01 17:05:50 -05:00
|
|
|
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-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
|