review improvements

This commit is contained in:
David Hart
2017-01-06 15:07:52 +01:00
parent 35ceb973bb
commit ec28cacb9f
7 changed files with 53 additions and 189 deletions

View File

@@ -9,7 +9,6 @@
#import <UIKit/UIKit.h>
#import <yoga/YGEnums.h>
#import <yoga/YGValue.h>
@interface YGLayout : NSObject

View File

@@ -10,11 +10,6 @@
#import "YGLayout+Private.h"
#import "UIView+Yoga.h"
#import <yoga/Yoga.h>
#import <UIKit/UIKit.h>
extern YGValue YGValueMake(CGFloat value, YGUnit unit) {
return (YGValue) { .value = value, .unit = unit };
}
#define YG_STYLE_PROPERTY_IMPL(type, lowercased_name, capitalized_name) \
- (type)lowercased_name \

View File

@@ -126,23 +126,13 @@ with open(root + '/yoga/YGEnums.h', 'w') as f:
f.write('YG_EXTERN_C_BEGIN\n\n')
for name, values in ENUMS.items():
f.write('#define YG%sCount %s\n' % (name, len(values)))
f.write('#ifndef NS_ENUM\n')
f.write('typedef enum YG%s {\n' % name)
f.write('typedef YG_ENUM_BEGIN(YG%s) {\n' % name)
for value in values:
if isinstance(value, tuple):
f.write(' YG%s%s = %d,\n' % (name, value[0], value[1]))
else:
f.write(' YG%s%s,\n' % (name, value))
f.write('} YG%s;\n' % name)
f.write('#else\n')
f.write('typedef NS_ENUM(NSInteger, YG%s) {\n' % name)
for value in values:
if isinstance(value, tuple):
f.write(' YG%s%s = %d,\n' % (name, value[0], value[1]))
else:
f.write(' YG%s%s,\n' % (name, value))
f.write('};\n')
f.write('#endif\n')
f.write('} YG_ENUM_END(YG%s);\n' % name)
f.write('\n')
f.write('YG_EXTERN_C_END\n')

View File

