mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-17 03:40:18 +00:00
Rename ASRelativeSize to ASLayoutSize (#2369)
This commit is contained in:
parent
507bc55504
commit
8f8df537d2
@ -172,7 +172,7 @@ ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT CGFloat ASDimensionResolve(ASDimensio
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - ASRelativeSize
|
#pragma mark - ASLayoutSize
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expresses a size with relative dimensions. Only used for calculations internally in ASDimension.h
|
* Expresses a size with relative dimensions. Only used for calculations internally in ASDimension.h
|
||||||
@ -180,14 +180,14 @@ ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT CGFloat ASDimensionResolve(ASDimensio
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
ASDimension width;
|
ASDimension width;
|
||||||
ASDimension height;
|
ASDimension height;
|
||||||
} ASRelativeSize;
|
} ASLayoutSize;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Creates an ASRelativeSize with provided min and max dimensions.
|
* Creates an ASLayoutSize with provided min and max dimensions.
|
||||||
*/
|
*/
|
||||||
ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT ASRelativeSize ASRelativeSizeMake(ASDimension width, ASDimension height)
|
ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT ASLayoutSize ASLayoutSizeMake(ASDimension width, ASDimension height)
|
||||||
{
|
{
|
||||||
ASRelativeSize size;
|
ASLayoutSize size;
|
||||||
size.width = width;
|
size.width = width;
|
||||||
size.height = height;
|
size.height = height;
|
||||||
return size;
|
return size;
|
||||||
@ -196,7 +196,7 @@ ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT ASRelativeSize ASRelativeSizeMake(ASD
|
|||||||
/*
|
/*
|
||||||
* Returns a string representation of a relative size.
|
* Returns a string representation of a relative size.
|
||||||
*/
|
*/
|
||||||
ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT NSString *NSStringFromASRelativeSize(ASRelativeSize size);
|
ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT NSString *NSStringFromASLayoutSize(ASLayoutSize size);
|
||||||
|
|
||||||
#pragma mark - ASSizeRange
|
#pragma mark - ASSizeRange
|
||||||
|
|
||||||
|
|||||||
@ -70,17 +70,17 @@ NSString *NSStringFromASDimension(ASDimension dimension)
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - ASRelativeSize
|
#pragma mark - ASLayoutSize
|
||||||
|
|
||||||
// ** Resolve this relative size relative to a parent size. */
|
// ** Resolve this relative size relative to a parent size. */
|
||||||
ASDISPLAYNODE_INLINE CGSize ASRelativeSizeResolveSize(ASRelativeSize relativeSize, CGSize parentSize, CGSize autoSize)
|
ASDISPLAYNODE_INLINE CGSize ASLayoutSizeResolveSize(ASLayoutSize layoutSize, CGSize parentSize, CGSize autoSize)
|
||||||
{
|
{
|
||||||
return CGSizeMake(ASDimensionResolve(relativeSize.width, parentSize.width, autoSize.width),
|
return CGSizeMake(ASDimensionResolve(layoutSize.width, parentSize.width, autoSize.width),
|
||||||
ASDimensionResolve(relativeSize.height, parentSize.height, autoSize.height));
|
ASDimensionResolve(layoutSize.height, parentSize.height, autoSize.height));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ** Returns a string formatted to contain the data from an ASRelativeSize. */
|
// ** Returns a string formatted to contain the data from an ASLayoutSize. */
|
||||||
ASDISPLAYNODE_INLINE NSString *NSStringFromASRelativeSize(ASRelativeSize size)
|
ASDISPLAYNODE_INLINE NSString *NSStringFromASLayoutSize(ASLayoutSize size)
|
||||||
{
|
{
|
||||||
return [NSString stringWithFormat:@"{%@, %@}",
|
return [NSString stringWithFormat:@"{%@, %@}",
|
||||||
NSStringFromASDimension(size.width),
|
NSStringFromASDimension(size.width),
|
||||||
@ -94,9 +94,9 @@ NSString *NSStringFromASLayoutElementSize(ASLayoutElementSize size)
|
|||||||
{
|
{
|
||||||
return [NSString stringWithFormat:
|
return [NSString stringWithFormat:
|
||||||
@"<ASLayoutElementSize: exact=%@, min=%@, max=%@>",
|
@"<ASLayoutElementSize: exact=%@, min=%@, max=%@>",
|
||||||
NSStringFromASRelativeSize(ASRelativeSizeMake(size.width, size.height)),
|
NSStringFromASLayoutSize(ASLayoutSizeMake(size.width, size.height)),
|
||||||
NSStringFromASRelativeSize(ASRelativeSizeMake(size.minWidth, size.minHeight)),
|
NSStringFromASLayoutSize(ASLayoutSizeMake(size.minWidth, size.minHeight)),
|
||||||
NSStringFromASRelativeSize(ASRelativeSizeMake(size.maxWidth, size.maxHeight))];
|
NSStringFromASLayoutSize(ASLayoutSizeMake(size.maxWidth, size.maxHeight))];
|
||||||
}
|
}
|
||||||
|
|
||||||
ASDISPLAYNODE_INLINE void ASLayoutElementSizeConstrain(CGFloat minVal, CGFloat exactVal, CGFloat maxVal, CGFloat *outMin, CGFloat *outMax)
|
ASDISPLAYNODE_INLINE void ASLayoutElementSizeConstrain(CGFloat minVal, CGFloat exactVal, CGFloat maxVal, CGFloat *outMin, CGFloat *outMax)
|
||||||
@ -133,9 +133,9 @@ ASDISPLAYNODE_INLINE void ASLayoutElementSizeConstrain(CGFloat minVal, CGFloat e
|
|||||||
|
|
||||||
ASSizeRange ASLayoutElementSizeResolveAutoSize(ASLayoutElementSize size, const CGSize parentSize, ASSizeRange autoASSizeRange)
|
ASSizeRange ASLayoutElementSizeResolveAutoSize(ASLayoutElementSize size, const CGSize parentSize, ASSizeRange autoASSizeRange)
|
||||||
{
|
{
|
||||||
CGSize resolvedExact = ASRelativeSizeResolveSize(ASRelativeSizeMake(size.width, size.height), parentSize, {NAN, NAN});
|
CGSize resolvedExact = ASLayoutSizeResolveSize(ASLayoutSizeMake(size.width, size.height), parentSize, {NAN, NAN});
|
||||||
CGSize resolvedMin = ASRelativeSizeResolveSize(ASRelativeSizeMake(size.minWidth, size.minHeight), parentSize, autoASSizeRange.min);
|
CGSize resolvedMin = ASLayoutSizeResolveSize(ASLayoutSizeMake(size.minWidth, size.minHeight), parentSize, autoASSizeRange.min);
|
||||||
CGSize resolvedMax = ASRelativeSizeResolveSize(ASRelativeSizeMake(size.maxWidth, size.maxHeight), parentSize, autoASSizeRange.max);
|
CGSize resolvedMax = ASLayoutSizeResolveSize(ASLayoutSizeMake(size.maxWidth, size.maxHeight), parentSize, autoASSizeRange.max);
|
||||||
|
|
||||||
CGSize rangeMin, rangeMax;
|
CGSize rangeMin, rangeMax;
|
||||||
ASLayoutElementSizeConstrain(resolvedMin.width, resolvedExact.width, resolvedMax.width, &rangeMin.width, &rangeMax.width);
|
ASLayoutElementSizeConstrain(resolvedMin.width, resolvedExact.width, resolvedMax.width, &rangeMin.width, &rangeMax.width);
|
||||||
|
|||||||
@ -247,7 +247,7 @@ extern NSString * const ASLayoutElementStyleLayoutPositionProperty;
|
|||||||
* and the preferredSize exceeds these, the minSize or maxSize will be enforced. If this optional value is not
|
* and the preferredSize exceeds these, the minSize or maxSize will be enforced. If this optional value is not
|
||||||
* provided, the layout element’s size will default to it’s intrinsic content size provided calculateSizeThatFits:
|
* provided, the layout element’s size will default to it’s intrinsic content size provided calculateSizeThatFits:
|
||||||
*
|
*
|
||||||
* @discussion This method is optional, but one of either preferredSize or preferredRelativeSize is required
|
* @discussion This method is optional, but one of either preferredSize or preferredLayoutSize is required
|
||||||
* for nodes that either have no intrinsic content size or
|
* for nodes that either have no intrinsic content size or
|
||||||
* should be laid out at a different size than its intrinsic content size. For example, this property could be
|
* should be laid out at a different size than its intrinsic content size. For example, this property could be
|
||||||
* set on an ASImageNode to display at a size different from the underlying image size.
|
* set on an ASImageNode to display at a size different from the underlying image size.
|
||||||
@ -280,27 +280,27 @@ extern NSString * const ASLayoutElementStyleLayoutPositionProperty;
|
|||||||
- (CGSize)maxSize UNAVAILABLE_ATTRIBUTE;
|
- (CGSize)maxSize UNAVAILABLE_ATTRIBUTE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @abstract Provides a suggested RELATIVE size for a layout element. An ASRelativeSize uses percentages rather
|
* @abstract Provides a suggested RELATIVE size for a layout element. An ASLayoutSize uses percentages rather
|
||||||
* than points to specify layout. E.g. width should be 50% of the parent’s width. If the optional minRelativeSize or
|
* than points to specify layout. E.g. width should be 50% of the parent’s width. If the optional minLayoutSize or
|
||||||
* maxRelativeSize are provided, and the preferredRelativeSize exceeds these, the minRelativeSize or maxRelativeSize
|
* maxLayoutSize are provided, and the preferredLayoutSize exceeds these, the minLayoutSize or maxLayoutSize
|
||||||
* will be enforced. If this optional value is not provided, the layout element’s size will default to its intrinsic content size
|
* will be enforced. If this optional value is not provided, the layout element’s size will default to its intrinsic content size
|
||||||
* provided calculateSizeThatFits:
|
* provided calculateSizeThatFits:
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, assign, readwrite) ASRelativeSize preferredRelativeSize;
|
@property (nonatomic, assign, readwrite) ASLayoutSize preferredLayoutSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @abstract An optional property that provides a minimum RELATIVE size bound for a layout element. If provided, this
|
* @abstract An optional property that provides a minimum RELATIVE size bound for a layout element. If provided, this
|
||||||
* restriction will always be enforced. If a parent layout element’s minimum relative size is smaller than its child’s minimum
|
* restriction will always be enforced. If a parent layout element’s minimum relative size is smaller than its child’s minimum
|
||||||
* relative size, the child’s minimum relative size will be enforced and its size will extend out of the layout spec’s.
|
* relative size, the child’s minimum relative size will be enforced and its size will extend out of the layout spec’s.
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, assign, readwrite) ASRelativeSize minRelativeSize;
|
@property (nonatomic, assign, readwrite) ASLayoutSize minLayoutSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @abstract An optional property that provides a maximum RELATIVE size bound for a layout element. If provided, this
|
* @abstract An optional property that provides a maximum RELATIVE size bound for a layout element. If provided, this
|
||||||
* restriction will always be enforced. If a parent layout element’s maximum relative size is smaller than its child’s maximum
|
* restriction will always be enforced. If a parent layout element’s maximum relative size is smaller than its child’s maximum
|
||||||
* relative size, the child’s maximum relative size will be enforced and its size will extend out of the layout spec’s.
|
* relative size, the child’s maximum relative size will be enforced and its size will extend out of the layout spec’s.
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, assign, readwrite) ASRelativeSize maxRelativeSize;
|
@property (nonatomic, assign, readwrite) ASLayoutSize maxLayoutSize;
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - ASStackLayoutElement
|
#pragma mark - ASStackLayoutElement
|
||||||
|
|||||||
@ -113,7 +113,7 @@ do {\
|
|||||||
}
|
}
|
||||||
|
|
||||||
@dynamic width, height, minWidth, maxWidth, minHeight, maxHeight;
|
@dynamic width, height, minWidth, maxWidth, minHeight, maxHeight;
|
||||||
@dynamic preferredSize, minSize, maxSize, preferredRelativeSize, minRelativeSize, maxRelativeSize;
|
@dynamic preferredSize, minSize, maxSize, preferredLayoutSize, minLayoutSize, maxLayoutSize;
|
||||||
|
|
||||||
#pragma mark - Lifecycle
|
#pragma mark - Lifecycle
|
||||||
|
|
||||||
@ -250,40 +250,40 @@ do {\
|
|||||||
self.maxHeight = ASDimensionMakeWithPoints(maxSize.height);
|
self.maxHeight = ASDimensionMakeWithPoints(maxSize.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (ASRelativeSize)preferredRelativeSize
|
- (ASLayoutSize)preferredLayoutSize
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(__instanceLock__);
|
ASDN::MutexLocker l(__instanceLock__);
|
||||||
return ASRelativeSizeMake(_size.width, _size.height);
|
return ASLayoutSizeMake(_size.width, _size.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setPreferredRelativeSize:(ASRelativeSize)preferredRelativeSize
|
- (void)setPreferredLayoutSize:(ASLayoutSize)preferredLayoutSize
|
||||||
{
|
{
|
||||||
self.width = preferredRelativeSize.width;
|
self.width = preferredLayoutSize.width;
|
||||||
self.height = preferredRelativeSize.height;
|
self.height = preferredLayoutSize.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (ASRelativeSize)minRelativeSize
|
- (ASLayoutSize)minLayoutSize
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(__instanceLock__);
|
ASDN::MutexLocker l(__instanceLock__);
|
||||||
return ASRelativeSizeMake(_size.minWidth, _size.minHeight);
|
return ASLayoutSizeMake(_size.minWidth, _size.minHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setMinRelativeSize:(ASRelativeSize)minRelativeSize
|
- (void)setMinLayoutSize:(ASLayoutSize)minLayoutSize
|
||||||
{
|
{
|
||||||
self.minWidth = minRelativeSize.width;
|
self.minWidth = minLayoutSize.width;
|
||||||
self.minHeight = minRelativeSize.height;
|
self.minHeight = minLayoutSize.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (ASRelativeSize)maxRelativeSize
|
- (ASLayoutSize)maxLayoutSize
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker l(__instanceLock__);
|
ASDN::MutexLocker l(__instanceLock__);
|
||||||
return ASRelativeSizeMake(_size.maxWidth, _size.maxHeight);
|
return ASLayoutSizeMake(_size.maxWidth, _size.maxHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setMaxRelativeSize:(ASRelativeSize)maxRelativeSize
|
- (void)setMaxLayoutSize:(ASLayoutSize)maxLayoutSize
|
||||||
{
|
{
|
||||||
self.maxWidth = maxRelativeSize.width;
|
self.maxWidth = maxLayoutSize.width;
|
||||||
self.maxHeight = maxRelativeSize.height;
|
self.maxHeight = maxLayoutSize.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -73,29 +73,29 @@
|
|||||||
XCTAssertTrue(ASDimensionEqualToDimension(style.maxHeight, ASDimensionMakeWithPoints(size.height)));
|
XCTAssertTrue(ASDimensionEqualToDimension(style.maxHeight, ASDimensionMakeWithPoints(size.height)));
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setSettingSizeViaRelativeSize
|
- (void)setSettingSizeViaLayoutSize
|
||||||
{
|
{
|
||||||
ASLayoutElementStyle *style = [ASLayoutElementStyle new];
|
ASLayoutElementStyle *style = [ASLayoutElementStyle new];
|
||||||
|
|
||||||
ASRelativeSize relativeSize = ASRelativeSizeMake(ASDimensionMake(100), ASDimensionMake(100));
|
ASLayoutSize layoutSize = ASLayoutSizeMake(ASDimensionMake(100), ASDimensionMake(100));
|
||||||
|
|
||||||
style.preferredRelativeSize = relativeSize;
|
style.preferredLayoutSize = layoutSize;
|
||||||
XCTAssertTrue(ASDimensionEqualToDimension(style.width, relativeSize.width));
|
XCTAssertTrue(ASDimensionEqualToDimension(style.width, layoutSize.width));
|
||||||
XCTAssertTrue(ASDimensionEqualToDimension(style.height, relativeSize.height));
|
XCTAssertTrue(ASDimensionEqualToDimension(style.height, layoutSize.height));
|
||||||
XCTAssertTrue(ASDimensionEqualToDimension(style.preferredRelativeSize.width, relativeSize.width));
|
XCTAssertTrue(ASDimensionEqualToDimension(style.preferredLayoutSize.width, layoutSize.width));
|
||||||
XCTAssertTrue(ASDimensionEqualToDimension(style.preferredRelativeSize.height, relativeSize.height));
|
XCTAssertTrue(ASDimensionEqualToDimension(style.preferredLayoutSize.height, layoutSize.height));
|
||||||
|
|
||||||
style.minRelativeSize = relativeSize;
|
style.minLayoutSize = layoutSize;
|
||||||
XCTAssertTrue(ASDimensionEqualToDimension(style.minWidth, relativeSize.width));
|
XCTAssertTrue(ASDimensionEqualToDimension(style.minWidth, layoutSize.width));
|
||||||
XCTAssertTrue(ASDimensionEqualToDimension(style.minHeight, relativeSize.height));
|
XCTAssertTrue(ASDimensionEqualToDimension(style.minHeight, layoutSize.height));
|
||||||
XCTAssertTrue(ASDimensionEqualToDimension(style.minRelativeSize.width, relativeSize.width));
|
XCTAssertTrue(ASDimensionEqualToDimension(style.minLayoutSize.width, layoutSize.width));
|
||||||
XCTAssertTrue(ASDimensionEqualToDimension(style.minRelativeSize.height, relativeSize.height));
|
XCTAssertTrue(ASDimensionEqualToDimension(style.minLayoutSize.height, layoutSize.height));
|
||||||
|
|
||||||
style.maxRelativeSize = relativeSize;
|
style.maxLayoutSize = layoutSize;
|
||||||
XCTAssertTrue(ASDimensionEqualToDimension(style.maxWidth, relativeSize.width));
|
XCTAssertTrue(ASDimensionEqualToDimension(style.maxWidth, layoutSize.width));
|
||||||
XCTAssertTrue(ASDimensionEqualToDimension(style.maxHeight, relativeSize.height));
|
XCTAssertTrue(ASDimensionEqualToDimension(style.maxHeight, layoutSize.height));
|
||||||
XCTAssertTrue(ASDimensionEqualToDimension(style.maxRelativeSize.width, relativeSize.width));
|
XCTAssertTrue(ASDimensionEqualToDimension(style.maxLayoutSize.width, layoutSize.width));
|
||||||
XCTAssertTrue(ASDimensionEqualToDimension(style.maxRelativeSize.height, relativeSize.height));
|
XCTAssertTrue(ASDimensionEqualToDimension(style.maxLayoutSize.height, layoutSize.height));
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)testSettingPropertiesWillCallDelegate
|
- (void)testSettingPropertiesWillCallDelegate
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user