transformed style values into properties and removed enums that were implementation details

This commit is contained in:
David Hart
2016-12-18 21:53:53 +01:00
parent 45b7ec95dc
commit 4be38891d8
6 changed files with 148 additions and 68 deletions

View File

@@ -15,44 +15,47 @@
/** /**
The property that decides if we should include this view when calculating layout. Defaults to YES. The property that decides if we should include this view when calculating layout. Defaults to YES.
*/ */
@property (nonatomic, readwrite, assign, setter=yk_setIncludeInLayout:) BOOL yk_includeInLayout; @property (nonatomic, setter=yk_setIncludeInLayout:) BOOL yk_includeInLayout;
/** /**
The property that decides during layout/sizing whether or not yk_* properties should be applied. Defaults to NO. The property that decides during layout/sizing whether or not yk_* properties should be applied. Defaults to NO.
*/ */
@property (nonatomic, readwrite, assign, setter=yk_setUsesYoga:) BOOL yk_usesYoga; @property (nonatomic, setter=yk_setUsesYoga:) BOOL yk_usesYoga;
- (void)yk_setDirection:(YKDirection)direction; @property (nonatomic, setter=yk_setDirection:) YKDirection yk_direction;
- (void)yk_setFlexDirection:(YKFlexDirection)flexDirection; @property (nonatomic, setter=yk_setFlexDirection:) YKFlexDirection yk_flexDirection;
- (void)yk_setJustifyContent:(YKJustify)justifyContent; @property (nonatomic, setter=yk_setJustifyContent:) YKJustify yk_justifyContent;
- (void)yk_setAlignContent:(YKAlign)alignContent; @property (nonatomic, setter=yk_setAlignContent:) YKAlign yk_alignContent;
- (void)yk_setAlignItems:(YKAlign)alignItems; @property (nonatomic, setter=yk_setAlignItems:) YKAlign yk_alignItems;
- (void)yk_setAlignSelf:(YKAlign)alignSelf; @property (nonatomic, setter=yk_setAlignSelf:) YKAlign yk_alignSelf;
- (void)yk_setPositionType:(YKPositionType)positionType; @property (nonatomic, setter=yk_setPositionType:) YKPositionType yk_positionType;
- (void)yk_setFlexWrap:(YKWrap)flexWrap; @property (nonatomic, setter=yk_setFlexWrap:) YKWrap yk_flexWrap;
- (void)yk_setFlexGrow:(CGFloat)flexGrow; @property (nonatomic, setter=yk_setFlexGrow:) CGFloat yk_flexGrow;
- (void)yk_setFlexShrink:(CGFloat)flexShrink; @property (nonatomic, setter=yk_setFlexShrink:) CGFloat yk_flexShrink;
- (void)yk_setFlexBasis:(CGFloat)flexBasis; @property (nonatomic, setter=yk_setFlexBasis:) CGFloat yk_flexBasis;
- (void)yk_positionForEdge:(YKEdge)edge;
- (void)yk_setPosition:(CGFloat)position forEdge:(YKEdge)edge; - (void)yk_setPosition:(CGFloat)position forEdge:(YKEdge)edge;
- (void)yk_marginForEdge:(YKEdge)edge;
- (void)yk_setMargin:(CGFloat)margin forEdge:(YKEdge)edge; - (void)yk_setMargin:(CGFloat)margin forEdge:(YKEdge)edge;
- (void)yk_paddingForEdge:(YKEdge)edge;
- (void)yk_setPadding:(CGFloat)padding forEdge:(YKEdge)edge; - (void)yk_setPadding:(CGFloat)padding forEdge:(YKEdge)edge;
- (void)yk_setWidth:(CGFloat)width; @property (nonatomic, setter=yk_setWidth:) CGFloat yk_width;
- (void)yk_setHeight:(CGFloat)height; @property (nonatomic, setter=yk_setHeight:) CGFloat yk_height;
- (void)yk_setMinWidth:(CGFloat)minWidth; @property (nonatomic, setter=yk_setMinWidth:) CGFloat yk_minWidth;
- (void)yk_setMinHeight:(CGFloat)minHeight; @property (nonatomic, setter=yk_setMinHeight:) CGFloat yk_minHeight;
- (void)yk_setMaxWidth:(CGFloat)maxWidth; @property (nonatomic, setter=yk_setMaxWidth:) CGFloat yk_maxWidth;
- (void)yk_setMaxHeight:(CGFloat)maxHeight; @property (nonatomic, setter=yk_setMaxHeight:) CGFloat yk_maxHeight;
// Yoga specific properties, not compatible with flexbox specification // Yoga specific properties, not compatible with flexbox specification
- (void)yk_setAspectRatio:(CGFloat)aspectRatio; @property (nonatomic, setter=yk_setAspectRatio:) CGFloat yk_aspectRatio;
/** /**
Get the resolved direction of this node. This won't be YGDirectionInherit Get the resolved direction of this node. This won't be YGDirectionInherit
*/ */
- (YKDirection)yk_resolvedDirection; @property (nonatomic, readonly) CGFloat yk_resolvedDirection;
/** /**
Perform a layout calculation and update the frames of the views in the hierarchy with the results Perform a layout calculation and update the frames of the views in the hierarchy with the results
@@ -62,11 +65,11 @@
/** /**
Returns the size of the view if no constraints were given. This could equivalent to calling [self sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)]; Returns the size of the view if no constraints were given. This could equivalent to calling [self sizeThatFits:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)];
*/ */
- (CGSize)yk_intrinsicSize; @property (nonatomic, readonly) CGSize yk_intrinsicSize;
/** /**
Returns the number of children that are using Flexbox. Returns the number of children that are using Flexbox.
*/ */
- (NSUInteger)yk_numberOfChildren; @property (nonatomic, readonly) NSUInteger yk_numberOfChildren;
@end @end

View File

@@ -76,106 +76,211 @@
OBJC_ASSOCIATION_RETAIN_NONATOMIC); OBJC_ASSOCIATION_RETAIN_NONATOMIC);
} }
- (YKDirection)yk_direction
{
return (YKDirection)YGNodeStyleGetDirection([self ygNode]);
}
- (void)yk_setDirection:(YKDirection)direction - (void)yk_setDirection:(YKDirection)direction
{ {
YGNodeStyleSetDirection([self ygNode], (YGDirection)direction); YGNodeStyleSetDirection([self ygNode], (YGDirection)direction);
} }
- (YKFlexDirection)yk_flexDirection
{
return (YKFlexDirection)YGNodeStyleGetFlexDirection([self ygNode]);
}
- (void)yk_setFlexDirection:(YKFlexDirection)flexDirection - (void)yk_setFlexDirection:(YKFlexDirection)flexDirection
{ {
YGNodeStyleSetFlexDirection([self ygNode], (YGFlexDirection)flexDirection); YGNodeStyleSetFlexDirection([self ygNode], (YGFlexDirection)flexDirection);
} }
- (YKJustify)yk_justifyContent
{
return (YKJustify)YGNodeStyleGetJustifyContent([self ygNode]);
}
- (void)yk_setJustifyContent:(YKJustify)justifyContent - (void)yk_setJustifyContent:(YKJustify)justifyContent
{ {
YGNodeStyleSetJustifyContent([self ygNode], (YGJustify)justifyContent); YGNodeStyleSetJustifyContent([self ygNode], (YGJustify)justifyContent);
} }
- (YKAlign)yk_alignContent
{
return (YKAlign)YGNodeStyleGetAlignContent([self ygNode]);
}
- (void)yk_setAlignContent:(YKAlign)alignContent - (void)yk_setAlignContent:(YKAlign)alignContent
{ {
YGNodeStyleSetAlignContent([self ygNode], (YGAlign)alignContent); YGNodeStyleSetAlignContent([self ygNode], (YGAlign)alignContent);
} }
- (YKAlign)yk_alignItems
{
return (YKAlign)YGNodeStyleGetAlignItems([self ygNode]);
}
- (void)yk_setAlignItems:(YKAlign)alignItems - (void)yk_setAlignItems:(YKAlign)alignItems
{ {
YGNodeStyleSetAlignItems([self ygNode], (YGAlign)alignItems); YGNodeStyleSetAlignItems([self ygNode], (YGAlign)alignItems);
} }
- (YKAlign)yk_alignSelf
{
return (YKAlign)YGNodeStyleGetAlignSelf([self ygNode]);
}
- (void)yk_setAlignSelf:(YKAlign)alignSelf - (void)yk_setAlignSelf:(YKAlign)alignSelf
{ {
YGNodeStyleSetAlignSelf([self ygNode], (YGAlign)alignSelf); YGNodeStyleSetAlignSelf([self ygNode], (YGAlign)alignSelf);
} }
- (YKPositionType)yk_positionType
{
return (YKPositionType)YGNodeStyleGetPositionType([self ygNode]);
}
- (void)yk_setPositionType:(YKPositionType)positionType - (void)yk_setPositionType:(YKPositionType)positionType
{ {
YGNodeStyleSetPositionType([self ygNode], (YGPositionType)positionType); YGNodeStyleSetPositionType([self ygNode], (YGPositionType)positionType);
} }
- (YKWrap)yk_flexWrap
{
return (YKWrap)YGNodeStyleGetFlexWrap([self ygNode]);
}
- (void)yk_setFlexWrap:(YKWrap)flexWrap - (void)yk_setFlexWrap:(YKWrap)flexWrap
{ {
YGNodeStyleSetFlexWrap([self ygNode], (YGWrap)flexWrap); YGNodeStyleSetFlexWrap([self ygNode], (YGWrap)flexWrap);
} }
- (CGFloat)yk_flexGrow
{
return YGNodeStyleGetFlexGrow([self ygNode]);
}
- (void)yk_setFlexGrow:(CGFloat)flexGrow - (void)yk_setFlexGrow:(CGFloat)flexGrow
{ {
YGNodeStyleSetFlexGrow([self ygNode], flexGrow); YGNodeStyleSetFlexGrow([self ygNode], flexGrow);
} }
- (CGFloat)yk_flexShrink
{
return YGNodeStyleGetFlexShrink([self ygNode]);
}
- (void)yk_setFlexShrink:(CGFloat)flexShrink - (void)yk_setFlexShrink:(CGFloat)flexShrink
{ {
YGNodeStyleSetFlexShrink([self ygNode], flexShrink); YGNodeStyleSetFlexShrink([self ygNode], flexShrink);
} }
- (CGFloat)yk_flexBasis
{
return YGNodeStyleGetFlexBasis([self ygNode]);
}
- (void)yk_setFlexBasis:(CGFloat)flexBasis - (void)yk_setFlexBasis:(CGFloat)flexBasis
{ {
YGNodeStyleSetFlexBasis([self ygNode], flexBasis); YGNodeStyleSetFlexBasis([self ygNode], flexBasis);
} }
- (CGFloat)yk_positionForEdge:(YKEdge)edge
{
return YGNodeStyleGetPosition([self ygNode], (YGEdge)edge);
}
- (void)yk_setPosition:(CGFloat)position forEdge:(YKEdge)edge - (void)yk_setPosition:(CGFloat)position forEdge:(YKEdge)edge
{ {
YGNodeStyleSetPosition([self ygNode], (YGEdge)edge, position); YGNodeStyleSetPosition([self ygNode], (YGEdge)edge, position);
} }
- (CGFloat)yk_marginForEdge:(YKEdge)edge
{
return YGNodeStyleGetMargin([self ygNode], (YGEdge)edge);
}
- (void)yk_setMargin:(CGFloat)margin forEdge:(YKEdge)edge - (void)yk_setMargin:(CGFloat)margin forEdge:(YKEdge)edge
{ {
YGNodeStyleSetMargin([self ygNode], (YGEdge)edge, margin); YGNodeStyleSetMargin([self ygNode], (YGEdge)edge, margin);
} }
- (CGFloat)yk_paddingForEdge:(YKEdge)edge
{
return YGNodeStyleGetPadding([self ygNode], (YGEdge)edge);
}
- (void)yk_setPadding:(CGFloat)padding forEdge:(YKEdge)edge - (void)yk_setPadding:(CGFloat)padding forEdge:(YKEdge)edge
{ {
YGNodeStyleSetPadding([self ygNode], (YGEdge)edge, padding); YGNodeStyleSetPadding([self ygNode], (YGEdge)edge, padding);
} }
- (CGFloat)yk_width
{
return YGNodeStyleGetWidth([self ygNode]);
}
- (void)yk_setWidth:(CGFloat)width - (void)yk_setWidth:(CGFloat)width
{ {
YGNodeStyleSetWidth([self ygNode], width); YGNodeStyleSetWidth([self ygNode], width);
} }
- (CGFloat)yk_height
{
return YGNodeStyleGetHeight([self ygNode]);
}
- (void)yk_setHeight:(CGFloat)height - (void)yk_setHeight:(CGFloat)height
{ {
YGNodeStyleSetHeight([self ygNode], height); YGNodeStyleSetHeight([self ygNode], height);
} }
- (CGFloat)yk_minWidth
{
return YGNodeStyleGetMinWidth([self ygNode]);
}
- (void)yk_setMinWidth:(CGFloat)minWidth - (void)yk_setMinWidth:(CGFloat)minWidth
{ {
YGNodeStyleSetMinWidth([self ygNode], minWidth); YGNodeStyleSetMinWidth([self ygNode], minWidth);
} }
- (CGFloat)yk_minHeight
{
return YGNodeStyleGetMinHeight([self ygNode]);
}
- (void)yk_setMinHeight:(CGFloat)minHeight - (void)yk_setMinHeight:(CGFloat)minHeight
{ {
YGNodeStyleSetMinHeight([self ygNode], minHeight); YGNodeStyleSetMinHeight([self ygNode], minHeight);
} }
- (CGFloat)yk_maxWidth
{
return YGNodeStyleGetMaxWidth([self ygNode]);
}
- (void)yk_setMaxWidth:(CGFloat)maxWidth - (void)yk_setMaxWidth:(CGFloat)maxWidth
{ {
YGNodeStyleSetMaxWidth([self ygNode], maxWidth); YGNodeStyleSetMaxWidth([self ygNode], maxWidth);
} }
- (CGFloat)yk_maxHeight
{
return YGNodeStyleGetMaxHeight([self ygNode]);
}
- (void)yk_setMaxHeight:(CGFloat)maxHeight - (void)yk_setMaxHeight:(CGFloat)maxHeight
{ {
YGNodeStyleSetMaxHeight([self ygNode], maxHeight); YGNodeStyleSetMaxHeight([self ygNode], maxHeight);
} }
- (CGFloat)yk_aspectRatio
{
return YGNodeStyleGetAspectRatio([self ygNode]);
}
- (void)yk_setAspectRatio:(CGFloat)aspectRatio - (void)yk_setAspectRatio:(CGFloat)aspectRatio
{ {
YGNodeStyleSetAspectRatio([self ygNode], aspectRatio); YGNodeStyleSetAspectRatio([self ygNode], aspectRatio);

View File

@@ -14,18 +14,6 @@ typedef NS_ENUM(NSInteger, YKFlexDirection) {
YKFlexDirectionRowReverse, YKFlexDirectionRowReverse,
}; };
typedef NS_ENUM(NSInteger, YKMeasureMode) {
YKMeasureModeUndefined,
YKMeasureModeExactly,
YKMeasureModeAtMost,
};
typedef NS_ENUM(NSInteger, YKPrintOptions) {
YKPrintOptionsLayout = 1,
YKPrintOptionsStyle = 2,
YKPrintOptionsChildren = 4,
};
typedef NS_ENUM(NSInteger, YKEdge) { typedef NS_ENUM(NSInteger, YKEdge) {
YKEdgeLeft, YKEdgeLeft,
YKEdgeTop, YKEdgeTop,
@@ -43,11 +31,6 @@ typedef NS_ENUM(NSInteger, YKPositionType) {
YKPositionTypeAbsolute, YKPositionTypeAbsolute,
}; };
typedef NS_ENUM(NSInteger, YKDimension) {
YKDimensionWidth,
YKDimensionHeight,
};
typedef NS_ENUM(NSInteger, YKJustify) { typedef NS_ENUM(NSInteger, YKJustify) {
YKJustifyFlexStart, YKJustifyFlexStart,
YKJustifyCenter, YKJustifyCenter,
@@ -62,30 +45,11 @@ typedef NS_ENUM(NSInteger, YKDirection) {
YKDirectionRightToLeft, YKDirectionRightToLeft,
}; };
typedef NS_ENUM(NSInteger, YKLogLevel) {
YKLogLevelError,
YKLogLevelWarn,
YKLogLevelInfo,
YKLogLevelDebug,
YKLogLevelVerbose,
};
typedef NS_ENUM(NSInteger, YKWrap) { typedef NS_ENUM(NSInteger, YKWrap) {
YKWrapNoWrap, YKWrapNoWrap,
YKWrapWrap, YKWrapWrap,
}; };
typedef NS_ENUM(NSInteger, YKOverflow) {
YKOverflowVisible,
YKOverflowHidden,
YKOverflowScroll,
};
typedef NS_ENUM(NSInteger, YKExperimentalFeature) {
YKExperimentalFeatureRounding,
YKExperimentalFeatureWebFlexBasis,
};
typedef NS_ENUM(NSInteger, YKAlign) { typedef NS_ENUM(NSInteger, YKAlign) {
YKAlignAuto, YKAlignAuto,
YKAlignFlexStart, YKAlignFlexStart,

View File

@@ -15,3 +15,4 @@ FOUNDATION_EXPORT double YogaKitVersionNumber;
FOUNDATION_EXPORT const unsigned char YogaKitVersionString[]; FOUNDATION_EXPORT const unsigned char YogaKitVersionString[];
#import <YogaKit/UIView+YogaKit.h> #import <YogaKit/UIView+YogaKit.h>
#import <YogaKit/YKEnums.h>

View File

@@ -94,7 +94,13 @@ OBJC_ENUMS = {
'Inherit', 'Inherit',
'LeftToRight', 'LeftToRight',
'RightToLeft', 'RightToLeft',
] ],
'MeasureMode': None,
'PrintOptions': None,
'Dimension': None,
'LogLevel': None,
'Overflow': None,
'ExperimentalFeature': None
} }
LICENSE = """/** LICENSE = """/**
@@ -202,11 +208,12 @@ with open(root + '/YogaKit/YKEnums.h', 'w') as f:
objc_enums.update(OBJC_ENUMS) objc_enums.update(OBJC_ENUMS)
f.write(LICENSE) f.write(LICENSE)
for name, values in objc_enums.items(): for name, values in objc_enums.items():
f.write('typedef NS_ENUM(NSInteger, YK%s) {\n' % name) if values is not None:
for value in values: f.write('typedef NS_ENUM(NSInteger, YK%s) {\n' % name)
if isinstance(value, tuple): for value in values:
f.write(' YK%s%s = %d,\n' % (name, value[0], value[1])) if isinstance(value, tuple):
else: f.write(' YK%s%s = %d,\n' % (name, value[0], value[1]))
f.write(' YK%s%s,\n' % (name, value)) else:
f.write('};\n') f.write(' YK%s%s,\n' % (name, value))
f.write('\n') f.write('};\n')
f.write('\n')