[Layout] Add helper properties for setting sizes via CGSize and ASRelativeSize (#2324)

* Remove set layout style size helper

* Update API to set and get a CGSize / ASRelativeSize from an ASLayoutElementStyle

- Expose ASRelativeSize type
- Add new helper properties to set a size / relative size to ASLayoutElementStyle
- Don't expose the size in ASLayoutElementStyle anymore and move into ASLayoutElementStylePrivate

* Update examples

* Update comments for size helpers
This commit is contained in:
Michael Schneider
2016-10-04 09:35:45 -07:00
committed by Adlai Holler
parent f027a8be80
commit d6e5e27c39
30 changed files with 288 additions and 143 deletions

View File

@@ -68,6 +68,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, assign, readonly) ASLayoutElementStyle *style;
#pragma mark - Calculate layout
/**
@@ -188,12 +189,8 @@ extern NSString * const ASLayoutElementStyleLayoutPositionProperty;
*/
@property (nullable, nonatomic, weak, readonly) id<ASLayoutElementStyleDelegate> delegate;
#pragma mark - Sizing
/**
* @abstract A size constraint that should apply to this ASLayoutElement.
*/
@property (nonatomic, assign, readwrite) ASLayoutElementSize size;
#pragma mark - Sizing
/**
* @abstract The width property specifies the height of the content area of an ASLayoutElement.
@@ -241,15 +238,68 @@ extern NSString * const ASLayoutElementStyleLayoutPositionProperty;
*/
@property (nonatomic, assign, readwrite) ASDimension maxWidth;
/**
* @abstract Set max and width properties from given size
*/
- (void)setSizeWithCGSize:(CGSize)size;
#pragma mark - ASLayoutElementStyleSizeHelpers
/**
* @abstract Set minHeight, maxHeight and minWidth, maxWidth properties from given size
* @abstract Provides a suggested size for a layout element. If the optional minSize or maxSize are provided,
* and the preferredSize exceeds these, the minSize or maxSize will be enforced. If this optional value is not
* provided, the layout elements size will default to its intrinsic content size provided calculateSizeThatFits:
*
* @discussion This method is optional, but one of either preferredSize or preferredRelativeSize is required
* 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
* set on an ASImageNode to display at a size different from the underlying image size.
*/
- (void)setExactSizeWithCGSize:(CGSize)size;
@property (nonatomic, assign) CGSize preferredSize;
- (CGSize)preferredSize UNAVAILABLE_ATTRIBUTE;
/**
* @abstract An optional property that provides a minimum size bound for a layout element. If provided, this restriction will
* always be enforced. If a parent layout elements minimum size is smaller than its childs minimum size, the childs
* minimum size will be enforced and its size will extend out of the layout specs.
*
* @discussion For example, if you set a preferred relative width of 50% and a minimum width of 200 points on an
* element in a full screen container, this would result in a width of 160 points on an iPhone screen. However,
* since 160 pts is lower than the minimum width of 200 pts, the minimum width would be used.
*/
@property (nonatomic, assign) CGSize minSize;
- (CGSize)minSize UNAVAILABLE_ATTRIBUTE;
/**
* @abstract An optional property that provides a maximum size bound for a layout element. If provided, this restriction will
* always be enforced. If a child layout elements maximum size is smaller than its parent, the childs maximum size will
* be enforced and its size will extend out of the layout specs.
*
* @discussion For example, if you set a preferred relative width of 50% and a maximum width of 120 points on an
* element in a full screen container, this would result in a width of 160 points on an iPhone screen. However,
* since 160 pts is higher than the maximum width of 120 pts, the maximum width would be used.
*/
@property (nonatomic, assign) CGSize maxSize;
- (CGSize)maxSize UNAVAILABLE_ATTRIBUTE;
/**
* @abstract Provides a suggested RELATIVE size for a layout element. An ASRelativeSize uses percentages rather
* than points to specify layout. E.g. width should be 50% of the parents width. If the optional minRelativeSize or
* maxRelativeSize are provided, and the preferredRelativeSize exceeds these, the minRelativeSize or maxRelativeSize
* will be enforced. If this optional value is not provided, the layout elements size will default to its intrinsic content size
* provided calculateSizeThatFits:
*/
@property (nonatomic, assign, readwrite) ASRelativeSize preferredRelativeSize;
/**
* @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 elements minimum relative size is smaller than its childs minimum
* relative size, the childs minimum relative size will be enforced and its size will extend out of the layout specs.
*/
@property (nonatomic, assign, readwrite) ASRelativeSize minRelativeSize;
/**
* @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 elements maximum relative size is smaller than its childs maximum
* relative size, the childs maximum relative size will be enforced and its size will extend out of the layout specs.
*/
@property (nonatomic, assign, readwrite) ASRelativeSize maxRelativeSize;
#pragma mark - ASStackLayoutElement
@@ -303,6 +353,7 @@ extern NSString * const ASLayoutElementStyleLayoutPositionProperty;
*/
@property (nonatomic, assign) CGFloat descender;
#pragma mark - ASAbsoluteLayoutElement
/**