Started reimplementing uiBox. Added a first argument to the main Auto Layout function so uiBox can have subviews.

This commit is contained in:
Pietro Gagliardi 2015-08-01 18:05:50 -04:00
parent b528d1ff0c
commit 7bd98bafc9
6 changed files with 55 additions and 32 deletions

View File

@ -50,28 +50,39 @@
return n; 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; NSMutableArray *subhorz, *subvert;
__block uintmax_t n = nn; uintmax_t *first;
NSUInteger i;
if (self->vertical) first = (uintmax_t *) malloc([self->children count] * sizeof (uintmax_t));
constraints = [NSMutableString stringWithString:@"V:"]; if (first == NULL)
else abort();
constraints = [NSMutableString stringWithString:@"H:"]; subhorz = [NSMutableArray new];
[constraints appendString:@"|"]; subvert = [NSMutableArray new];
[self->children enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) { for (i = 0; i < [self->children count]; i++) {
NSString *thisView; id<tControl> cur;
// TODO have every control do this first[i] = *n;
[constraints appendString:tAutoLayoutKey(n)]; cur = (id<tControl>) [self->children objectAtIndex:i];
n++; [cur tFillAutoLayoutHorz:subhorz vert:subvert
}]; extra:extra extraVert:extraVert
[constraints appendString:@"|"]; views:views first:n];
return constraints; }
// TODOs: // TODO combine subhorz/subvert
// - lateral dimension: for each view of n+1, make other dimension next to first n [subhorz release];
// this way, subelement views get positioned right [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 @end

View File

@ -37,10 +37,15 @@
extra:(NSMutableArray *)extra extra:(NSMutableArray *)extra
extraVert:(NSMutableArray *)extraVert extraVert:(NSMutableArray *)extraVert
views:(NSMutableDictionary *)views views:(NSMutableDictionary *)views
first:(uintmax_t *)n
{ {
[horz addObject:@"[view0]"]; NSString *key;
[vert addObject:@"[view0]"];
[views setObject:self->b forKey:@"view0"]; key = tAutoLayoutKey(*n);
(*n)++;
[horz addObject:[NSString stringWithFormat:@"[%@]", key]];
[vert addObject:[NSString stringWithFormat:@"[%@]", key]];
[views setObject:self->b forKey:key];
} }
@end @end

View File

@ -10,7 +10,8 @@
vert:(NSMutableArray *)vert vert:(NSMutableArray *)vert
extra:(NSMutableArray *)extra extra:(NSMutableArray *)extra
extraVert:(NSMutableArray *)extraVert extraVert:(NSMutableArray *)extraVert
views:(NSMutableDictionary *)views; views:(NSMutableDictionary *)views
first:(uintmax_t *)n;
@end @end
@interface tWindow : NSObject<tControl> @interface tWindow : NSObject<tControl>
@ -21,12 +22,10 @@
- (void)tRelayout; - (void)tRelayout;
@end @end
/*
@interface tBox : NSObject<tControl> @interface tBox : NSObject<tControl>
- (id)tInitVertical:(BOOL)vert; - (id)tInitVertical:(BOOL)vert;
- (void)tAddControl:(id<tControl>)c stretchy:(BOOL)s; - (void)tAddControl:(id<tControl>)c stretchy:(BOOL)s;
@end @end
*/
@interface tButton : NSObject<tControl> @interface tButton : NSObject<tControl>
- (id)tInitWithText:(NSString *)text; - (id)tInitWithText:(NSString *)text;

View File

@ -49,11 +49,17 @@
extraVert:(NSMutableArray *)extraVert extraVert:(NSMutableArray *)extraVert
views:(NSMutableDictionary *)views views:(NSMutableDictionary *)views
{ {
[horz addObject:@"[view0]-[view1]"]; NSString *keyt;
[vert addObject:@"[view0]"]; NSString *keys;
[vert addObject:@"[view1]"];
[views setObject:self->t forKey:@"view0"]; keyt = tAutoLayoutKey(*n);
[views setObject:self->s forKey:@"view1"]; 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 @end

View File

@ -3,5 +3,5 @@
NSString *tAutoLayoutKey(uintmax_t n) NSString *tAutoLayoutKey(uintmax_t n)
{ {
return [NSString stringWithFormat:@"[view%ju]", n]; return [NSString stringWithFormat:@"view%ju", n];
} }

View File

@ -47,6 +47,7 @@
NSMutableDictionary *views; NSMutableDictionary *views;
NSUInteger i; NSUInteger i;
NSString *margin; NSString *margin;
uintmax_t n;
if (self->c == nil) if (self->c == nil)
return; return;
@ -57,7 +58,8 @@
extra = [NSMutableArray new]; extra = [NSMutableArray new];
extraVert = [NSMutableArray new]; extraVert = [NSMutableArray new];
views = [NSMutableDictionary 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 = @""; margin = @"";
if (self->margined) if (self->margined)
margin = @"-"; margin = @"-";