mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Fix naming convention: Rename ASLayout's "children" to "sublayouts".
This commit is contained in:
@@ -1402,7 +1402,7 @@ static NSInteger incrementIfFound(NSInteger i) {
|
||||
}
|
||||
|
||||
// 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.");
|
||||
((ASDisplayNode *)subnodeLayout.layoutableObject).frame = CGRectMake(subnodeLayout.position.x,
|
||||
subnodeLayout.position.y,
|
||||
|
||||
@@ -44,18 +44,18 @@
|
||||
- (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
|
||||
{
|
||||
ASLayout *contentsLayout = [_child calculateLayoutThatFits:constrainedSize];
|
||||
contentsLayout.position = CGPointZero;
|
||||
|
||||
NSMutableArray *children = [NSMutableArray arrayWithCapacity:2];
|
||||
NSMutableArray *sublayouts = [NSMutableArray arrayWithCapacity:2];
|
||||
if (_background) {
|
||||
// Size background to exactly the same size.
|
||||
ASLayout *backgroundLayout = [_background calculateLayoutThatFits:{contentsLayout.size, contentsLayout.size}];
|
||||
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
|
||||
|
||||
@@ -49,30 +49,30 @@
|
||||
(_centeringOptions & ASCenterLayoutSpecCenteringX) != 0 ? 0 : constrainedSize.min.width,
|
||||
(_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
|
||||
// size
|
||||
size = ASSizeRangeClamp(constrainedSize, {
|
||||
isnan(size.width) ? childLayout.size.width : size.width,
|
||||
isnan(size.height) ? childLayout.size.height : size.height
|
||||
isnan(size.width) ? sublayout.size.width : size.width,
|
||||
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
|
||||
size = ASSizeRangeClamp(constrainedSize, {
|
||||
MIN(size.width, (_sizingOptions & ASCenterLayoutSpecSizingOptionMinimumX) != 0 ? childLayout.size.width : size.width),
|
||||
MIN(size.height, (_sizingOptions & ASCenterLayoutSpecSizingOptionMinimumY) != 0 ? childLayout.size.height : size.height)
|
||||
MIN(size.width, (_sizingOptions & ASCenterLayoutSpecSizingOptionMinimumX) != 0 ? sublayout.size.width : size.width),
|
||||
MIN(size.height, (_sizingOptions & ASCenterLayoutSpecSizingOptionMinimumY) != 0 ? sublayout.size.height : size.height)
|
||||
});
|
||||
|
||||
// Compute the centered postion for the child
|
||||
BOOL shouldCenterAlongX = (_centeringOptions & ASCenterLayoutSpecCenteringX);
|
||||
BOOL shouldCenterAlongY = (_centeringOptions & ASCenterLayoutSpecCenteringY);
|
||||
childLayout.position = {
|
||||
ASRoundPixelValue(shouldCenterAlongX ? (size.width - childLayout.size.width) * 0.5f : 0),
|
||||
ASRoundPixelValue(shouldCenterAlongY ? (size.height - childLayout.size.height) * 0.5f : 0)
|
||||
sublayout.position = {
|
||||
ASRoundPixelValue(shouldCenterAlongX ? (size.width - sublayout.size.width) * 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
|
||||
|
||||
@@ -84,25 +84,25 @@ static CGFloat centerInset(CGFloat outer, CGFloat inner)
|
||||
MAX(0, constrainedSize.max.height - insetsY),
|
||||
}
|
||||
};
|
||||
ASLayout *childLayout = [_child calculateLayoutThatFits:insetConstrainedSize];
|
||||
ASLayout *sublayout = [_child calculateLayoutThatFits:insetConstrainedSize];
|
||||
|
||||
const CGSize computedSize = ASSizeRangeClamp(constrainedSize, {
|
||||
finite(childLayout.size.width + _insets.left + _insets.right, constrainedSize.max.width),
|
||||
finite(childLayout.size.height + _insets.top + _insets.bottom, constrainedSize.max.height),
|
||||
finite(sublayout.size.width + _insets.left + _insets.right, constrainedSize.max.width),
|
||||
finite(sublayout.size.height + _insets.top + _insets.bottom, constrainedSize.max.height),
|
||||
});
|
||||
|
||||
const CGFloat x = finite(_insets.left, constrainedSize.max.width -
|
||||
(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,
|
||||
constrainedSize.max.height -
|
||||
(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
|
||||
|
||||
@@ -24,7 +24,7 @@ extern BOOL CGPointIsNull(CGPoint point);
|
||||
/**
|
||||
* 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.
|
||||
* 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;
|
||||
/**
|
||||
* 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
|
||||
size:(CGSize)size
|
||||
position:(CGPoint)position
|
||||
children:(NSArray *)children;
|
||||
sublayouts:(NSArray *)sublayouts;
|
||||
|
||||
/**
|
||||
* Convenience that has CGPointNull position.
|
||||
*/
|
||||
+ (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject
|
||||
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;
|
||||
|
||||
@@ -62,7 +62,7 @@ extern BOOL CGPointIsNull(CGPoint point);
|
||||
* The block takes 1 argument: evaluatedLayout - the layout to be evaluated.
|
||||
* 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;
|
||||
|
||||
|
||||
@@ -25,11 +25,11 @@ extern BOOL CGPointIsNull(CGPoint point)
|
||||
+ (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject
|
||||
size:(CGSize)size
|
||||
position:(CGPoint)position
|
||||
children:(NSArray *)children
|
||||
sublayouts:(NSArray *)sublayouts
|
||||
{
|
||||
ASDisplayNodeAssert(layoutableObject, @"layoutableObject is required.");
|
||||
for (ASLayout *child in children) {
|
||||
ASDisplayNodeAssert(!CGPointIsNull(child.position), @"Invalid position is not allowed in children.");
|
||||
for (ASLayout *sublayout in sublayouts) {
|
||||
ASDisplayNodeAssert(!CGPointIsNull(sublayout.position), @"Invalid position is not allowed in sublayout.");
|
||||
}
|
||||
|
||||
ASLayout *l = [super new];
|
||||
@@ -37,21 +37,21 @@ extern BOOL CGPointIsNull(CGPoint point)
|
||||
l->_layoutableObject = layoutableObject;
|
||||
l->_size = size;
|
||||
l->_position = position;
|
||||
l->_children = [children copy];
|
||||
l->_sublayouts = [sublayouts copy];
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
+ (instancetype)newWithLayoutableObject:(id<ASLayoutable>)layoutableObject
|
||||
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
|
||||
{
|
||||
return [self newWithLayoutableObject:layoutableObject size:size children:nil];
|
||||
return [self newWithLayoutableObject:layoutableObject size:size sublayouts:nil];
|
||||
}
|
||||
|
||||
- (void)setPosition:(CGPoint)position
|
||||
@@ -63,7 +63,7 @@ extern BOOL CGPointIsNull(CGPoint point)
|
||||
|
||||
- (ASLayout *)flattenedLayoutUsingPredicateBlock:(BOOL (^)(ASLayout *))predicateBlock
|
||||
{
|
||||
NSMutableArray *flattenedChildren = [NSMutableArray array];
|
||||
NSMutableArray *flattenedSublayouts = [NSMutableArray array];
|
||||
|
||||
struct Context {
|
||||
ASLayout *layout;
|
||||
@@ -83,19 +83,19 @@ extern BOOL CGPointIsNull(CGPoint point)
|
||||
context.visited = YES;
|
||||
|
||||
if (predicateBlock(context.layout)) {
|
||||
[flattenedChildren addObject:[ASLayout newWithLayoutableObject:context.layout.layoutableObject
|
||||
[flattenedSublayouts addObject:[ASLayout newWithLayoutableObject:context.layout.layoutableObject
|
||||
size:context.layout.size
|
||||
position:context.absolutePosition
|
||||
children:nil]];
|
||||
sublayouts:nil]];
|
||||
}
|
||||
|
||||
for (ASLayout *child in context.layout.children) {
|
||||
stack.push({child, context.absolutePosition + child.position, NO});
|
||||
for (ASLayout *sublayout in context.layout.sublayouts) {
|
||||
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
|
||||
|
||||
@@ -42,14 +42,14 @@
|
||||
{
|
||||
ASLayout *contentsLayout = [_child calculateLayoutThatFits:constrainedSize];
|
||||
contentsLayout.position = CGPointZero;
|
||||
NSMutableArray *layoutChildren = [NSMutableArray arrayWithObject:contentsLayout];
|
||||
NSMutableArray *sublayouts = [NSMutableArray arrayWithObject:contentsLayout];
|
||||
if (_overlay) {
|
||||
ASLayout *overlayLayout = [_overlay calculateLayoutThatFits:{contentsLayout.size, contentsLayout.size}];
|
||||
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
|
||||
|
||||
@@ -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.
|
||||
const ASSizeRange childRange = (bestSize == sizeOptions.end()) ? constrainedSize : ASSizeRangeMake(*bestSize, *bestSize);
|
||||
ASLayout *childLayout = [_child calculateLayoutThatFits:childRange];
|
||||
childLayout.position = CGPointZero;
|
||||
return [ASLayout newWithLayoutableObject:self size:childLayout.size children:@[childLayout]];
|
||||
ASLayout *sublayout = [_child calculateLayoutThatFits:childRange];
|
||||
sublayout.position = CGPointZero;
|
||||
return [ASLayout newWithLayoutableObject:self size:sublayout.size sublayouts:@[sublayout]];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -50,10 +50,10 @@
|
||||
const auto unpositionedLayout = ASStackUnpositionedLayout::compute(_children, _style, constrainedSize);
|
||||
const auto positionedLayout = ASStackPositionedLayout::compute(unpositionedLayout, _style, constrainedSize);
|
||||
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
|
||||
size:ASSizeRangeClamp(constrainedSize, finalSize)
|
||||
children:children];
|
||||
sublayouts:sublayouts];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
constrainedSize.max.height
|
||||
};
|
||||
|
||||
NSMutableArray *layoutChildren = [NSMutableArray arrayWithCapacity:_children.count];
|
||||
NSMutableArray *sublayouts = [NSMutableArray arrayWithCapacity:_children.count];
|
||||
for (ASStaticLayoutSpecChild *child in _children) {
|
||||
CGSize autoMaxSize = {
|
||||
constrainedSize.max.width - child.position.x,
|
||||
@@ -68,28 +68,28 @@
|
||||
ASSizeRange childConstraint = ASRelativeSizeRangeEqualToRelativeSizeRange(ASRelativeSizeRangeUnconstrained, child.size)
|
||||
? ASSizeRangeMake({0, 0}, autoMaxSize)
|
||||
: ASRelativeSizeRangeResolve(child.size, size);
|
||||
ASLayout *childLayout = [child.layoutableObject calculateLayoutThatFits:childConstraint];
|
||||
childLayout.position = child.position;
|
||||
[layoutChildren addObject:childLayout];
|
||||
ASLayout *sublayout = [child.layoutableObject calculateLayoutThatFits:childConstraint];
|
||||
sublayout.position = child.position;
|
||||
[sublayouts addObject:sublayout];
|
||||
}
|
||||
|
||||
if (isnan(size.width)) {
|
||||
size.width = constrainedSize.min.width;
|
||||
for (ASLayout *child in layoutChildren) {
|
||||
size.width = MAX(size.width, child.position.x + child.size.width);
|
||||
for (ASLayout *sublayout in sublayouts) {
|
||||
size.width = MAX(size.width, sublayout.position.x + sublayout.size.width);
|
||||
}
|
||||
}
|
||||
|
||||
if (isnan(size.height)) {
|
||||
size.height = constrainedSize.min.height;
|
||||
for (ASLayout *child in layoutChildren) {
|
||||
size.height = MAX(size.height, child.position.y + child.size.height);
|
||||
for (ASLayout *sublayout in sublayouts) {
|
||||
size.height = MAX(size.height, sublayout.position.y + sublayout.size.height);
|
||||
}
|
||||
}
|
||||
|
||||
return [ASLayout newWithLayoutableObject:self
|
||||
size:ASSizeRangeClamp(constrainedSize, size)
|
||||
children:layoutChildren];
|
||||
sublayouts:sublayouts];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
/** Represents a set of laid out and positioned stack layout children. */
|
||||
struct ASStackPositionedLayout {
|
||||
const std::vector<ASLayout *> children;
|
||||
const std::vector<ASLayout *> sublayouts;
|
||||
const CGFloat crossSize;
|
||||
|
||||
/** Given an unpositioned layout, computes the positions each child should be placed at. */
|
||||
|
||||
Reference in New Issue
Block a user