Fix naming convention: Rename ASLayout's "children" to "sublayouts".

This commit is contained in:
Huy Nguyen
2015-07-01 17:52:01 +07:00
parent 2149d44990
commit 2a3753516a
11 changed files with 60 additions and 60 deletions

View File

@@ -1402,7 +1402,7 @@ static NSInteger incrementIfFound(NSInteger i) {
} }
// Assume that _layout was flattened and is 1-level deep. // Assume that _layout was flattened and is 1-level deep.
for (ASLayout *subnodeLayout in _layout.children) { for (ASLayout *subnodeLayout in _layout.sublayouts) {
ASDisplayNodeAssert([_subnodes containsObject:subnodeLayout.layoutableObject], @"Cached layout's children must only contain layout of subnodes."); ASDisplayNodeAssert([_subnodes containsObject:subnodeLayout.layoutableObject], @"Cached layout's children must only contain layout of subnodes.");
((ASDisplayNode *)subnodeLayout.layoutableObject).frame = CGRectMake(subnodeLayout.position.x, ((ASDisplayNode *)subnodeLayout.layoutableObject).frame = CGRectMake(subnodeLayout.position.x,
subnodeLayout.position.y, subnodeLayout.position.y,

View File

@@ -44,18 +44,18 @@
- (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize - (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
{ {
ASLayout *contentsLayout = [_child calculateLayoutThatFits:constrainedSize]; ASLayout *contentsLayout = [_child calculateLayoutThatFits:constrainedSize];
contentsLayout.position = CGPointZero;
NSMutableArray *children = [NSMutableArray arrayWithCapacity:2]; NSMutableArray *sublayouts = [NSMutableArray arrayWithCapacity:2];
if (_background) { if (_background) {
// Size background to exactly the same size. // Size background to exactly the same size.
ASLayout *backgroundLayout = [_background calculateLayoutThatFits:{contentsLayout.size, contentsLayout.size}]; ASLayout *backgroundLayout = [_background calculateLayoutThatFits:{contentsLayout.size, contentsLayout.size}];
backgroundLayout.position = CGPointZero; backgroundLayout.position = CGPointZero;
[children addObject:backgroundLayout]; [sublayouts addObject:backgroundLayout];
} }
[children addObject:contentsLayout]; contentsLayout.position = CGPointZero;
[sublayouts addObject:contentsLayout];
return [ASLayout newWithLayoutableObject:self size:contentsLayout.size children:children]; return [ASLayout newWithLayoutableObject:self size:contentsLayout.size sublayouts:sublayouts];
} }
@end @end

View File

@@ -49,30 +49,30 @@
(_centeringOptions & ASCenterLayoutSpecCenteringX) != 0 ? 0 : constrainedSize.min.width, (_centeringOptions & ASCenterLayoutSpecCenteringX) != 0 ? 0 : constrainedSize.min.width,
(_centeringOptions & ASCenterLayoutSpecCenteringY) != 0 ? 0 : constrainedSize.min.height, (_centeringOptions & ASCenterLayoutSpecCenteringY) != 0 ? 0 : constrainedSize.min.height,
}; };
ASLayout *childLayout = [_child calculateLayoutThatFits:ASSizeRangeMake(minChildSize, constrainedSize.max)]; ASLayout *sublayout = [_child calculateLayoutThatFits:ASSizeRangeMake(minChildSize, constrainedSize.max)];
// If we have an undetermined height or width, use the child size to define the layout // If we have an undetermined height or width, use the child size to define the layout
// size // size
size = ASSizeRangeClamp(constrainedSize, { size = ASSizeRangeClamp(constrainedSize, {
isnan(size.width) ? childLayout.size.width : size.width, isnan(size.width) ? sublayout.size.width : size.width,
isnan(size.height) ? childLayout.size.height : size.height isnan(size.height) ? sublayout.size.height : size.height
}); });
// If minimum size options are set, attempt to shrink the size to the size of the child // If minimum size options are set, attempt to shrink the size to the size of the child
size = ASSizeRangeClamp(constrainedSize, { size = ASSizeRangeClamp(constrainedSize, {
MIN(size.width, (_sizingOptions & ASCenterLayoutSpecSizingOptionMinimumX) != 0 ? childLayout.size.width : size.width), MIN(size.width, (_sizingOptions & ASCenterLayoutSpecSizingOptionMinimumX) != 0 ? sublayout.size.width : size.width),
MIN(size.height, (_sizingOptions & ASCenterLayoutSpecSizingOptionMinimumY) != 0 ? childLayout.size.height : size.height) MIN(size.height, (_sizingOptions & ASCenterLayoutSpecSizingOptionMinimumY) != 0 ? sublayout.size.height : size.height)
}); });
// Compute the centered postion for the child // Compute the centered postion for the child
BOOL shouldCenterAlongX = (_centeringOptions & ASCenterLayoutSpecCenteringX); BOOL shouldCenterAlongX = (_centeringOptions & ASCenterLayoutSpecCenteringX);
BOOL shouldCenterAlongY = (_centeringOptions & ASCenterLayoutSpecCenteringY); BOOL shouldCenterAlongY = (_centeringOptions & ASCenterLayoutSpecCenteringY);
childLayout.position = { sublayout.position = {
ASRoundPixelValue(shouldCenterAlongX ? (size.width - childLayout.size.width) * 0.5f : 0), ASRoundPixelValue(shouldCenterAlongX ? (size.width - sublayout.size.width) * 0.5f : 0),
ASRoundPixelValue(shouldCenterAlongY ? (size.height - childLayout.size.height) * 0.5f : 0) ASRoundPixelValue(shouldCenterAlongY ? (size.height - sublayout.size.height) * 0.5f : 0)
}; };
return [ASLayout newWithLayoutableObject:self size:size children:@[childLayout]]; return [ASLayout newWithLayoutableObject:self size:size sublayouts:@[sublayout]];
} }
@end @end

View File

@@ -84,25 +84,25 @@ static CGFloat centerInset(CGFloat outer, CGFloat inner)
MAX(0, constrainedSize.max.height - insetsY), MAX(0, constrainedSize.max.height - insetsY),
} }
}; };
ASLayout *childLayout = [_child calculateLayoutThatFits:insetConstrainedSize]; ASLayout *sublayout = [_child calculateLayoutThatFits:insetConstrainedSize];
const CGSize computedSize = ASSizeRangeClamp(constrainedSize, { const CGSize computedSize = ASSizeRangeClamp(constrainedSize, {
finite(childLayout.size.width + _insets.left + _insets.right, constrainedSize.max.width), finite(sublayout.size.width + _insets.left + _insets.right, constrainedSize.max.width),
finite(childLayout.size.height + _insets.top + _insets.bottom, constrainedSize.max.height), finite(sublayout.size.height + _insets.top + _insets.bottom, constrainedSize.max.height),
}); });
const CGFloat x = finite(_insets.left, constrainedSize.max.width - const CGFloat x = finite(_insets.left, constrainedSize.max.width -
(finite(_insets.right, (finite(_insets.right,
centerInset(constrainedSize.max.width, childLayout.size.width)) + childLayout.size.width)); centerInset(constrainedSize.max.width, sublayout.size.width)) + sublayout.size.width));
const CGFloat y = finite(_insets.top, const CGFloat y = finite(_insets.top,
constrainedSize.max.height - constrainedSize.max.height -
(finite(_insets.bottom, (finite(_insets.bottom,
centerInset(constrainedSize.max.height, childLayout.size.height)) + childLayout.size.height)); centerInset(constrainedSize.max.height, sublayout.size.height)) + sublayout.size.height));
childLayout.position = CGPointMake(x, y); sublayout.position = CGPointMake(x, y);
return [ASLayout newWithLayoutableObject:self size:computedSize children:@[childLayout]]; return [ASLayout newWithLayoutableObject:self size:computedSize sublayouts:@[sublayout]];
} }
@end @end

