Started reimplementing uiBox. Added a first argument to the main Auto Layout function so uiBox can have subviews.
This commit is contained in:
parent
b528d1ff0c
commit
7bd98bafc9
|
@ -50,28 +50,39 @@
|
|||
return n;
|
||||
}
|
||||
|
||||
- (NSString *)tBuildAutoLayoutConstraintsKeyNumber:(uintmax_t)nn
|
||||
- (void)tFillAutoLayoutHorz:(NSMutableArray *)horz
|
||||
vert:(NSMutableArray *)vert
|
||||
extra:(NSMutableArray *)extra
|
||||
extraVert:(NSMutableArray *)extraVert
|
||||
views:(NSMutableDictionary *)views
|
||||
first:(uintmax_t *)n
|
||||
{
|
||||
NSMutableString *constraints;
|
||||
__block uintmax_t n = nn;
|
||||
NSMutableArray *subhorz, *subvert;
|
||||
uintmax_t *first;
|
||||
NSUInteger i;
|
||||
|
||||
if (self->vertical)
|
||||
constraints = [NSMutableString stringWithString:@"V:"];
|
||||
else
|
||||
constraints = [NSMutableString stringWithString:@"H:"];
|
||||
[constraints appendString:@"|"];
|
||||
[self->children enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
|
||||
NSString *thisView;
|
||||
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;
|
||||
|
||||
// TODO have every control do this
|
||||
[constraints appendString:tAutoLayoutKey(n)];
|
||||
n++;
|
||||
}];
|
||||
[constraints appendString:@"|"];
|
||||
return constraints;
|
||||
// TODOs:
|
||||
// - lateral dimension: for each view of n+1, make other dimension next to first n
|
||||
// this way, subelement views get positioned right
|
||||
first[i] = *n;
|
||||
cur = (id<tControl>) [self->children objectAtIndex:i];
|
||||
[cur tFillAutoLayoutHorz:subhorz vert:subvert
|
||||
extra:extra extraVert:extraVert
|
||||
views:views first:n];
|
||||
}
|
||||
// TODO combine subhorz/subvert
|
||||
[subhorz release];
|
||||
[subvert release];
|
||||
free(first);
|
||||
}
|
||||
|
||||
// TODOs:
|
||||
// - lateral dimension: for each view of n+1, make other dimension next to first n
|
||||
// this way, subelement views get positioned right
|
||||
|
||||
@end
|
|
@ -37,10 +37,15 @@
|
|||
extra:(NSMutableArray *)extra
|
||||
extraVert:(NSMutableArray *)extraVert
|
||||
views:(NSMutableDictionary *)views
|
||||
first:(uintmax_t *)n
|
||||
{
|
||||
[horz addObject:@"[view0]"];
|
||||
[vert addObject:@"[view0]"];
|
||||
[views setObject:self->b forKey:@"view0"];
|
||||
NSString *key;
|
||||
|
||||
key = tAutoLayoutKey(*n);
|
||||
(*n)++;
|
||||
[horz addObject:[NSString stringWithFormat:@"[%@]", key]];
|
||||
[vert addObject:[NSString stringWithFormat:@"[%@]", key]];
|
||||
[views setObject:self->b forKey:key];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
vert:(NSMutableArray *)vert
|
||||
extra:(NSMutableArray *)extra
|
||||
extraVert:(NSMutableArray *)extraVert
|
||||
views:(NSMutableDictionary *)views;
|
||||
views:(NSMutableDictionary *)views
|
||||
first:(uintmax_t *)n;
|
||||
@end
|
||||
|
||||
@interface tWindow : NSObject<tControl>
|
||||
|
@ -21,12 +22,10 @@
|
|||
- (void)tRelayout;
|
||||
@end
|
||||
|
||||
/*
|
||||
@interface tBox : NSObject<tControl>
|
||||
- (id)tInitVertical:(BOOL)vert;
|
||||
- (void)tAddControl:(id<tControl>)c stretchy:(BOOL)s;
|
||||
@end
|
||||
*/
|
||||
|
||||
@interface tButton : NSObject<tControl>
|
||||
- (id)tInitWithText:(NSString *)text;
|
||||
|
|
|
@ -49,11 +49,17 @@
|
|||
extraVert:(NSMutableArray *)extraVert
|
||||
views:(NSMutableDictionary *)views
|
||||
{
|
||||
[horz addObject:@"[view0]-[view1]"];
|
||||
[vert addObject:@"[view0]"];
|
||||
[vert addObject:@"[view1]"];
|
||||
[views setObject:self->t forKey:@"view0"];
|
||||
[views setObject:self->s forKey:@"view1"];
|
||||
NSString *keyt;
|
||||
NSString *keys;
|
||||
|
||||
keyt = tAutoLayoutKey(*n);
|
||||
keys = tAutoLayoutKey(*n + 1);
|
||||
*n += 2;
|
||||
[horz addObject:[NSString stringWithFormat:@"[%@]-[%@]", keyt, keys]];
|
||||
[vert addObject:[NSString stringWithFormat:@"[%@]", keyt]];
|
||||
[vert addObject:[NSString stringWithFormat:@"[%@]", keys]];
|
||||
[views setObject:self->t forKey:keyt];
|
||||
[views setObject:self->s forKey:keys];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
|
||||
NSString *tAutoLayoutKey(uintmax_t n)
|
||||
{
|
||||
return [NSString stringWithFormat:@"[view%ju]", n];
|
||||
return [NSString stringWithFormat:@"view%ju", n];
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
NSMutableDictionary *views;
|
||||
NSUInteger i;
|
||||
NSString *margin;
|
||||
uintmax_t n;
|
||||
|
||||
if (self->c == nil)
|
||||
return;
|
||||
|
@ -57,7 +58,8 @@
|
|||
extra = [NSMutableArray new];
|
||||
extraVert = [NSMutableArray new];
|
||||
views = [NSMutableDictionary new];
|
||||
[self->c tFillAutoLayoutHorz:horz vert:vert extra:extra extraVert:extraVert views:views];
|
||||
n = 0;
|
||||
[self->c tFillAutoLayoutHorz:horz vert:vert extra:extra extraVert:extraVert views:views first:&n];
|
||||
margin = @"";
|
||||
if (self->margined)
|
||||
margin = @"-";
|
||||
|
|
Loading…
Reference in New Issue