Added a non-stretchy predicate for non-stretchy controls. This fixes our spinboxes.

This commit is contained in:
Pietro Gagliardi 2015-08-03 12:43:51 -04:00
parent 1e66408881
commit 70adbf6496
3 changed files with 14 additions and 1 deletions

View File

@ -57,7 +57,6 @@
[self tRelayout]; [self tRelayout];
} }
// TODO custom minimum width for non-stretchy controls
- (void)tFillAutoLayout:(tAutoLayoutParams *)p - (void)tFillAutoLayout:(tAutoLayoutParams *)p
{ {
NSMutableDictionary *views; NSMutableDictionary *views;
@ -67,6 +66,7 @@
BOOL firstStretchy; BOOL firstStretchy;
uintmax_t nStretchy; uintmax_t nStretchy;
NSLayoutConstraintOrientation orientation; NSLayoutConstraintOrientation orientation;
__block NSMutableArray *predicates;
if ([self->children count] == 0) if ([self->children count] == 0)
goto selfOnly; goto selfOnly;
@ -79,6 +79,7 @@
views = [NSMutableDictionary new]; views = [NSMutableDictionary new];
n = 0; n = 0;
predicates = [NSMutableArray new];
[self->children enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) { [self->children enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop) {
id<tControl> c; id<tControl> c;
NSNumber *isStretchy; NSNumber *isStretchy;
@ -86,12 +87,18 @@
c = (id<tControl>) obj; c = (id<tControl>) obj;
isStretchy = (NSNumber *) [self->stretchy objectAtIndex:n]; isStretchy = (NSNumber *) [self->stretchy objectAtIndex:n];
pp.nonStretchyWidthPredicate = @"";
pp.nonStretchyHeightPredicate = @"";
// this also resets the hugging priority // this also resets the hugging priority
// TODO do this when adding and removing controls instead // TODO do this when adding and removing controls instead
[c tFillAutoLayout:&pp]; [c tFillAutoLayout:&pp];
priority = NSLayoutPriorityDefaultHigh; // forcibly hug; avoid stretching out priority = NSLayoutPriorityDefaultHigh; // forcibly hug; avoid stretching out
if ([isStretchy boolValue]) if ([isStretchy boolValue])
priority = NSLayoutPriorityDefaultLow; // do not forcibly hug; freely stretch out priority = NSLayoutPriorityDefaultLow; // do not forcibly hug; freely stretch out
if (self->vertical)
[predicates addObject:pp.nonStretchyHeightPredicate];
else
[predicates addObject:pp.nonStretchyWidthPredicate];
[pp.view setContentHuggingPriority:priority forOrientation:orientation]; [pp.view setContentHuggingPriority:priority forOrientation:orientation];
[views setObject:pp.view forKey:tAutoLayoutKey(n)]; [views setObject:pp.view forKey:tAutoLayoutKey(n)];
n++; n++;
@ -120,6 +127,8 @@
[constraint appendString:tAutoLayoutKey(nStretchy)]; [constraint appendString:tAutoLayoutKey(nStretchy)];
[constraint appendString:@")"]; [constraint appendString:@")"];
} }
else
[constraint appendString:[predicates objectAtIndex:i]];
[constraint appendString:@"]"]; [constraint appendString:@"]"];
} }
[constraint appendString:@"|"]; [constraint appendString:@"|"];
@ -140,6 +149,7 @@ NSLog(@"other dimension %@", constraint);
// TODO do not release constraint; it's autoreleased? // TODO do not release constraint; it's autoreleased?
} }
[predicates release];
[views release]; [views release];
// and now populate for self // and now populate for self

View File

@ -12,6 +12,8 @@ struct tAutoLayoutParams {
BOOL attachTop; BOOL attachTop;
BOOL attachRight; BOOL attachRight;
BOOL attachBottom; BOOL attachBottom;
NSString *nonStretchyWidthPredicate;
NSString *nonStretchyHeightPredicate;
}; };
@protocol tControl @protocol tControl

View File

@ -93,6 +93,7 @@ nspinbox++;
p->attachTop = YES; p->attachTop = YES;
p->attachRight = YES; p->attachRight = YES;
p->attachBottom = YES; p->attachBottom = YES;
p->nonStretchyWidthPredicate = @"(==96)"; // TODO on the text field only
} }
- (void)tRelayout - (void)tRelayout