@@ -14,55 +14,29 @@
YG_EXTERN_C_BEGIN
#define YGFlexDirectionCount 4
#ifndef NS_ENUM
typedef enum YGFlexDirection {
typedef YG_ENUM_BEGIN(YGFlexDirection) {
YGFlexDirectionColumn,
YGFlexDirectionColumnReverse,
YGFlexDirectionRow,
YGFlexDirectionRowReverse,
} YGFlexDirection;
#else
typedef NS_ENUM(NSInteger, YGFlexDirection) {
YGFlexDirectionColumn,
YGFlexDirectionColumnReverse,
YGFlexDirectionRow,
YGFlexDirectionRowReverse,
};
#endif
} YG_ENUM_END(YGFlexDirection);
#define YGMeasureModeCount 3
#ifndef NS_ENUM
typedef enum YGMeasureMode {
typedef YG_ENUM_BEGIN(YGMeasureMode) {
YGMeasureModeUndefined,
YGMeasureModeExactly,
YGMeasureModeAtMost,
} YGMeasureMode;
#else
typedef NS_ENUM(NSInteger, YGMeasureMode) {
YGMeasureModeUndefined,
YGMeasureModeExactly,
YGMeasureModeAtMost,
};
#endif
} YG_ENUM_END(YGMeasureMode);
#define YGPrintOptionsCount 3
#ifndef NS_ENUM
typedef enum YGPrintOptions {
typedef YG_ENUM_BEGIN(YGPrintOptions) {
YGPrintOptionsLayout = 1,
YGPrintOptionsStyle = 2,
YGPrintOptionsChildren = 4,
} YGPrintOptions;
#else
typedef NS_ENUM(NSInteger, YGPrintOptions) {
YGPrintOptionsLayout = 1,
YGPrintOptionsStyle = 2,
YGPrintOptionsChildren = 4,
};
#endif
} YG_ENUM_END(YGPrintOptions);
#define YGEdgeCount 9
#ifndef NS_ENUM
typedef enum YGEdge {
typedef YG_ENUM_BEGIN(YGEdge) {
YGEdgeLeft,
YGEdgeTop,
YGEdgeRight,
@@ -72,173 +46,78 @@ typedef enum YGEdge {
YGEdgeHorizontal,
YGEdgeVertical,
YGEdgeAll,
} YGEdge;
#else
typedef NS_ENUM(NSInteger, YGEdge) {
YGEdgeLeft,
YGEdgeTop,
YGEdgeRight,
YGEdgeBottom,
YGEdgeStart,
YGEdgeEnd,
YGEdgeHorizontal,
YGEdgeVertical,
YGEdgeAll,
};
#endif
} YG_ENUM_END(YGEdge);
#define YGPositionTypeCount 2
#ifndef NS_ENUM
typedef enum YGPositionType {
typedef YG_ENUM_BEGIN(YGPositionType) {
YGPositionTypeRelative,
YGPositionTypeAbsolute,
} YGPositionType;
#else
typedef NS_ENUM(NSInteger, YGPositionType) {
YGPositionTypeRelative,
YGPositionTypeAbsolute,
};
#endif
} YG_ENUM_END(YGPositionType);
#define YGDimensionCount 2
#ifndef NS_ENUM
typedef enum YGDimension {
typedef YG_ENUM_BEGIN(YGDimension) {
YGDimensionWidth,
YGDimensionHeight,
} YGDimension;
#else
typedef NS_ENUM(NSInteger, YGDimension) {
YGDimensionWidth,
YGDimensionHeight,
};
#endif
} YG_ENUM_END(YGDimension);
#define YGJustifyCount 5
#ifndef NS_ENUM
typedef enum YGJustify {
typedef YG_ENUM_BEGIN(YGJustify) {
YGJustifyFlexStart,
YGJustifyCenter,
YGJustifyFlexEnd,
YGJustifySpaceBetween,
YGJustifySpaceAround,
} YGJustify;
#else
typedef NS_ENUM(NSInteger, YGJustify) {
YGJustifyFlexStart,
YGJustifyCenter,
YGJustifyFlexEnd,
YGJustifySpaceBetween,
YGJustifySpaceAround,
};
#endif
} YG_ENUM_END(YGJustify);
#define YGDirectionCount 3
#ifndef NS_ENUM
typedef enum YGDirection {
typedef YG_ENUM_BEGIN(YGDirection) {
YGDirectionInherit,
YGDirectionLTR,
YGDirectionRTL,
} YGDirection;
#else
typedef NS_ENUM(NSInteger, YGDirection) {
YGDirectionInherit,
YGDirectionLTR,
YGDirectionRTL,
};
#endif
} YG_ENUM_END(YGDirection);
#define YGLogLevelCount 5
#ifndef NS_ENUM
typedef enum YGLogLevel {
typedef YG_ENUM_BEGIN(YGLogLevel) {
YGLogLevelError,
YGLogLevelWarn,
YGLogLevelInfo,
YGLogLevelDebug,
YGLogLevelVerbose,
} YGLogLevel;
#else
typedef NS_ENUM(NSInteger, YGLogLevel) {
YGLogLevelError,
YGLogLevelWarn,
YGLogLevelInfo,
YGLogLevelDebug,
YGLogLevelVerbose,
};
#endif
} YG_ENUM_END(YGLogLevel);
#define YGWrapCount 2
#ifndef NS_ENUM
typedef enum YGWrap {
typedef YG_ENUM_BEGIN(YGWrap) {
YGWrapNoWrap,
YGWrapWrap,
} YGWrap;
#else
typedef NS_ENUM(NSInteger, YGWrap) {
YGWrapNoWrap,
YGWrapWrap,
};
#endif
} YG_ENUM_END(YGWrap);
#define YGOverflowCount 3
#ifndef NS_ENUM
typedef enum YGOverflow {
typedef YG_ENUM_BEGIN(YGOverflow) {
YGOverflowVisible,
YGOverflowHidden,
YGOverflowScroll,
} YGOverflow;
#else
typedef NS_ENUM(NSInteger, YGOverflow) {
YGOverflowVisible,
YGOverflowHidden,
YGOverflowScroll,
};
#endif
} YG_ENUM_END(YGOverflow);
#define YGExperimentalFeatureCount 2
#ifndef NS_ENUM
typedef enum YGExperimentalFeature {
typedef YG_ENUM_BEGIN(YGExperimentalFeature) {
YGExperimentalFeatureRounding,
YGExperimentalFeatureWebFlexBasis,
} YGExperimentalFeature;
#else
typedef NS_ENUM(NSInteger, YGExperimentalFeature) {
YGExperimentalFeatureRounding,
YGExperimentalFeatureWebFlexBasis,
};
#endif
} YG_ENUM_END(YGExperimentalFeature);
#define YGAlignCount 5
#ifndef NS_ENUM
typedef enum YGAlign {
typedef YG_ENUM_BEGIN(YGAlign) {
YGAlignAuto,
YGAlignFlexStart,
YGAlignCenter,
YGAlignFlexEnd,
YGAlignStretch,
} YGAlign;
#else
typedef NS_ENUM(NSInteger, YGAlign) {
YGAlignAuto,
YGAlignFlexStart,
YGAlignCenter,
YGAlignFlexEnd,
YGAlignStretch,
};
#endif
} YG_ENUM_END(YGAlign);
#define YGUnitCount 3
#ifndef NS_ENUM
typedef enum YGUnit {
typedef YG_ENUM_BEGIN(YGUnit) {
YGUnitUndefined,
YGUnitPixel,
YGUnitPercent,
} YGUnit;
#else
typedef NS_ENUM(NSInteger, YGUnit) {
YGUnitUndefined,
YGUnitPixel,
YGUnitPercent,
};
#endif
} YG_ENUM_END(YGUnit);
YG_EXTERN_C_END

View File

@@ -40,3 +40,19 @@
YG_ABORT(); \
}
#endif
#ifndef YG_ENUM_BEGIN
#ifndef NS_ENUM
#define YG_ENUM_BEGIN(name) enum name
#else
#define YG_ENUM_BEGIN(name) NS_ENUM(NSInteger, name)
#endif
#endif
#ifndef YG_ENUM_END
#ifndef NS_ENUM
#define YG_ENUM_END(name) name
#else
#define YG_ENUM_END(name)
#endif
#endif

View File

@@ -1,19 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#pragma once
YG_EXTERN_C_BEGIN
typedef struct YGValue {
float value;
YGUnit unit;
} YGValue;
YG_EXTERN_C_END

View File

@@ -30,7 +30,6 @@ static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
#include "YGEnums.h"
#include "YGMacros.h"
#include "YGValue.h"
YG_EXTERN_C_BEGIN
@@ -39,6 +38,11 @@ typedef struct YGSize {
float height;
} YGSize;
typedef struct YGValue {
float value;
YGUnit unit;
} YGValue;
typedef struct YGNode *YGNodeRef;
typedef YGSize (*YGMeasureFunc)(YGNodeRef node,
float width,