1313#import < AsyncDisplayKit/ASBaseDefines.h>
1414#import < AsyncDisplayKit/ASAssert.h>
1515
16+ ASDISPLAYNODE_EXTERN_C_BEGIN
17+ NS_ASSUME_NONNULL_BEGIN
18+
19+ #pragma mark -
20+
1621ASDISPLAYNODE_INLINE BOOL AS_WARN_UNUSED_RESULT ASPointsValidForLayout (CGFloat points)
1722{
1823 return ((isnormal (points) || points == 0.0 ) && points >= 0.0 && points < (CGFLOAT_MAX / 2.0 ));
@@ -33,6 +38,8 @@ ASDISPLAYNODE_INLINE BOOL AS_WARN_UNUSED_RESULT ASIsCGSizeValidForSize(CGSize si
3338 return (ASPointsValidForSize (size.width ) && ASPointsValidForSize (size.height ));
3439}
3540
41+ #pragma mark - ASDimension
42+
3643/* *
3744 * A dimension relative to constraints to be provided in the future.
3845 * A ASDimension can be one of three types:
@@ -58,42 +65,10 @@ typedef struct {
5865} ASDimension;
5966
6067/* *
61- * Expresses an inclusive range of sizes. Used to provide a simple constraint to layout.
68+ * Represents auto as ASDimension
6269 */
63- typedef struct {
64- CGSize min;
65- CGSize max;
66- } ASSizeRange;
67-
68- /* *
69- * A struct specifying a ASLayoutElement's size. Example:
70- *
71- * ASLayoutElementSize size = (ASLayoutElementSize){
72- * .width = ASDimensionMakeWithFraction(0.25),
73- * .maxWidth = ASDimensionMakeWithPoints(200),
74- * .minHeight = ASDimensionMakeWithFraction(0.50)
75- * };
76- *
77- * Description: <ASLayoutElementSize: exact={25%, Auto}, min={Auto, 50%}, max={200pt, Auto}>
78- *
79- */
80- typedef struct {
81- ASDimension width;
82- ASDimension height;
83- ASDimension minWidth;
84- ASDimension maxWidth;
85- ASDimension minHeight;
86- ASDimension maxHeight;
87- } ASLayoutElementSize;
88-
8970extern ASDimension const ASDimensionAuto;
9071
91- ASDISPLAYNODE_EXTERN_C_BEGIN
92- NS_ASSUME_NONNULL_BEGIN
93-
94-
95- #pragma mark - ASDimension
96-
9772/* *
9873 * Returns a dimension with the specified type and value.
9974 */
@@ -173,15 +148,6 @@ ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT CGFloat ASDimensionResolve(ASDimensio
173148 }
174149}
175150
176-
177- #pragma mark - NSNumber+ASDimension
178-
179- @interface NSNumber (ASDimension)
180- @property (nonatomic , readonly ) ASDimension as_pointDimension;
181- @property (nonatomic , readonly ) ASDimension as_fractionDimension;
182- @end
183-
184-
185151#pragma mark - ASLayoutSize
186152
187153/* *
@@ -205,6 +171,15 @@ ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT ASLayoutSize ASLayoutSizeMake(ASDimen
205171 return size;
206172}
207173
174+ /* *
175+ * Resolve this relative size relative to a parent size.
176+ */
177+ ASDISPLAYNODE_INLINE CGSize ASLayoutSizeResolveSize (ASLayoutSize layoutSize, CGSize parentSize, CGSize autoSize)
178+ {
179+ return CGSizeMake (ASDimensionResolve (layoutSize.width , parentSize.width , autoSize.width ),
180+ ASDimensionResolve (layoutSize.height , parentSize.height , autoSize.height ));
181+ }
182+
208183/*
209184 * Returns a string representation of a relative size.
210185 */
@@ -217,6 +192,14 @@ ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT NSString *NSStringFromASLayoutSize(AS
217192
218193#pragma mark - ASSizeRange
219194
195+ /* *
196+ * Expresses an inclusive range of sizes. Used to provide a simple constraint to layout.
197+ */
198+ typedef struct {
199+ CGSize min;
200+ CGSize max;
201+ } ASSizeRange;
202+
220203/* *
221204 * Creates an ASSizeRange with provided min and max size.
222205 */
@@ -272,149 +255,5 @@ ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT BOOL ASSizeRangeEqualToSizeRange(ASSi
272255 */
273256extern AS_WARN_UNUSED_RESULT NSString *NSStringFromASSizeRange (ASSizeRange sizeRange);
274257
275-
276- #pragma mark - ASLayoutElementSize
277-
278- /* *
279- * Returns an ASLayoutElementSize with default values.
280- */
281- ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT ASLayoutElementSize ASLayoutElementSizeMake ()
282- {
283- return (ASLayoutElementSize){
284- .width = ASDimensionAuto,
285- .height = ASDimensionAuto,
286- .minWidth = ASDimensionAuto,
287- .maxWidth = ASDimensionAuto,
288- .minHeight = ASDimensionAuto,
289- .maxHeight = ASDimensionAuto
290- };
291- }
292-
293- /* *
294- * Returns an ASLayoutElementSize with the specified CGSize values as width and height.
295- */
296- ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT ASLayoutElementSize ASLayoutElementSizeMakeFromCGSize (CGSize size)
297- {
298- ASLayoutElementSize s = ASLayoutElementSizeMake ();
299- s.width = ASDimensionMakeWithPoints (size.width );
300- s.height = ASDimensionMakeWithPoints (size.height );
301- return s;
302- }
303-
304- /* *
305- * Returns whether two sizes are equal.
306- */
307- ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT BOOL ASLayoutElementSizeEqualToLayoutElementSize (ASLayoutElementSize lhs, ASLayoutElementSize rhs)
308- {
309- return (ASDimensionEqualToDimension (lhs.width , rhs.width )
310- && ASDimensionEqualToDimension (lhs.height , rhs.height )
311- && ASDimensionEqualToDimension (lhs.minWidth , rhs.minWidth )
312- && ASDimensionEqualToDimension (lhs.maxWidth , rhs.maxWidth )
313- && ASDimensionEqualToDimension (lhs.minHeight , rhs.minHeight )
314- && ASDimensionEqualToDimension (lhs.maxHeight , rhs.maxHeight ));
315- }
316-
317- /* *
318- * Returns a string formatted to contain the data from an ASLayoutElementSize.
319- */
320- extern AS_WARN_UNUSED_RESULT NSString *NSStringFromASLayoutElementSize (ASLayoutElementSize size);
321-
322- /* *
323- * Resolve the given size relative to a parent size and an auto size.
324- * From the given size uses width, height to resolve the exact size constraint, uses the minHeight and minWidth to
325- * resolve the min size constraint and the maxHeight and maxWidth to resolve the max size constraint. For every
326- * dimension with unit ASDimensionUnitAuto the given autoASSizeRange value will be used.
327- * Based on the calculated exact, min and max size constraints the final size range will be calculated.
328- */
329- extern AS_WARN_UNUSED_RESULT ASSizeRange ASLayoutElementSizeResolveAutoSize (ASLayoutElementSize size, const CGSize parentSize, ASSizeRange autoASSizeRange);
330-
331- /* *
332- * Resolve the given size to a parent size. Uses internally ASLayoutElementSizeResolveAutoSize with {INFINITY, INFINITY} as
333- * as autoASSizeRange. For more information look at ASLayoutElementSizeResolveAutoSize.
334- */
335- ASDISPLAYNODE_INLINE AS_WARN_UNUSED_RESULT ASSizeRange ASLayoutElementSizeResolve (ASLayoutElementSize size, const CGSize parentSize)
336- {
337- return ASLayoutElementSizeResolveAutoSize (size, parentSize, ASSizeRangeMake (CGSizeZero, CGSizeMake (INFINITY, INFINITY)));
338- }
339-
340-
341- #pragma mark - Deprecated
342-
343- /* *
344- * A dimension relative to constraints to be provided in the future.
345- * A ASDimension can be one of three types:
346- *
347- * "Auto" - This indicated "I have no opinion" and may be resolved in whatever way makes most sense given the circumstances.
348- *
349- * "Points" - Just a number. It will always resolve to exactly this amount.
350- *
351- * "Percent" - Multiplied to a provided parent amount to resolve a final amount.
352- */
353- typedef NS_ENUM (NSInteger , ASRelativeDimensionType) {
354- /* * This indicates "I have no opinion" and may be resolved in whatever way makes most sense given the circumstances. */
355- ASRelativeDimensionTypeAuto,
356- /* * Just a number. It will always resolve to exactly this amount. This is the default type. */
357- ASRelativeDimensionTypePoints,
358- /* * Multiplied to a provided parent amount to resolve a final amount. */
359- ASRelativeDimensionTypeFraction,
360- };
361-
362- #define ASRelativeDimension ASDimension
363- #define ASRelativeSize ASLayoutSize
364- #define ASRelativeDimensionMakeWithPoints ASDimensionMakeWithPoints
365- #define ASRelativeDimensionMakeWithFraction ASDimensionMakeWithFraction
366-
367- /* *
368- * Function is deprecated. Use ASSizeRangeMake instead.
369- */
370- extern AS_WARN_UNUSED_RESULT ASSizeRange ASSizeRangeMakeExactSize (CGSize size) ASDISPLAYNODE_DEPRECATED_MSG(" Use ASSizeRangeMake instead." );
371-
372- /* *
373- Expresses an inclusive range of relative sizes. Used to provide additional constraint to layout.
374- Used by ASStaticLayoutSpec.
375- */
376- typedef struct {
377- ASLayoutSize min;
378- ASLayoutSize max;
379- } ASRelativeSizeRange;
380-
381- extern ASRelativeSizeRange const ASRelativeSizeRangeUnconstrained;
382-
383- #pragma mark - ASRelativeDimension
384-
385- extern ASDimension ASRelativeDimensionMake (ASRelativeDimensionType type, CGFloat value) ASDISPLAYNODE_DEPRECATED;
386-
387- #pragma mark - ASRelativeSize
388-
389- extern ASLayoutSize ASRelativeSizeMake (ASRelativeDimension width, ASRelativeDimension height) ASDISPLAYNODE_DEPRECATED;
390-
391- /* * Convenience constructor to provide size in points. */
392- extern ASLayoutSize ASRelativeSizeMakeWithCGSize (CGSize size) ASDISPLAYNODE_DEPRECATED;
393-
394- /* * Convenience constructor to provide size as a fraction. */
395- extern ASLayoutSize ASRelativeSizeMakeWithFraction (CGFloat fraction) ASDISPLAYNODE_DEPRECATED;
396-
397- extern BOOL ASRelativeSizeEqualToRelativeSize (ASLayoutSize lhs, ASLayoutSize rhs) ASDISPLAYNODE_DEPRECATED;
398-
399- extern NSString *NSStringFromASRelativeSize (ASLayoutSize size) ASDISPLAYNODE_DEPRECATED;
400-
401- #pragma mark - ASRelativeSizeRange
402-
403- extern ASRelativeSizeRange ASRelativeSizeRangeMake (ASLayoutSize min, ASLayoutSize max) ASDISPLAYNODE_DEPRECATED;
404-
405- #pragma mark Convenience constructors to provide an exact size (min == max).
406- extern ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactRelativeSize (ASLayoutSize exact) ASDISPLAYNODE_DEPRECATED;
407-
408- extern ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactCGSize (CGSize exact) ASDISPLAYNODE_DEPRECATED;
409-
410- extern ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactFraction (CGFloat fraction) ASDISPLAYNODE_DEPRECATED;
411-
412- extern ASRelativeSizeRange ASRelativeSizeRangeMakeWithExactRelativeDimensions (ASRelativeDimension exactWidth, ASRelativeDimension exactHeight) ASDISPLAYNODE_DEPRECATED;
413-
414- extern BOOL ASRelativeSizeRangeEqualToRelativeSizeRange (ASRelativeSizeRange lhs, ASRelativeSizeRange rhs) ASDISPLAYNODE_DEPRECATED;
415-
416- /* * Provided a parent size, compute final dimensions for this RelativeSizeRange to arrive at a SizeRange. */
417- extern ASSizeRange ASRelativeSizeRangeResolve (ASRelativeSizeRange relativeSizeRange, CGSize parentSize) ASDISPLAYNODE_DEPRECATED;
418-
419258NS_ASSUME_NONNULL_END
420259ASDISPLAYNODE_EXTERN_C_END
0 commit comments