View File

@@ -24,7 +24,7 @@ extern BOOL CGPointIsNull(CGPoint point);
/** /**
* Position in parent. Default to CGPointNull. * Position in parent. Default to CGPointNull.
* *
* @discussion Before being used as a child layout, this property must be set and no longer equal CGPointNull. * @discussion Before being used as a sublayout, this property must be set and no longer equal CGPointNull.
* *
* @discussion Unlike all other properties, this property is read-write because often by initializaion time, it has yet been determined. * @discussion Unlike all other properties, this property is read-write because often by initializaion time, it has yet been determined.
* To enforce immutability, this property can be set once and only once. * To enforce immutability, this property can be set once and only once.
@@ -32,24 +32,24 @@ extern BOOL CGPointIsNull(CGPoint point);
*/ */
@property (nonatomic, readwrite) CGPoint position; @property (nonatomic, readwrite) CGPoint position;
/** /**
* Array of ASLayout children. Each child must have a valid non-null position. * Array of ASLayouts. Each must have a valid non-null position.
*/ */
@property (nonatomic, readonly) NSArray *children; @property (nonatomic, readonly) NSArray *sublayouts;
+ (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject + (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject
size:(CGSize)size size:(CGSize)size
position:(CGPoint)position position:(CGPoint)position
children:(NSArray *)children; sublayouts:(NSArray *)sublayouts;
/** /**
* Convenience that has CGPointNull position. * Convenience that has CGPointNull position.
*/ */
+ (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject + (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject
size:(CGSize)size size:(CGSize)size
children:(NSArray *)children; sublayouts:(NSArray *)sublayouts;
/** /**
* Convenience that has CGPointNull position and no children. * Convenience that has CGPointNull position and no sublayouts.
*/ */
+ (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject size:(CGSize)size; + (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject size:(CGSize)size;
@@ -62,7 +62,7 @@ extern BOOL CGPointIsNull(CGPoint point);
* The block takes 1 argument: evaluatedLayout - the layout to be evaluated. * The block takes 1 argument: evaluatedLayout - the layout to be evaluated.
* The block returns YES if evaluatedLayout evaluates to true, otherwise NO. * The block returns YES if evaluatedLayout evaluates to true, otherwise NO.
* *
* @return A new, 1-level deep layout containing the layout children for which the predicate block returns true. * @return A new, 1-level deep layout containing the layouts for which the predicate block returns true.
*/ */
- (ASLayout *)flattenedLayoutUsingPredicateBlock:(BOOL (^)(ASLayout *evaluatedLayout))predicateBlock; - (ASLayout *)flattenedLayoutUsingPredicateBlock:(BOOL (^)(ASLayout *evaluatedLayout))predicateBlock;

View File

@@ -25,11 +25,11 @@ extern BOOL CGPointIsNull(CGPoint point)
+ (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject + (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject
size:(CGSize)size size:(CGSize)size
position:(CGPoint)position position:(CGPoint)position
children:(NSArray *)children sublayouts:(NSArray *)sublayouts
{ {
ASDisplayNodeAssert(layoutableObject, @"layoutableObject is required."); ASDisplayNodeAssert(layoutableObject, @"layoutableObject is required.");
for (ASLayout *child in children) { for (ASLayout *sublayout in sublayouts) {
ASDisplayNodeAssert(!CGPointIsNull(child.position), @"Invalid position is not allowed in children."); ASDisplayNodeAssert(!CGPointIsNull(sublayout.position), @"Invalid position is not allowed in sublayout.");
} }
ASLayout *l = [super new]; ASLayout *l = [super new];
@@ -37,21 +37,21 @@ extern BOOL CGPointIsNull(CGPoint point)
l->_layoutableObject = layoutableObject; l->_layoutableObject = layoutableObject;
l->_size = size; l->_size = size;
l->_position = position; l->_position = position;
l->_children = [children copy]; l->_sublayouts = [sublayouts copy];
} }
return l; return l;
} }
+ (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject + (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject
size:(CGSize)size size:(CGSize)size
children:(NSArray *)children sublayouts:(NSArray *)sublayouts
{ {
return [self newWithLayoutableObject:layoutableObject size:size position:CGPointNull children:children]; return [self newWithLayoutableObject:layoutableObject size:size position:CGPointNull sublayouts:sublayouts];
} }
+ (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject size:(CGSize)size + (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject size:(CGSize)size
{ {
return [self newWithLayoutableObject:layoutableObject size:size children:nil]; return [self newWithLayoutableObject:layoutableObject size:size sublayouts:nil];
} }
- (void)setPosition:(CGPoint)position - (void)setPosition:(CGPoint)position
@@ -63,7 +63,7 @@ extern BOOL CGPointIsNull(CGPoint point)
- (ASLayout *)flattenedLayoutUsingPredicateBlock:(BOOL (^)(ASLayout *))predicateBlock - (ASLayout *)flattenedLayoutUsingPredicateBlock:(BOOL (^)(ASLayout *))predicateBlock
{ {
NSMutableArray *flattenedChildren = [NSMutableArray array]; NSMutableArray *flattenedSublayouts = [NSMutableArray array];
struct Context { struct Context {
ASLayout *layout; ASLayout *layout;
@@ -83,19 +83,19 @@ extern BOOL CGPointIsNull(CGPoint point)
context.visited = YES; context.visited = YES;
if (predicateBlock(context.layout)) { if (predicateBlock(context.layout)) {
[flattenedChildren addObject:[ASLayout newWithLayoutableObject:context.layout.layoutableObject [flattenedSublayouts addObject:[ASLayout newWithLayoutableObject:context.layout.layoutableObject
size:context.layout.size size:context.layout.size
position:context.absolutePosition position:context.absolutePosition
children:nil]]; sublayouts:nil]];
} }
for (ASLayout *child in context.layout.children) { for (ASLayout *sublayout in context.layout.sublayouts) {
stack.push({child, context.absolutePosition + child.position, NO}); stack.push({sublayout, context.absolutePosition + sublayout.position, NO});
} }
} }
} }
return [ASLayout newWithLayoutableObject:_layoutableObject size:_size children:flattenedChildren]; return [ASLayout newWithLayoutableObject:_layoutableObject size:_size sublayouts:flattenedSublayouts];
} }
@end @end

View File

@@ -42,14 +42,14 @@
{ {
ASLayout *contentsLayout = [_child calculateLayoutThatFits:constrainedSize]; ASLayout *contentsLayout = [_child calculateLayoutThatFits:constrainedSize];
contentsLayout.position = CGPointZero; contentsLayout.position = CGPointZero;
NSMutableArray *layoutChildren = [NSMutableArray arrayWithObject:contentsLayout]; NSMutableArray *sublayouts = [NSMutableArray arrayWithObject:contentsLayout];
if (_overlay) { if (_overlay) {
ASLayout *overlayLayout = [_overlay calculateLayoutThatFits:{contentsLayout.size, contentsLayout.size}]; ASLayout *overlayLayout = [_overlay calculateLayoutThatFits:{contentsLayout.size, contentsLayout.size}];
overlayLayout.position = CGPointZero; overlayLayout.position = CGPointZero;
[layoutChildren addObject:overlayLayout]; [sublayouts addObject:overlayLayout];
} }
return [ASLayout newWithLayoutableObject:self size:contentsLayout.size children:layoutChildren]; return [ASLayout newWithLayoutableObject:self size:contentsLayout.size sublayouts:sublayouts];
} }
@end @end

View File

@@ -67,9 +67,9 @@
// If there is no max size in *either* dimension, we can't apply the ratio, so just pass our size range through. // If there is no max size in *either* dimension, we can't apply the ratio, so just pass our size range through.
const ASSizeRange childRange = (bestSize == sizeOptions.end()) ? constrainedSize : ASSizeRangeMake(*bestSize, *bestSize); const ASSizeRange childRange = (bestSize == sizeOptions.end()) ? constrainedSize : ASSizeRangeMake(*bestSize, *bestSize);
ASLayout *childLayout = [_child calculateLayoutThatFits:childRange]; ASLayout *sublayout = [_child calculateLayoutThatFits:childRange];
childLayout.position = CGPointZero; sublayout.position = CGPointZero;
return [ASLayout newWithLayoutableObject:self size:childLayout.size children:@[childLayout]]; return [ASLayout newWithLayoutableObject:self size:sublayout.size sublayouts:@[sublayout]];
} }
@end @end

View File

@@ -50,10 +50,10 @@
const auto unpositionedLayout = ASStackUnpositionedLayout::compute(_children, _style, constrainedSize); const auto unpositionedLayout = ASStackUnpositionedLayout::compute(_children, _style, constrainedSize);
const auto positionedLayout = ASStackPositionedLayout::compute(unpositionedLayout, _style, constrainedSize); const auto positionedLayout = ASStackPositionedLayout::compute(unpositionedLayout, _style, constrainedSize);
const CGSize finalSize = directionSize(_style.direction, unpositionedLayout.stackDimensionSum, positionedLayout.crossSize); const CGSize finalSize = directionSize(_style.direction, unpositionedLayout.stackDimensionSum, positionedLayout.crossSize);
NSArray *children = [NSArray arrayWithObjects:&positionedLayout.children[0] count:positionedLayout.children.size()]; NSArray *sublayouts = [NSArray arrayWithObjects:&positionedLayout.sublayouts[0] count:positionedLayout.sublayouts.size()];
return [ASLayout newWithLayoutableObject:self return [ASLayout newWithLayoutableObject:self
size:ASSizeRangeClamp(constrainedSize, finalSize) size:ASSizeRangeClamp(constrainedSize, finalSize)
children:children]; sublayouts:sublayouts];
} }
@end @end

View File

@@ -59,7 +59,7 @@
constrainedSize.max.height constrainedSize.max.height
}; };
NSMutableArray *layoutChildren = [NSMutableArray arrayWithCapacity:_children.count]; NSMutableArray *sublayouts = [NSMutableArray arrayWithCapacity:_children.count];
for (ASStaticLayoutSpecChild *child in _children) { for (ASStaticLayoutSpecChild *child in _children) {
CGSize autoMaxSize = { CGSize autoMaxSize = {
constrainedSize.max.width - child.position.x, constrainedSize.max.width - child.position.x,
@@ -68,28 +68,28 @@
ASSizeRange childConstraint = ASRelativeSizeRangeEqualToRelativeSizeRange(ASRelativeSizeRangeUnconstrained, child.size) ASSizeRange childConstraint = ASRelativeSizeRangeEqualToRelativeSizeRange(ASRelativeSizeRangeUnconstrained, child.size)
? ASSizeRangeMake({0, 0}, autoMaxSize) ? ASSizeRangeMake({0, 0}, autoMaxSize)
: ASRelativeSizeRangeResolve(child.size, size); : ASRelativeSizeRangeResolve(child.size, size);
ASLayout *childLayout = [child.layoutableObject calculateLayoutThatFits:childConstraint]; ASLayout *sublayout = [child.layoutableObject calculateLayoutThatFits:childConstraint];
childLayout.position = child.position; sublayout.position = child.position;
[layoutChildren addObject:childLayout]; [sublayouts addObject:sublayout];
} }
if (isnan(size.width)) { if (isnan(size.width)) {
size.width = constrainedSize.min.width; size.width = constrainedSize.min.width;
for (ASLayout *child in layoutChildren) { for (ASLayout *sublayout in sublayouts) {
size.width = MAX(size.width, child.position.x + child.size.width); size.width = MAX(size.width, sublayout.position.x + sublayout.size.width);
} }
} }
if (isnan(size.height)) { if (isnan(size.height)) {
size.height = constrainedSize.min.height; size.height = constrainedSize.min.height;
for (ASLayout *child in layoutChildren) { for (ASLayout *sublayout in sublayouts) {
size.height = MAX(size.height, child.position.y + child.size.height); size.height = MAX(size.height, sublayout.position.y + sublayout.size.height);
} }
} }
return [ASLayout newWithLayoutableObject:self return [ASLayout newWithLayoutableObject:self
size:ASSizeRangeClamp(constrainedSize, size) size:ASSizeRangeClamp(constrainedSize, size)
children:layoutChildren]; sublayouts:sublayouts];
} }
@end @end

View File

@@ -15,7 +15,7 @@
/** Represents a set of laid out and positioned stack layout children. */ /** Represents a set of laid out and positioned stack layout children. */
struct ASStackPositionedLayout { struct ASStackPositionedLayout {
const std::vector<ASLayout *> children; const std::vector<ASLayout *> sublayouts;
const CGFloat crossSize; const CGFloat crossSize;
/** Given an unpositioned layout, computes the positions each child should be placed at. */ /** Given an unpositioned layout, computes the positions each child should be placed at. */