Changed the Auto Layout generation function to use a structure of parameters. This will make adding parameters easier.
This commit is contained in:
parent
96dfd95fd3
commit
64ed23e933
|
@ -45,32 +45,35 @@
|
|||
[self tRelayout];
|
||||
}
|
||||
|
||||
- (void)tFillAutoLayoutHorz:(NSMutableArray *)horz
|
||||
vert:(NSMutableArray *)vert
|
||||
extra:(NSMutableArray *)extra
|
||||
extraVert:(NSMutableArray *)extraVert
|
||||
views:(NSMutableDictionary *)views
|
||||
first:(uintmax_t *)n
|
||||
- (void)tFillAutoLayout:(tAutoLayoutParams *)p
|
||||
{
|
||||
NSMutableArray *subhorz, *subvert;
|
||||
uintmax_t *first;
|
||||
NSUInteger i;
|
||||
NSMutableString *out;
|
||||
tAutoLayoutParams pp;
|
||||
|
||||
first = (uintmax_t *) malloc([self->children count] * sizeof (uintmax_t));
|
||||
if (first == NULL)
|
||||
abort();
|
||||
subhorz = [NSMutableArray new];
|
||||
subvert = [NSMutableArray new];
|
||||
|
||||
pp.horz = subhorz;
|
||||
pp.vert = subvert;
|
||||
pp.extra = p->extra;
|
||||
pp.extraVert = p->extraVert;
|
||||
pp.views = p->views;
|
||||
pp.n = p->n;
|
||||
for (i = 0; i < [self->children count]; i++) {
|
||||
id<tControl> cur;
|
||||
|
||||
first[i] = *n;
|
||||
first[i] = pp.n;
|
||||
cur = (id<tControl>) [self->children objectAtIndex:i];
|
||||
[cur tFillAutoLayoutHorz:subhorz vert:subvert
|
||||
extra:extra extraVert:extraVert
|
||||
views:views first:n];
|
||||
[cur tFillAutoLayout:&pp];
|
||||
}
|
||||
p->n = pp.n;
|
||||
|
||||
// TODO vertical
|
||||
out = [NSMutableString new];
|
||||
[subhorz enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
||||
|
@ -78,8 +81,9 @@
|
|||
//TODO [out appendString:@"-"];
|
||||
[out appendString:((NSString *) obj)];
|
||||
}];
|
||||
[horz addObject:out];
|
||||
[vert addObjectsFromArray:subvert];
|
||||
[p->horz addObject:out];
|
||||
[p->vert addObjectsFromArray:subvert];
|
||||
|
||||
[subhorz release];
|
||||
[subvert release];
|
||||
free(first);
|
||||
|
|
|
@ -30,20 +30,15 @@
|
|||
[self tRelayout];
|
||||
}
|
||||
|
||||
- (void)tFillAutoLayoutHorz:(NSMutableArray *)horz
|
||||
vert:(NSMutableArray *)vert
|
||||
extra:(NSMutableArray *)extra
|
||||
extraVert:(NSMutableArray *)extraVert
|
||||
views:(NSMutableDictionary *)views
|
||||
first:(uintmax_t *)n
|
||||
- (void)tFillAutoLayout:(tAutoLayoutParams *)p
|
||||
{
|
||||
NSString *key;
|
||||
|
||||
key = tAutoLayoutKey(*n);
|
||||
(*n)++;
|
||||
[horz addObject:[NSString stringWithFormat:@"[%@]", key]];
|
||||
[vert addObject:[NSString stringWithFormat:@"[%@]", key]];
|
||||
[views setObject:self->b forKey:key];
|
||||
key = tAutoLayoutKey(p->n);
|
||||
p->n++;
|
||||
[p->horz addObject:[NSString stringWithFormat:@"[%@]", key]];
|
||||
[p->vert addObject:[NSString stringWithFormat:@"[%@]", key]];
|
||||
[p->views setObject:self->b forKey:key];
|
||||
}
|
||||
|
||||
- (void)tRelayout
|
||||
|
|
|
@ -2,15 +2,21 @@
|
|||
#import <Cocoa/Cocoa.h>
|
||||
#import <stdint.h>
|
||||
|
||||
typedef struct tAutoLayoutParams tAutoLayoutParams;
|
||||
|
||||
struct tAutoLayoutParams {
|
||||
NSMutableArray *horz;
|
||||
NSMutableArray *vert;
|
||||
NSMutableArray *extra; // TODO make extraHorz and return BOOL NSNumber logic
|
||||
NSMutableArray *extraVert;
|
||||
NSMutableDictionary *views;
|
||||
uintmax_t n;
|
||||
};
|
||||
|
||||
@protocol tControl
|
||||
@required
|
||||
- (void)tSetParent:(id<tControl>)p addToView:(NSView *)v;
|
||||
- (void)tFillAutoLayoutHorz:(NSMutableArray *)horz
|
||||
vert:(NSMutableArray *)vert
|
||||
extra:(NSMutableArray *)extra
|
||||
extraVert:(NSMutableArray *)extraVert
|
||||
views:(NSMutableDictionary *)views
|
||||
first:(uintmax_t *)n;
|
||||
- (void)tFillAutoLayout:(tAutoLayoutParams *)p;
|
||||
- (void)tRelayout;
|
||||
@end
|
||||
|
||||
|
|
|
@ -73,20 +73,15 @@
|
|||
[v addSubview:self->c];
|
||||
}
|
||||
|
||||
- (void)tFillAutoLayoutHorz:(NSMutableArray *)horz
|
||||
vert:(NSMutableArray *)vert
|
||||
extra:(NSMutableArray *)extra
|
||||
extraVert:(NSMutableArray *)extraVert
|
||||
views:(NSMutableDictionary *)views
|
||||
first:(uintmax_t *)n
|
||||
- (void)tFillAutoLayout:(tAutoLayoutParams *)p
|
||||
{
|
||||
NSString *key;
|
||||
|
||||
key = tAutoLayoutKey(*n);
|
||||
(*n)++;
|
||||
[horz addObject:[NSString stringWithFormat:@"[%@]", key]];
|
||||
[vert addObject:[NSString stringWithFormat:@"[%@]", key]];
|
||||
[views setObject:self->c forKey:key];
|
||||
key = tAutoLayoutKey(p->n);
|
||||
p->n++;
|
||||
[p->horz addObject:[NSString stringWithFormat:@"[%@]", key]];
|
||||
[p->vert addObject:[NSString stringWithFormat:@"[%@]", key]];
|
||||
[p->views setObject:self->c forKey:key];
|
||||
}
|
||||
|
||||
- (void)tRelayout
|
||||
|
|
|
@ -42,48 +42,49 @@
|
|||
- (void)tRelayout
|
||||
{
|
||||
NSView *contentView;
|
||||
NSMutableArray *horz, *vert;
|
||||
NSMutableArray *extra, *extraVert;
|
||||
NSMutableDictionary *views;
|
||||
tAutoLayoutParams p;
|
||||
NSUInteger i;
|
||||
NSString *margin;
|
||||
uintmax_t n;
|
||||
|
||||
if (self->c == nil)
|
||||
return;
|
||||
|
||||
contentView = [self->w contentView];
|
||||
[contentView removeConstraints:[contentView constraints]];
|
||||
horz = [NSMutableArray new];
|
||||
vert = [NSMutableArray new];
|
||||
extra = [NSMutableArray new];
|
||||
extraVert = [NSMutableArray new];
|
||||
views = [NSMutableDictionary new];
|
||||
n = 0;
|
||||
[self->c tFillAutoLayoutHorz:horz vert:vert extra:extra extraVert:extraVert views:views first:&n];
|
||||
|
||||
p.horz = [NSMutableArray new];
|
||||
p.vert = [NSMutableArray new];
|
||||
p.extra = [NSMutableArray new];
|
||||
p.extraVert = [NSMutableArray new];
|
||||
p.views = [NSMutableDictionary new];
|
||||
p.n = 0;
|
||||
[self->c tFillAutoLayout:&p];
|
||||
|
||||
margin = @"";
|
||||
if (self->margined)
|
||||
margin = @"-";
|
||||
[horz enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
||||
[extra addObject:[NSString stringWithFormat:@"|%@%@%@|", margin, obj, margin]];
|
||||
[extraVert addObject:@NO];
|
||||
[p.horz enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
||||
[p.extra addObject:[NSString stringWithFormat:@"|%@%@%@|", margin, obj, margin]];
|
||||
[p.extraVert addObject:@NO];
|
||||
}];
|
||||
[vert enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
||||
[extra addObject:[NSString stringWithFormat:@"|%@%@%@|", margin, obj, margin]];
|
||||
[extraVert addObject:@YES];
|
||||
[p.vert enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
||||
[p.extra addObject:[NSString stringWithFormat:@"|%@%@%@|", margin, obj, margin]];
|
||||
[p.extraVert addObject:@YES];
|
||||
}];
|
||||
for (i = 0; i < [extra count]; i++) {
|
||||
for (i = 0; i < [p.extra count]; i++) {
|
||||
NSString *constraint;
|
||||
NSNumber *vertical;
|
||||
NSArray *constraints;
|
||||
|
||||
vertical = (NSNumber *) [extraVert objectAtIndex:i];
|
||||
vertical = (NSNumber *) [p.extraVert objectAtIndex:i];
|
||||
if ([vertical boolValue])
|
||||
constraint = [NSString stringWithFormat:@"V:%@", [extra objectAtIndex:i]];
|
||||
constraint = [NSString stringWithFormat:@"V:%@", [p.extra objectAtIndex:i]];
|
||||
else
|
||||
constraint = [NSString stringWithFormat:@"H:%@", [extra objectAtIndex:i]];
|
||||
constraints = [NSLayoutConstraint constraintsWithVisualFormat:constraint options:0 metrics:nil views:views];
|
||||
constraint = [NSString stringWithFormat:@"H:%@", [p.extra objectAtIndex:i]];
|
||||
constraints = [NSLayoutConstraint constraintsWithVisualFormat:constraint options:0 metrics:nil views:p.views];
|
||||
[contentView addConstraints:constraints];
|
||||
}
|
||||
|
||||
// TODO release everything
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue