diff --git a/YogaKit/Source/UIView+Yoga.h b/YogaKit/Source/UIView+Yoga.h index cac23385..4c85dcc4 100644 --- a/YogaKit/Source/UIView+Yoga.h +++ b/YogaKit/Source/UIView+Yoga.h @@ -5,28 +5,29 @@ * LICENSE file in the root directory of this source tree. */ -#import "YGLayout.h" #import +#import "YGLayout.h" NS_ASSUME_NONNULL_BEGIN -typedef void (^YGLayoutConfigurationBlock)(YGLayout *layout); +typedef void (^YGLayoutConfigurationBlock)(YGLayout* layout); @interface UIView (Yoga) /** The YGLayout that is attached to this view. It is lazily created. */ -@property (nonatomic, readonly, strong) YGLayout *yoga; +@property(nonatomic, readonly, strong) YGLayout* yoga; /** Indicates whether or not Yoga is enabled */ -@property (nonatomic, readonly, assign) BOOL isYogaEnabled; +@property(nonatomic, readonly, assign) BOOL isYogaEnabled; /** - In ObjC land, every time you access `view.yoga.*` you are adding another `objc_msgSend` - to your code. If you plan on making multiple changes to YGLayout, it's more performant - to use this method, which uses a single objc_msgSend call. + In ObjC land, every time you access `view.yoga.*` you are adding another + `objc_msgSend` to your code. If you plan on making multiple changes to + YGLayout, it's more performant to use this method, which uses a single + objc_msgSend call. */ - (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block NS_SWIFT_NAME(configureLayout(block:)); diff --git a/YogaKit/Source/UIView+Yoga.m b/YogaKit/Source/UIView+Yoga.m index ba133919..e472c9c7 100644 --- a/YogaKit/Source/UIView+Yoga.m +++ b/YogaKit/Source/UIView+Yoga.m @@ -5,32 +5,30 @@ * LICENSE file in the root directory of this source tree. */ +#import #import "UIView+Yoga.h" #import "YGLayout+Private.h" -#import -static const void *kYGYogaAssociatedKey = &kYGYogaAssociatedKey; +static const void* kYGYogaAssociatedKey = &kYGYogaAssociatedKey; @implementation UIView (YogaKit) -- (YGLayout *)yoga -{ - YGLayout *yoga = objc_getAssociatedObject(self, kYGYogaAssociatedKey); +- (YGLayout*)yoga { + YGLayout* yoga = objc_getAssociatedObject(self, kYGYogaAssociatedKey); if (!yoga) { yoga = [[YGLayout alloc] initWithView:self]; - objc_setAssociatedObject(self, kYGYogaAssociatedKey, yoga, OBJC_ASSOCIATION_RETAIN_NONATOMIC); + objc_setAssociatedObject( + self, kYGYogaAssociatedKey, yoga, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } return yoga; } -- (BOOL)isYogaEnabled -{ +- (BOOL)isYogaEnabled { return objc_getAssociatedObject(self, kYGYogaAssociatedKey) != nil; } -- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block -{ +- (void)configureLayoutWithBlock:(YGLayoutConfigurationBlock)block { if (block != nil) { block(self.yoga); } diff --git a/YogaKit/Source/YGLayout+Private.h b/YogaKit/Source/YGLayout+Private.h index 00ab40f5..0588d950 100644 --- a/YogaKit/Source/YGLayout+Private.h +++ b/YogaKit/Source/YGLayout+Private.h @@ -5,13 +5,13 @@ * LICENSE file in the root directory of this source tree. */ -#import "YGLayout.h" #import +#import "YGLayout.h" @interface YGLayout () -@property (nonatomic, assign, readonly) YGNodeRef node; +@property(nonatomic, assign, readonly) YGNodeRef node; -- (instancetype)initWithView:(UIView *)view; +- (instancetype)initWithView:(UIView*)view; @end diff --git a/YogaKit/Source/YGLayout.h b/YogaKit/Source/YGLayout.h index 19f3982b..5a60f95e 100644 --- a/YogaKit/Source/YGLayout.h +++ b/YogaKit/Source/YGLayout.h @@ -7,15 +7,15 @@ #import #import -#import #import +#import YG_EXTERN_C_BEGIN -extern YGValue YGPointValue(CGFloat value) - NS_SWIFT_UNAVAILABLE("Use the swift Int and FloatingPoint extensions instead"); -extern YGValue YGPercentValue(CGFloat value) - NS_SWIFT_UNAVAILABLE("Use the swift Int and FloatingPoint extensions instead"); +extern YGValue YGPointValue(CGFloat value) NS_SWIFT_UNAVAILABLE( + "Use the swift Int and FloatingPoint extensions instead"); +extern YGValue YGPercentValue(CGFloat value) NS_SWIFT_UNAVAILABLE( + "Use the swift Int and FloatingPoint extensions instead"); YG_EXTERN_C_END @@ -44,103 +44,107 @@ typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) { The property that decides if we should include this view when calculating layout. Defaults to YES. */ -@property (nonatomic, readwrite, assign, setter=setIncludedInLayout:) BOOL isIncludedInLayout; +@property(nonatomic, readwrite, assign, setter=setIncludedInLayout:) + BOOL isIncludedInLayout; /** - The property that decides during layout/sizing whether or not styling properties should be applied. - Defaults to NO. + The property that decides during layout/sizing whether or not styling + properties should be applied. Defaults to NO. */ -@property (nonatomic, readwrite, assign, setter=setEnabled:) BOOL isEnabled; +@property(nonatomic, readwrite, assign, setter=setEnabled:) BOOL isEnabled; -@property (nonatomic, readwrite, assign) YGDirection direction; -@property (nonatomic, readwrite, assign) YGFlexDirection flexDirection; -@property (nonatomic, readwrite, assign) YGJustify justifyContent; -@property (nonatomic, readwrite, assign) YGAlign alignContent; -@property (nonatomic, readwrite, assign) YGAlign alignItems; -@property (nonatomic, readwrite, assign) YGAlign alignSelf; -@property (nonatomic, readwrite, assign) YGPositionType position; -@property (nonatomic, readwrite, assign) YGWrap flexWrap; -@property (nonatomic, readwrite, assign) YGOverflow overflow; -@property (nonatomic, readwrite, assign) YGDisplay display; +@property(nonatomic, readwrite, assign) YGDirection direction; +@property(nonatomic, readwrite, assign) YGFlexDirection flexDirection; +@property(nonatomic, readwrite, assign) YGJustify justifyContent; +@property(nonatomic, readwrite, assign) YGAlign alignContent; +@property(nonatomic, readwrite, assign) YGAlign alignItems; +@property(nonatomic, readwrite, assign) YGAlign alignSelf; +@property(nonatomic, readwrite, assign) YGPositionType position; +@property(nonatomic, readwrite, assign) YGWrap flexWrap; +@property(nonatomic, readwrite, assign) YGOverflow overflow; +@property(nonatomic, readwrite, assign) YGDisplay display; -@property (nonatomic, readwrite, assign) CGFloat flex; -@property (nonatomic, readwrite, assign) CGFloat flexGrow; -@property (nonatomic, readwrite, assign) CGFloat flexShrink; -@property (nonatomic, readwrite, assign) YGValue flexBasis; +@property(nonatomic, readwrite, assign) CGFloat flex; +@property(nonatomic, readwrite, assign) CGFloat flexGrow; +@property(nonatomic, readwrite, assign) CGFloat flexShrink; +@property(nonatomic, readwrite, assign) YGValue flexBasis; -@property (nonatomic, readwrite, assign) YGValue left; -@property (nonatomic, readwrite, assign) YGValue top; -@property (nonatomic, readwrite, assign) YGValue right; -@property (nonatomic, readwrite, assign) YGValue bottom; -@property (nonatomic, readwrite, assign) YGValue start; -@property (nonatomic, readwrite, assign) YGValue end; +@property(nonatomic, readwrite, assign) YGValue left; +@property(nonatomic, readwrite, assign) YGValue top; +@property(nonatomic, readwrite, assign) YGValue right; +@property(nonatomic, readwrite, assign) YGValue bottom; +@property(nonatomic, readwrite, assign) YGValue start; +@property(nonatomic, readwrite, assign) YGValue end; -@property (nonatomic, readwrite, assign) YGValue marginLeft; -@property (nonatomic, readwrite, assign) YGValue marginTop; -@property (nonatomic, readwrite, assign) YGValue marginRight; -@property (nonatomic, readwrite, assign) YGValue marginBottom; -@property (nonatomic, readwrite, assign) YGValue marginStart; -@property (nonatomic, readwrite, assign) YGValue marginEnd; -@property (nonatomic, readwrite, assign) YGValue marginHorizontal; -@property (nonatomic, readwrite, assign) YGValue marginVertical; -@property (nonatomic, readwrite, assign) YGValue margin; +@property(nonatomic, readwrite, assign) YGValue marginLeft; +@property(nonatomic, readwrite, assign) YGValue marginTop; +@property(nonatomic, readwrite, assign) YGValue marginRight; +@property(nonatomic, readwrite, assign) YGValue marginBottom; +@property(nonatomic, readwrite, assign) YGValue marginStart; +@property(nonatomic, readwrite, assign) YGValue marginEnd; +@property(nonatomic, readwrite, assign) YGValue marginHorizontal; +@property(nonatomic, readwrite, assign) YGValue marginVertical; +@property(nonatomic, readwrite, assign) YGValue margin; -@property (nonatomic, readwrite, assign) YGValue paddingLeft; -@property (nonatomic, readwrite, assign) YGValue paddingTop; -@property (nonatomic, readwrite, assign) YGValue paddingRight; -@property (nonatomic, readwrite, assign) YGValue paddingBottom; -@property (nonatomic, readwrite, assign) YGValue paddingStart; -@property (nonatomic, readwrite, assign) YGValue paddingEnd; -@property (nonatomic, readwrite, assign) YGValue paddingHorizontal; -@property (nonatomic, readwrite, assign) YGValue paddingVertical; -@property (nonatomic, readwrite, assign) YGValue padding; +@property(nonatomic, readwrite, assign) YGValue paddingLeft; +@property(nonatomic, readwrite, assign) YGValue paddingTop; +@property(nonatomic, readwrite, assign) YGValue paddingRight; +@property(nonatomic, readwrite, assign) YGValue paddingBottom; +@property(nonatomic, readwrite, assign) YGValue paddingStart; +@property(nonatomic, readwrite, assign) YGValue paddingEnd; +@property(nonatomic, readwrite, assign) YGValue paddingHorizontal; +@property(nonatomic, readwrite, assign) YGValue paddingVertical; +@property(nonatomic, readwrite, assign) YGValue padding; -@property (nonatomic, readwrite, assign) CGFloat borderLeftWidth; -@property (nonatomic, readwrite, assign) CGFloat borderTopWidth; -@property (nonatomic, readwrite, assign) CGFloat borderRightWidth; -@property (nonatomic, readwrite, assign) CGFloat borderBottomWidth; -@property (nonatomic, readwrite, assign) CGFloat borderStartWidth; -@property (nonatomic, readwrite, assign) CGFloat borderEndWidth; -@property (nonatomic, readwrite, assign) CGFloat borderWidth; +@property(nonatomic, readwrite, assign) CGFloat borderLeftWidth; +@property(nonatomic, readwrite, assign) CGFloat borderTopWidth; +@property(nonatomic, readwrite, assign) CGFloat borderRightWidth; +@property(nonatomic, readwrite, assign) CGFloat borderBottomWidth; +@property(nonatomic, readwrite, assign) CGFloat borderStartWidth; +@property(nonatomic, readwrite, assign) CGFloat borderEndWidth; +@property(nonatomic, readwrite, assign) CGFloat borderWidth; -@property (nonatomic, readwrite, assign) YGValue width; -@property (nonatomic, readwrite, assign) YGValue height; -@property (nonatomic, readwrite, assign) YGValue minWidth; -@property (nonatomic, readwrite, assign) YGValue minHeight; -@property (nonatomic, readwrite, assign) YGValue maxWidth; -@property (nonatomic, readwrite, assign) YGValue maxHeight; +@property(nonatomic, readwrite, assign) YGValue width; +@property(nonatomic, readwrite, assign) YGValue height; +@property(nonatomic, readwrite, assign) YGValue minWidth; +@property(nonatomic, readwrite, assign) YGValue minHeight; +@property(nonatomic, readwrite, assign) YGValue maxWidth; +@property(nonatomic, readwrite, assign) YGValue maxHeight; // Yoga specific properties, not compatible with flexbox specification -@property (nonatomic, readwrite, assign) CGFloat aspectRatio; +@property(nonatomic, readwrite, assign) CGFloat aspectRatio; /** Get the resolved direction of this node. This won't be YGDirectionInherit */ -@property (nonatomic, readonly, assign) YGDirection resolvedDirection; +@property(nonatomic, readonly, assign) YGDirection resolvedDirection; /** - Perform a layout calculation and update the frames of the views in the hierarchy with the results. - If the origin is not preserved, the root view's layout results will applied from {0,0}. + Perform a layout calculation and update the frames of the views in the + hierarchy with the results. If the origin is not preserved, the root view's + layout results will applied from {0,0}. */ - (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin NS_SWIFT_NAME(applyLayout(preservingOrigin:)); /** - Perform a layout calculation and update the frames of the views in the hierarchy with the results. - If the origin is not preserved, the root view's layout results will applied from {0,0}. + Perform a layout calculation and update the frames of the views in the + hierarchy with the results. If the origin is not preserved, the root view's + layout results will applied from {0,0}. */ - (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin dimensionFlexibility:(YGDimensionFlexibility)dimensionFlexibility NS_SWIFT_NAME(applyLayout(preservingOrigin:dimensionFlexibility:)); /** - 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)]; */ -@property (nonatomic, readonly, assign) CGSize intrinsicSize; +@property(nonatomic, readonly, assign) CGSize intrinsicSize; /** - Returns the size of the view based on provided constraints. Pass NaN for an unconstrained dimension. + Returns the size of the view based on provided constraints. Pass NaN for an + unconstrained dimension. */ - (CGSize)calculateLayoutWithSize:(CGSize)size NS_SWIFT_NAME(calculateLayout(with:)); @@ -148,19 +152,19 @@ typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) { /** Returns the number of children that are using Flexbox. */ -@property (nonatomic, readonly, assign) NSUInteger numberOfChildren; +@property(nonatomic, readonly, assign) NSUInteger numberOfChildren; /** - Return a BOOL indiciating whether or not we this node contains any subviews that are included in - Yoga's layout. + Return a BOOL indiciating whether or not we this node contains any subviews + that are included in Yoga's layout. */ -@property (nonatomic, readonly, assign) BOOL isLeaf; +@property(nonatomic, readonly, assign) BOOL isLeaf; /** Return's a BOOL indicating if a view is dirty. When a node is dirty it usually indicates that it will be remeasured on the next layout pass. */ -@property (nonatomic, readonly, assign) BOOL isDirty; +@property(nonatomic, readonly, assign) BOOL isDirty; /** Mark that a view's layout needs to be recalculated. Only works for leaf views. diff --git a/YogaKit/Source/YGLayout.m b/YogaKit/Source/YGLayout.m index 692020ca..4a95a5ca 100644 --- a/YogaKit/Source/YGLayout.m +++ b/YogaKit/Source/YGLayout.m @@ -5,153 +5,184 @@ * LICENSE file in the root directory of this source tree. */ -#import "YGLayout+Private.h" #import "UIView+Yoga.h" +#import "YGLayout+Private.h" -#define YG_PROPERTY(type, lowercased_name, capitalized_name) \ -- (type)lowercased_name \ -{ \ - return YGNodeStyleGet##capitalized_name(self.node); \ -} \ - \ -- (void)set##capitalized_name:(type)lowercased_name \ -{ \ - YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \ +#define YG_PROPERTY(type, lowercased_name, capitalized_name) \ + -(type)lowercased_name { \ + return YGNodeStyleGet##capitalized_name(self.node); \ + } \ + \ + -(void)set##capitalized_name : (type)lowercased_name { \ + YGNodeStyleSet##capitalized_name(self.node, lowercased_name); \ + } + +#define YG_VALUE_PROPERTY(lowercased_name, capitalized_name) \ + -(YGValue)lowercased_name { \ + return YGNodeStyleGet##capitalized_name(self.node); \ + } \ + \ + -(void)set##capitalized_name : (YGValue)lowercased_name { \ + switch (lowercased_name.unit) { \ + case YGUnitUndefined: \ + YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \ + break; \ + case YGUnitPoint: \ + YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \ + break; \ + case YGUnitPercent: \ + YGNodeStyleSet##capitalized_name##Percent( \ + self.node, lowercased_name.value); \ + break; \ + default: \ + NSAssert(NO, @"Not implemented"); \ + } \ + } + +#define YG_AUTO_VALUE_PROPERTY(lowercased_name, capitalized_name) \ + -(YGValue)lowercased_name { \ + return YGNodeStyleGet##capitalized_name(self.node); \ + } \ + \ + -(void)set##capitalized_name : (YGValue)lowercased_name { \ + switch (lowercased_name.unit) { \ + case YGUnitPoint: \ + YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \ + break; \ + case YGUnitPercent: \ + YGNodeStyleSet##capitalized_name##Percent( \ + self.node, lowercased_name.value); \ + break; \ + case YGUnitAuto: \ + YGNodeStyleSet##capitalized_name##Auto(self.node); \ + break; \ + default: \ + NSAssert(NO, @"Not implemented"); \ + } \ + } + +#define YG_EDGE_PROPERTY_GETTER( \ + type, lowercased_name, capitalized_name, property, edge) \ + -(type)lowercased_name { \ + return YGNodeStyleGet##property(self.node, edge); \ + } + +#define YG_EDGE_PROPERTY_SETTER( \ + lowercased_name, capitalized_name, property, edge) \ + -(void)set##capitalized_name : (CGFloat)lowercased_name { \ + YGNodeStyleSet##property(self.node, edge, lowercased_name); \ + } + +#define YG_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \ + YG_EDGE_PROPERTY_GETTER( \ + CGFloat, lowercased_name, capitalized_name, property, edge) \ + YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) + +#define YG_VALUE_EDGE_PROPERTY_SETTER( \ + objc_lowercased_name, objc_capitalized_name, c_name, edge) \ + -(void)set##objc_capitalized_name : (YGValue)objc_lowercased_name { \ + switch (objc_lowercased_name.unit) { \ + case YGUnitUndefined: \ + YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name.value); \ + break; \ + case YGUnitPoint: \ + YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name.value); \ + break; \ + case YGUnitPercent: \ + YGNodeStyleSet##c_name##Percent( \ + self.node, edge, objc_lowercased_name.value); \ + break; \ + default: \ + NSAssert(NO, @"Not implemented"); \ + } \ + } + +#define YG_VALUE_EDGE_PROPERTY( \ + lowercased_name, capitalized_name, property, edge) \ + YG_EDGE_PROPERTY_GETTER( \ + YGValue, lowercased_name, capitalized_name, property, edge) \ + YG_VALUE_EDGE_PROPERTY_SETTER( \ + lowercased_name, capitalized_name, property, edge) + +#define YG_VALUE_EDGES_PROPERTIES(lowercased_name, capitalized_name) \ + YG_VALUE_EDGE_PROPERTY( \ + lowercased_name##Left, \ + capitalized_name##Left, \ + capitalized_name, \ + YGEdgeLeft) \ + YG_VALUE_EDGE_PROPERTY( \ + lowercased_name##Top, \ + capitalized_name##Top, \ + capitalized_name, \ + YGEdgeTop) \ + YG_VALUE_EDGE_PROPERTY( \ + lowercased_name##Right, \ + capitalized_name##Right, \ + capitalized_name, \ + YGEdgeRight) \ + YG_VALUE_EDGE_PROPERTY( \ + lowercased_name##Bottom, \ + capitalized_name##Bottom, \ + capitalized_name, \ + YGEdgeBottom) \ + YG_VALUE_EDGE_PROPERTY( \ + lowercased_name##Start, \ + capitalized_name##Start, \ + capitalized_name, \ + YGEdgeStart) \ + YG_VALUE_EDGE_PROPERTY( \ + lowercased_name##End, \ + capitalized_name##End, \ + capitalized_name, \ + YGEdgeEnd) \ + YG_VALUE_EDGE_PROPERTY( \ + lowercased_name##Horizontal, \ + capitalized_name##Horizontal, \ + capitalized_name, \ + YGEdgeHorizontal) \ + YG_VALUE_EDGE_PROPERTY( \ + lowercased_name##Vertical, \ + capitalized_name##Vertical, \ + capitalized_name, \ + YGEdgeVertical) \ + YG_VALUE_EDGE_PROPERTY( \ + lowercased_name, capitalized_name, capitalized_name, YGEdgeAll) + +YGValue YGPointValue(CGFloat value) { + return (YGValue){.value = value, .unit = YGUnitPoint}; } -#define YG_VALUE_PROPERTY(lowercased_name, capitalized_name) \ -- (YGValue)lowercased_name \ -{ \ - return YGNodeStyleGet##capitalized_name(self.node); \ -} \ - \ -- (void)set##capitalized_name:(YGValue)lowercased_name \ -{ \ - switch (lowercased_name.unit) { \ - case YGUnitUndefined: \ - YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \ - break; \ - case YGUnitPoint: \ - YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \ - break; \ - case YGUnitPercent: \ - YGNodeStyleSet##capitalized_name##Percent(self.node, lowercased_name.value); \ - break; \ - default: \ - NSAssert(NO, @"Not implemented"); \ - } \ -} - -#define YG_AUTO_VALUE_PROPERTY(lowercased_name, capitalized_name) \ -- (YGValue)lowercased_name \ -{ \ - return YGNodeStyleGet##capitalized_name(self.node); \ -} \ - \ -- (void)set##capitalized_name:(YGValue)lowercased_name \ -{ \ - switch (lowercased_name.unit) { \ - case YGUnitPoint: \ - YGNodeStyleSet##capitalized_name(self.node, lowercased_name.value); \ - break; \ - case YGUnitPercent: \ - YGNodeStyleSet##capitalized_name##Percent(self.node, lowercased_name.value); \ - break; \ - case YGUnitAuto: \ - YGNodeStyleSet##capitalized_name##Auto(self.node); \ - break; \ - default: \ - NSAssert(NO, @"Not implemented"); \ - } \ -} - -#define YG_EDGE_PROPERTY_GETTER(type, lowercased_name, capitalized_name, property, edge) \ -- (type)lowercased_name \ -{ \ - return YGNodeStyleGet##property(self.node, edge); \ -} - -#define YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) \ -- (void)set##capitalized_name:(CGFloat)lowercased_name \ -{ \ - YGNodeStyleSet##property(self.node, edge, lowercased_name); \ -} - -#define YG_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \ -YG_EDGE_PROPERTY_GETTER(CGFloat, lowercased_name, capitalized_name, property, edge) \ -YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) - -#define YG_VALUE_EDGE_PROPERTY_SETTER(objc_lowercased_name, objc_capitalized_name, c_name, edge) \ -- (void)set##objc_capitalized_name:(YGValue)objc_lowercased_name \ -{ \ - switch (objc_lowercased_name.unit) { \ - case YGUnitUndefined: \ - YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name.value); \ - break; \ - case YGUnitPoint: \ - YGNodeStyleSet##c_name(self.node, edge, objc_lowercased_name.value); \ - break; \ - case YGUnitPercent: \ - YGNodeStyleSet##c_name##Percent(self.node, edge, objc_lowercased_name.value); \ - break; \ - default: \ - NSAssert(NO, @"Not implemented"); \ - } \ -} - -#define YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, property, edge) \ -YG_EDGE_PROPERTY_GETTER(YGValue, lowercased_name, capitalized_name, property, edge) \ -YG_VALUE_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge) - -#define YG_VALUE_EDGES_PROPERTIES(lowercased_name, capitalized_name) \ -YG_VALUE_EDGE_PROPERTY(lowercased_name##Left, capitalized_name##Left, capitalized_name, YGEdgeLeft) \ -YG_VALUE_EDGE_PROPERTY(lowercased_name##Top, capitalized_name##Top, capitalized_name, YGEdgeTop) \ -YG_VALUE_EDGE_PROPERTY(lowercased_name##Right, capitalized_name##Right, capitalized_name, YGEdgeRight) \ -YG_VALUE_EDGE_PROPERTY(lowercased_name##Bottom, capitalized_name##Bottom, capitalized_name, YGEdgeBottom) \ -YG_VALUE_EDGE_PROPERTY(lowercased_name##Start, capitalized_name##Start, capitalized_name, YGEdgeStart) \ -YG_VALUE_EDGE_PROPERTY(lowercased_name##End, capitalized_name##End, capitalized_name, YGEdgeEnd) \ -YG_VALUE_EDGE_PROPERTY(lowercased_name##Horizontal, capitalized_name##Horizontal, capitalized_name, YGEdgeHorizontal) \ -YG_VALUE_EDGE_PROPERTY(lowercased_name##Vertical, capitalized_name##Vertical, capitalized_name, YGEdgeVertical) \ -YG_VALUE_EDGE_PROPERTY(lowercased_name, capitalized_name, capitalized_name, YGEdgeAll) - -YGValue YGPointValue(CGFloat value) -{ - return (YGValue) { .value = value, .unit = YGUnitPoint }; -} - -YGValue YGPercentValue(CGFloat value) -{ - return (YGValue) { .value = value, .unit = YGUnitPercent }; +YGValue YGPercentValue(CGFloat value) { + return (YGValue){.value = value, .unit = YGUnitPercent}; } static YGConfigRef globalConfig; @interface YGLayout () -@property (nonatomic, weak, readonly) UIView *view; +@property(nonatomic, weak, readonly) UIView* view; @property(nonatomic, assign, readonly) BOOL isUIView; @end @implementation YGLayout -@synthesize isEnabled=_isEnabled; -@synthesize isIncludedInLayout=_isIncludedInLayout; -@synthesize node=_node; +@synthesize isEnabled = _isEnabled; +@synthesize isIncludedInLayout = _isIncludedInLayout; +@synthesize node = _node; -+ (void)initialize -{ ++ (void)initialize { globalConfig = YGConfigNew(); - YGConfigSetExperimentalFeatureEnabled(globalConfig, YGExperimentalFeatureWebFlexBasis, true); + YGConfigSetExperimentalFeatureEnabled( + globalConfig, YGExperimentalFeatureWebFlexBasis, true); YGConfigSetPointScaleFactor(globalConfig, [UIScreen mainScreen].scale); } -- (instancetype)initWithView:(UIView*)view -{ +- (instancetype)initWithView:(UIView*)view { if (self = [super init]) { _view = view; _node = YGNodeNewWithConfig(globalConfig); - YGNodeSetContext(_node, (__bridge void *) view); + YGNodeSetContext(_node, (__bridge void*)view); _isEnabled = NO; _isIncludedInLayout = YES; _isUIView = [view isMemberOfClass:[UIView class]]; @@ -160,18 +191,15 @@ static YGConfigRef globalConfig; return self; } -- (void)dealloc -{ +- (void)dealloc { YGNodeFree(self.node); } -- (BOOL)isDirty -{ +- (BOOL)isDirty { return YGNodeIsDirty(self.node); } -- (void)markDirty -{ +- (void)markDirty { if (self.isDirty || !self.isLeaf) { return; } @@ -187,17 +215,17 @@ static YGConfigRef globalConfig; YGNodeMarkDirty(node); } -- (NSUInteger)numberOfChildren -{ +- (NSUInteger)numberOfChildren { return YGNodeGetChildCount(self.node); } -- (BOOL)isLeaf -{ - NSAssert([NSThread isMainThread], @"This method must be called on the main thread."); +- (BOOL)isLeaf { + NSAssert( + [NSThread isMainThread], + @"This method must be called on the main thread."); if (self.isEnabled) { - for (UIView *subview in self.view.subviews) { - YGLayout *const yoga = subview.yoga; + for (UIView* subview in self.view.subviews) { + YGLayout* const yoga = subview.yoga; if (yoga.isEnabled && yoga.isIncludedInLayout) { return NO; } @@ -209,13 +237,11 @@ static YGConfigRef globalConfig; #pragma mark - Style -- (YGPositionType)position -{ +- (YGPositionType)position { return YGNodeStyleGetPositionType(self.node); } -- (void)setPosition:(YGPositionType)position -{ +- (void)setPosition:(YGPositionType)position { YGNodeStyleSetPositionType(self.node, position); } @@ -261,25 +287,23 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio) #pragma mark - Layout and Sizing -- (YGDirection)resolvedDirection -{ +- (YGDirection)resolvedDirection { return YGNodeLayoutGetDirection(self.node); } -- (void)applyLayout -{ +- (void)applyLayout { [self calculateLayoutWithSize:self.view.bounds.size]; YGApplyLayoutToViewHierarchy(self.view, NO); } -- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin -{ +- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin { [self calculateLayoutWithSize:self.view.bounds.size]; YGApplyLayoutToViewHierarchy(self.view, preserveOrigin); } -- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin dimensionFlexibility:(YGDimensionFlexibility)dimensionFlexibility -{ +- (void)applyLayoutPreservingOrigin:(BOOL)preserveOrigin + dimensionFlexibility: + (YGDimensionFlexibility)dimensionFlexibility { CGSize size = self.view.bounds.size; if (dimensionFlexibility & YGDimensionFlexibilityFlexibleWidth) { size.width = YGUndefined; @@ -291,18 +315,15 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio) YGApplyLayoutToViewHierarchy(self.view, preserveOrigin); } - -- (CGSize)intrinsicSize -{ +- (CGSize)intrinsicSize { const CGSize constrainedSize = { - .width = YGUndefined, - .height = YGUndefined, + .width = YGUndefined, + .height = YGUndefined, }; return [self calculateLayoutWithSize:constrainedSize]; } -- (CGSize)calculateLayoutWithSize:(CGSize)size -{ +- (CGSize)calculateLayoutWithSize:(CGSize)size { NSAssert([NSThread isMainThread], @"Yoga calculation must be done on main."); NSAssert(self.isEnabled, @"Yoga is not enabled for this view."); @@ -310,30 +331,28 @@ YG_PROPERTY(CGFloat, aspectRatio, AspectRatio) const YGNodeRef node = self.node; YGNodeCalculateLayout( - node, - size.width, - size.height, - YGNodeStyleGetDirection(node)); + node, size.width, size.height, YGNodeStyleGetDirection(node)); - return (CGSize) { - .width = YGNodeLayoutGetWidth(node), - .height = YGNodeLayoutGetHeight(node), + return (CGSize){ + .width = YGNodeLayoutGetWidth(node), + .height = YGNodeLayoutGetHeight(node), }; } #pragma mark - Private static YGSize YGMeasureView( - YGNodeRef node, - float width, - YGMeasureMode widthMode, - float height, - YGMeasureMode heightMode) -{ - const CGFloat constrainedWidth = (widthMode == YGMeasureModeUndefined) ? CGFLOAT_MAX : width; - const CGFloat constrainedHeight = (heightMode == YGMeasureModeUndefined) ? CGFLOAT_MAX: height; + YGNodeRef node, + float width, + YGMeasureMode widthMode, + float height, + YGMeasureMode heightMode) { + const CGFloat constrainedWidth = + (widthMode == YGMeasureModeUndefined) ? CGFLOAT_MAX : width; + const CGFloat constrainedHeight = + (heightMode == YGMeasureModeUndefined) ? CGFLOAT_MAX : height; - UIView *view = (__bridge UIView*) YGNodeGetContext(node); + UIView* view = (__bridge UIView*)YGNodeGetContext(node); CGSize sizeThatFits = CGSizeZero; // The default implementation of sizeThatFits: returns the existing size of @@ -349,17 +368,18 @@ static YGSize YGMeasureView( }]; } - return (YGSize) { - .width = YGSanitizeMeasurement(constrainedWidth, sizeThatFits.width, widthMode), - .height = YGSanitizeMeasurement(constrainedHeight, sizeThatFits.height, heightMode), + return (YGSize){ + .width = YGSanitizeMeasurement( + constrainedWidth, sizeThatFits.width, widthMode), + .height = YGSanitizeMeasurement( + constrainedHeight, sizeThatFits.height, heightMode), }; } static CGFloat YGSanitizeMeasurement( - CGFloat constrainedSize, - CGFloat measuredSize, - YGMeasureMode measureMode) -{ + CGFloat constrainedSize, + CGFloat measuredSize, + YGMeasureMode measureMode) { CGFloat result; if (measureMode == YGMeasureModeExactly) { result = constrainedSize; @@ -372,13 +392,14 @@ static CGFloat YGSanitizeMeasurement( return result; } -static BOOL YGNodeHasExactSameChildren(const YGNodeRef node, NSArray *subviews) -{ +static BOOL YGNodeHasExactSameChildren( + const YGNodeRef node, + NSArray* subviews) { if (YGNodeGetChildCount(node) != subviews.count) { return NO; } - for (int i=0; i * return YES; } -static void YGAttachNodesFromViewHierachy(UIView *const view) -{ - YGLayout *const yoga = view.yoga; +static void YGAttachNodesFromViewHierachy(UIView* const view) { + YGLayout* const yoga = view.yoga; const YGNodeRef node = yoga.node; // Only leaf nodes should have a measure function @@ -399,8 +419,9 @@ static void YGAttachNodesFromViewHierachy(UIView *const view) } else { YGNodeSetMeasureFunc(node, NULL); - NSMutableArray *subviewsToInclude = [[NSMutableArray alloc] initWithCapacity:view.subviews.count]; - for (UIView *subview in view.subviews) { + NSMutableArray* subviewsToInclude = + [[NSMutableArray alloc] initWithCapacity:view.subviews.count]; + for (UIView* subview in view.subviews) { if (subview.yoga.isEnabled && subview.yoga.isIncludedInLayout) { [subviewsToInclude addObject:subview]; } @@ -408,19 +429,18 @@ static void YGAttachNodesFromViewHierachy(UIView *const view) if (!YGNodeHasExactSameChildren(node, subviewsToInclude)) { YGRemoveAllChildren(node); - for (int i=0; i diff --git a/java/jni/ScopedGlobalRef.h b/java/jni/ScopedGlobalRef.h index b1c18e68..fa98214a 100644 --- a/java/jni/ScopedGlobalRef.h +++ b/java/jni/ScopedGlobalRef.h @@ -84,9 +84,7 @@ public: return *this; } - ~ScopedGlobalRef() { - reset(); - } + ~ScopedGlobalRef() { reset(); } /** * Deletes the currently held reference and reassigns a new one to the @@ -120,9 +118,7 @@ public: /** * Returns true if the underlying JNI reference is not NULL. */ - operator bool() const { - return mGlobalRef != NULL; - } + operator bool() const { return mGlobalRef != NULL; } ScopedGlobalRef(const ScopedGlobalRef& ref) = delete; ScopedGlobalRef& operator=(const ScopedGlobalRef& other) = delete; diff --git a/java/jni/ScopedLocalRef.h b/java/jni/ScopedLocalRef.h index 0c5e9440..2368ced2 100644 --- a/java/jni/ScopedLocalRef.h +++ b/java/jni/ScopedLocalRef.h @@ -83,9 +83,7 @@ public: return *this; } - ~ScopedLocalRef() { - reset(); - } + ~ScopedLocalRef() { reset(); } /** * Deletes the currently held reference and reassigns a new one to the @@ -119,9 +117,7 @@ public: /** * Returns true if the underlying JNI reference is not NULL. */ - operator bool() const { - return mLocalRef != NULL; - } + operator bool() const { return mLocalRef != NULL; } ScopedLocalRef(const ScopedLocalRef& ref) = delete; ScopedLocalRef& operator=(const ScopedLocalRef& other) = delete; diff --git a/java/jni/common.cpp b/java/jni/common.cpp index 143c695f..37b56770 100644 --- a/java/jni/common.cpp +++ b/java/jni/common.cpp @@ -77,8 +77,11 @@ DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(void, Void) { assertNoPendingJniException(env); } -ScopedLocalRef -callStaticObjectMethod(JNIEnv* env, jclass clazz, jmethodID methodId, ...) { +ScopedLocalRef callStaticObjectMethod( + JNIEnv* env, + jclass clazz, + jmethodID methodId, + ...) { va_list args; va_start(args, methodId); jobject result = env->CallStaticObjectMethodV(clazz, methodId, args); diff --git a/java/jni/common.h b/java/jni/common.h index 19eca6a4..fda1e06d 100644 --- a/java/jni/common.h +++ b/java/jni/common.h @@ -61,8 +61,11 @@ DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(void, Void); DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(jlong, Long); DEFINE_CALL_METHOD_FOR_PRIMITIVE_INTERFACE(jfloat, Float); -ScopedLocalRef -callStaticObjectMethod(JNIEnv* env, jclass clazz, jmethodID methodId, ...); +ScopedLocalRef callStaticObjectMethod( + JNIEnv* env, + jclass clazz, + jmethodID methodId, + ...); /** * Given a local or a global reference, this method creates a new global diff --git a/javascript/sources/Size.hh b/javascript/sources/Size.hh index d7ea6da9..9f550a96 100644 --- a/javascript/sources/Size.hh +++ b/javascript/sources/Size.hh @@ -18,7 +18,5 @@ struct Size { Size(double width, double height) : width(width), height(height) {} - void toJS(nbind::cbOutput expose) const { - expose(width, height); - } + void toJS(nbind::cbOutput expose) const { expose(width, height); } }; diff --git a/javascript/sources/Value.hh b/javascript/sources/Value.hh index e7a9cf66..2581ae4a 100644 --- a/javascript/sources/Value.hh +++ b/javascript/sources/Value.hh @@ -21,7 +21,5 @@ struct Value { Value(int unit, double value) : unit(unit), value(value) {} - void toJS(nbind::cbOutput expose) const { - expose(unit, value); - } + void toJS(nbind::cbOutput expose) const { expose(unit, value); } };