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];
|
[self tRelayout];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)tFillAutoLayoutHorz:(NSMutableArray *)horz
|
- (void)tFillAutoLayout:(tAutoLayoutParams *)p
|
||||||
vert:(NSMutableArray *)vert
|
|
||||||
extra:(NSMutableArray *)extra
|
|
||||||
extraVert:(NSMutableArray *)extraVert
|
|
||||||
views:(NSMutableDictionary *)views
|
|
||||||
first:(uintmax_t *)n
|
|
||||||
{
|
{
|
||||||
NSMutableArray *subhorz, *subvert;
|
NSMutableArray *subhorz, *subvert;
|
||||||
uintmax_t *first;
|
uintmax_t *first;
|
||||||
NSUInteger i;
|
NSUInteger i;
|
||||||
NSMutableString *out;
|
NSMutableString *out;
|
||||||
|
tAutoLayoutParams pp;
|
||||||
|
|
||||||
first = (uintmax_t *) malloc([self->children count] * sizeof (uintmax_t));
|
first = (uintmax_t *) malloc([self->children count] * sizeof (uintmax_t));
|
||||||
if (first == NULL)
|
if (first == NULL)
|
||||||
abort();
|
abort();
|
||||||
subhorz = [NSMutableArray new];
|
subhorz = [NSMutableArray new];
|
||||||
subvert = [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++) {
|
for (i = 0; i < [self->children count]; i++) {
|
||||||
id<tControl> cur;
|
id<tControl> cur;
|
||||||
|
|
||||||
first[i] = *n;
|
first[i] = pp.n;
|
||||||
cur = (id<tControl>) [self->children objectAtIndex:i];
|
cur = (id<tControl>) [self->children objectAtIndex:i];
|
||||||
[cur tFillAutoLayoutHorz:subhorz vert:subvert
|
[cur tFillAutoLayout:&pp];
|
||||||
extra:extra extraVert:extraVert
|
|
||||||
views:views first:n];
|
|
||||||
}
|
}
|
||||||
|
p->n = pp.n;
|
||||||
|
|
||||||
// TODO vertical
|
// TODO vertical
|
||||||
out = [NSMutableString new];
|
out = [NSMutableString new];
|
||||||
[subhorz enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
[subhorz enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
||||||
|
@ -78,8 +81,9 @@
|
||||||
//TODO [out appendString:@"-"];
|
//TODO [out appendString:@"-"];
|
||||||
[out appendString:((NSString *) obj)];
|
[out appendString:((NSString *) obj)];
|
||||||
}];
|
}];
|
||||||
[horz addObject:out];
|
[p->horz addObject:out];
|
||||||
[vert addObjectsFromArray:subvert];
|
[p->vert addObjectsFromArray:subvert];
|
||||||
|
|
||||||
[subhorz release];
|
[subhorz release];
|
||||||
[subvert release];
|
[subvert release];
|
||||||
free(first);
|
free(first);
|
||||||
|
|
|
@ -30,20 +30,15 @@
|
||||||
[self tRelayout];
|
[self tRelayout];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)tFillAutoLayoutHorz:(NSMutableArray *)horz
|
- (void)tFillAutoLayout:(tAutoLayoutParams *)p
|
||||||
vert:(NSMutableArray *)vert
|
|
||||||
extra:(NSMutableArray *)extra
|
|
||||||
extraVert:(NSMutableArray *)extraVert
|
|
||||||
views:(NSMutableDictionary *)views
|
|
||||||
first:(uintmax_t *)n
|
|
||||||
{
|
{
|
||||||
NSString *key;
|
NSString *key;
|
||||||
|
|
||||||
key = tAutoLayoutKey(*n);
|
key = tAutoLayoutKey(p->n);
|
||||||
(*n)++;
|
p->n++;
|
||||||
[horz addObject:[NSString stringWithFormat:@"[%@]", key]];
|
[p->horz addObject:[NSString stringWithFormat:@"[%@]", key]];
|
||||||
[vert addObject:[NSString stringWithFormat:@"[%@]", key]];
|
[p->vert addObject:[NSString stringWithFormat:@"[%@]", key]];
|
||||||
[views setObject:self->b forKey:key];
|
[p->views setObject:self->b forKey:key];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)tRelayout
|
- (void)tRelayout
|
||||||
|
|
|
@ -2,15 +2,21 @@
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
#import <stdint.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
|
@protocol tControl
|
||||||
@required
|
@required
|
||||||
- (void)tSetParent:(id<tControl>)p addToView:(NSView *)v;
|
- (void)tSetParent:(id<tControl>)p addToView:(NSView *)v;
|
||||||
- (void)tFillAutoLayoutHorz:(NSMutableArray *)horz
|
- (void)tFillAutoLayout:(tAutoLayoutParams *)p;
|
||||||
vert:(NSMutableArray *)vert
|
|
||||||
extra:(NSMutableArray *)extra
|
|
||||||
extraVert:(NSMutableArray *)extraVert
|
|
||||||
views:(NSMutableDictionary *)views
|
|
||||||
first:(uintmax_t *)n;
|
|
||||||
- (void)tRelayout;
|
- (void)tRelayout;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -73,20 +73,15 @@
|
||||||
[v addSubview:self->c];
|
[v addSubview:self->c];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)tFillAutoLayoutHorz:(NSMutableArray *)horz
|
- (void)tFillAutoLayout:(tAutoLayoutParams *)p
|
||||||
vert:(NSMutableArray *)vert
|
|
||||||
extra:(NSMutableArray *)extra
|
|
||||||
extraVert:(NSMutableArray *)extraVert
|
|
||||||
views:(NSMutableDictionary *)views
|
|
||||||
first:(uintmax_t *)n
|
|
||||||
{
|
{
|
||||||
NSString *key;
|
NSString *key;
|
||||||
|
|
||||||
key = tAutoLayoutKey(*n);
|
key = tAutoLayoutKey(p->n);
|
||||||
(*n)++;
|
p->n++;
|
||||||
[horz addObject:[NSString stringWithFormat:@"[%@]", key]];
|
[p->horz addObject:[NSString stringWithFormat:@"[%@]", key]];
|
||||||
[vert addObject:[NSString stringWithFormat:@"[%@]", key]];
|
[p->vert addObject:[NSString stringWithFormat:@"[%@]", key]];
|
||||||
[views setObject:self->c forKey:key];
|
[p->views setObject:self->c forKey:key];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)tRelayout
|
- (void)tRelayout
|
||||||
|
|
|
@ -42,48 +42,49 @@
|
||||||
- (void)tRelayout
|
- (void)tRelayout
|
||||||
{
|
{
|
||||||
NSView *contentView;
|
NSView *contentView;
|
||||||
NSMutableArray *horz, *vert;
|
tAutoLayoutParams p;
|
||||||
NSMutableArray *extra, *extraVert;
|
|
||||||
NSMutableDictionary *views;
|
|
||||||
NSUInteger i;
|
NSUInteger i;
|
||||||
NSString *margin;
|
NSString *margin;
|
||||||
uintmax_t n;
|
|
||||||
|
|
||||||
if (self->c == nil)
|
if (self->c == nil)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
contentView = [self->w contentView];
|
contentView = [self->w contentView];
|
||||||
[contentView removeConstraints:[contentView constraints]];
|
[contentView removeConstraints:[contentView constraints]];
|
||||||
horz = [NSMutableArray new];
|
|
||||||
vert = [NSMutableArray new];
|
p.horz = [NSMutableArray new];
|
||||||
extra = [NSMutableArray new];
|
p.vert = [NSMutableArray new];
|
||||||
extraVert = [NSMutableArray new];
|
p.extra = [NSMutableArray new];
|
||||||
views = [NSMutableDictionary new];
|
p.extraVert = [NSMutableArray new];
|
||||||
n = 0;
|
p.views = [NSMutableDictionary new];
|
||||||
[self->c tFillAutoLayoutHorz:horz vert:vert extra:extra extraVert:extraVert views:views first:&n];
|
p.n = 0;
|
||||||
|
[self->c tFillAutoLayout:&p];
|
||||||
|
|
||||||
margin = @"";
|
margin = @"";
|
||||||
if (self->margined)
|
if (self->margined)
|
||||||
margin = @"-";
|
margin = @"-";
|
||||||
[horz enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
[p.horz enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
||||||
[extra addObject:[NSString stringWithFormat:@"|%@%@%@|", margin, obj, margin]];
|
[p.extra addObject:[NSString stringWithFormat:@"|%@%@%@|", margin, obj, margin]];
|
||||||
[extraVert addObject:@NO];
|
[p.extraVert addObject:@NO];
|
||||||
}];
|
}];
|
||||||
[vert enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
[p.vert enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
||||||
[extra addObject:[NSString stringWithFormat:@"|%@%@%@|", margin, obj, margin]];
|
[p.extra addObject:[NSString stringWithFormat:@"|%@%@%@|", margin, obj, margin]];
|
||||||
[extraVert addObject:@YES];
|
[p.extraVert addObject:@YES];
|
||||||
}];
|
}];
|
||||||
for (i = 0; i < [extra count]; i++) {
|
for (i = 0; i < [p.extra count]; i++) {
|
||||||
NSString *constraint;
|
NSString *constraint;
|
||||||
NSNumber *vertical;
|
NSNumber *vertical;
|
||||||
NSArray *constraints;
|
NSArray *constraints;
|
||||||
|
|
||||||
vertical = (NSNumber *) [extraVert objectAtIndex:i];
|
vertical = (NSNumber *) [p.extraVert objectAtIndex:i];
|
||||||
if ([vertical boolValue])
|
if ([vertical boolValue])
|
||||||
constraint = [NSString stringWithFormat:@"V:%@", [extra objectAtIndex:i]];
|
constraint = [NSString stringWithFormat:@"V:%@", [p.extra objectAtIndex:i]];
|
||||||
else
|
else
|
||||||
constraint = [NSString stringWithFormat:@"H:%@", [extra objectAtIndex:i]];
|
constraint = [NSString stringWithFormat:@"H:%@", [p.extra objectAtIndex:i]];
|
||||||
constraints = [NSLayoutConstraint constraintsWithVisualFormat:constraint options:0 metrics:nil views:views];
|
constraints = [NSLayoutConstraint constraintsWithVisualFormat:constraint options:0 metrics:nil views:p.views];
|
||||||
[contentView addConstraints:constraints];
|
[contentView addConstraints:constraints];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO release everything
|
// TODO release everything
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue