From 67f6b32409f78cb1d5bb6a4dc5cf35a27692b08d Mon Sep 17 00:00:00 2001 From: David Hart Date: Tue, 14 Feb 2017 14:26:13 -0800 Subject: [PATCH] Rename YGUnitPixel to YGPoint... Summary: ...to reflect the modern world we live in with dynamic DPI platforms :) Closes https://github.com/facebook/yoga/pull/375 Reviewed By: dshahidehpour Differential Revision: D4528518 Pulled By: emilsjolander fbshipit-source-id: e422bd4ae148e02c598a7b484a6adfa8c0e1e0c9 --- .../RCTConvert_YGValueTests.m | 2 +- React/Base/RCTConvert.m | 2 +- React/Views/RCTShadowView.m | 12 +++--- .../flat/FlatARTSurfaceViewShadowNode.java | 2 +- .../react/flat/FlatReactModalShadowNode.java | 2 +- .../react/flat/NativeViewWrapper.java | 2 +- .../facebook/yoga/YogaBaselineFunction.java | 2 +- .../main/java/com/facebook/yoga/YogaUnit.java | 4 +- .../java/com/facebook/yoga/YogaValue.java | 2 +- ReactCommon/yoga/yoga/YGEnums.h | 2 +- ReactCommon/yoga/yoga/Yoga.c | 38 +++++++++---------- ReactCommon/yoga/yoga/Yoga.h | 2 +- 12 files changed, 36 insertions(+), 36 deletions(-) diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTConvert_YGValueTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTConvert_YGValueTests.m index ac476ab48..3b6f64f58 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTConvert_YGValueTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTConvert_YGValueTests.m @@ -32,7 +32,7 @@ - (void)testNumberPoints { YGValue value = [RCTConvert YGValue:@100]; - XCTAssertEqual(value.unit, YGUnitPixel); + XCTAssertEqual(value.unit, YGUnitPoint); XCTAssertEqual(value.value, 100); } diff --git a/React/Base/RCTConvert.m b/React/Base/RCTConvert.m index 4d842904e..d8a0e9df2 100644 --- a/React/Base/RCTConvert.m +++ b/React/Base/RCTConvert.m @@ -504,7 +504,7 @@ RCT_CGSTRUCT_CONVERTER(CGAffineTransform, (@[ if (!json) { return YGValueUndefined; } else if ([json isKindOfClass:[NSNumber class]]) { - return (YGValue) { [json floatValue], YGUnitPixel }; + return (YGValue) { [json floatValue], YGUnitPoint }; } else if ([json isKindOfClass:[NSString class]]) { NSString *s = (NSString *) json; if ([s hasSuffix:@"%"]) { diff --git a/React/Views/RCTShadowView.m b/React/Views/RCTShadowView.m index f38844c09..ed5228d8f 100644 --- a/React/Views/RCTShadowView.m +++ b/React/Views/RCTShadowView.m @@ -61,7 +61,7 @@ switch (ygvalue.unit) { \ case YGUnitUndefined: \ setter(__VA_ARGS__, YGUndefined); \ break; \ - case YGUnitPixel: \ + case YGUnitPoint: \ setter(__VA_ARGS__, ygvalue.value); \ break; \ case YGUnitPercent: \ @@ -136,9 +136,9 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT], #if RCT_DEBUG // This works around a breaking change in css-layout where setting flexBasis needs to be set explicitly, instead of relying on flex to propagate. // We check for it by seeing if a width/height is provided along with a flexBasis of 0 and the width/height is laid out as 0. - if (YGNodeStyleGetFlexBasis(node).unit == YGUnitPixel && YGNodeStyleGetFlexBasis(node).value == 0 && - ((YGNodeStyleGetWidth(node).unit == YGUnitPixel && YGNodeStyleGetWidth(node).value > 0 && YGNodeLayoutGetWidth(node) == 0) || - (YGNodeStyleGetHeight(node).unit == YGUnitPixel && YGNodeStyleGetHeight(node).value > 0 && YGNodeLayoutGetHeight(node) == 0))) { + if (YGNodeStyleGetFlexBasis(node).unit == YGUnitPoint && YGNodeStyleGetFlexBasis(node).value == 0 && + ((YGNodeStyleGetWidth(node).unit == YGUnitPoint && YGNodeStyleGetWidth(node).value > 0 && YGNodeLayoutGetWidth(node) == 0) || + (YGNodeStyleGetHeight(node).unit == YGUnitPoint && YGNodeStyleGetHeight(node).value > 0 && YGNodeLayoutGetHeight(node) == 0))) { RCTLogError(@"View was rendered with explicitly set width/height but with a 0 flexBasis. (This might be fixed by changing flex: to flexGrow:) View: %@", self); } #endif @@ -565,8 +565,8 @@ RCT_POSITION_PROPERTY(Left, left, YGEdgeStart) YGValue height = YGNodeStyleGetHeight(_cssNode); return CGSizeMake( - width.unit == YGUnitPixel ? width.value : NAN, - height.unit == YGUnitPixel ? height.value : NAN + width.unit == YGUnitPoint ? width.value : NAN, + height.unit == YGUnitPoint ? height.value : NAN ); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatARTSurfaceViewShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatARTSurfaceViewShadowNode.java index 6b3c72fc2..64a127538 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatARTSurfaceViewShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatARTSurfaceViewShadowNode.java @@ -107,7 +107,7 @@ import com.facebook.yoga.YogaUnit; @Override public void setPadding(int spacingType, float padding) { YogaValue current = getStylePadding(spacingType); - if (current.unit != YogaUnit.PIXEL || current.value != padding) { + if (current.unit != YogaUnit.POINT || current.value != padding) { super.setPadding(spacingType, padding); mPaddingChanged = true; markUpdated(); diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatReactModalShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatReactModalShadowNode.java index 138262a64..fbe1cd8c2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatReactModalShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatReactModalShadowNode.java @@ -89,7 +89,7 @@ class FlatReactModalShadowNode extends FlatShadowNode implements AndroidView { @Override public void setPadding(int spacingType, float padding) { YogaValue current = getStylePadding(spacingType); - if (current.unit != YogaUnit.PIXEL || current.value != padding) { + if (current.unit != YogaUnit.POINT || current.value != padding) { super.setPadding(spacingType, padding); mPaddingChanged = true; markUpdated(); diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/NativeViewWrapper.java b/ReactAndroid/src/main/java/com/facebook/react/flat/NativeViewWrapper.java index 62099e0d0..b5b23913d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/NativeViewWrapper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/NativeViewWrapper.java @@ -104,7 +104,7 @@ import com.facebook.yoga.YogaUnit; @Override public void setPadding(int spacingType, float padding) { YogaValue current = getStylePadding(spacingType); - if (current.unit != YogaUnit.PIXEL || current.value != padding) { + if (current.unit != YogaUnit.POINT || current.value != padding) { super.setPadding(spacingType, padding); mPaddingChanged = true; markUpdated(); diff --git a/ReactAndroid/src/main/java/com/facebook/yoga/YogaBaselineFunction.java b/ReactAndroid/src/main/java/com/facebook/yoga/YogaBaselineFunction.java index 1bfb52a71..60de81c56 100644 --- a/ReactAndroid/src/main/java/com/facebook/yoga/YogaBaselineFunction.java +++ b/ReactAndroid/src/main/java/com/facebook/yoga/YogaBaselineFunction.java @@ -14,7 +14,7 @@ import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip public interface YogaBaselineFunction { /** - * Return the baseline of the node in pixels. When no baseline function is set the baseline + * Return the baseline of the node in points. When no baseline function is set the baseline * default to the computed height of the node. */ @DoNotStrip diff --git a/ReactAndroid/src/main/java/com/facebook/yoga/YogaUnit.java b/ReactAndroid/src/main/java/com/facebook/yoga/YogaUnit.java index 2fd6655b1..f7b34369e 100644 --- a/ReactAndroid/src/main/java/com/facebook/yoga/YogaUnit.java +++ b/ReactAndroid/src/main/java/com/facebook/yoga/YogaUnit.java @@ -14,7 +14,7 @@ import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip public enum YogaUnit { UNDEFINED(0), - PIXEL(1), + POINT(1), PERCENT(2), AUTO(3); @@ -31,7 +31,7 @@ public enum YogaUnit { public static YogaUnit fromInt(int value) { switch (value) { case 0: return UNDEFINED; - case 1: return PIXEL; + case 1: return POINT; case 2: return PERCENT; case 3: return AUTO; default: throw new IllegalArgumentException("Unknown enum value: " + value); diff --git a/ReactAndroid/src/main/java/com/facebook/yoga/YogaValue.java b/ReactAndroid/src/main/java/com/facebook/yoga/YogaValue.java index f9c0ebfc4..c1741a789 100644 --- a/ReactAndroid/src/main/java/com/facebook/yoga/YogaValue.java +++ b/ReactAndroid/src/main/java/com/facebook/yoga/YogaValue.java @@ -14,7 +14,7 @@ import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip public class YogaValue { static final YogaValue UNDEFINED = new YogaValue(YogaConstants.UNDEFINED, YogaUnit.UNDEFINED); - static final YogaValue ZERO = new YogaValue(0, YogaUnit.PIXEL); + static final YogaValue ZERO = new YogaValue(0, YogaUnit.POINT); public final float value; public final YogaUnit unit; diff --git a/ReactCommon/yoga/yoga/YGEnums.h b/ReactCommon/yoga/yoga/YGEnums.h index 74ec96cc0..f25343340 100644 --- a/ReactCommon/yoga/yoga/YGEnums.h +++ b/ReactCommon/yoga/yoga/YGEnums.h @@ -119,7 +119,7 @@ typedef YG_ENUM_BEGIN(YGPrintOptions) { #define YGUnitCount 4 typedef YG_ENUM_BEGIN(YGUnit) { YGUnitUndefined, - YGUnitPixel, + YGUnitPoint, YGUnitPercent, YGUnitAuto, } YG_ENUM_END(YGUnit); diff --git a/ReactCommon/yoga/yoga/Yoga.c b/ReactCommon/yoga/yoga/Yoga.c index 7123b5b44..e5b765155 100644 --- a/ReactCommon/yoga/yoga/Yoga.c +++ b/ReactCommon/yoga/yoga/Yoga.c @@ -195,7 +195,7 @@ YGCalloc gYGCalloc = &calloc; YGRealloc gYGRealloc = &realloc; YGFree gYGFree = &free; -static YGValue YGValueZero = {.value = 0, .unit = YGUnitPixel}; +static YGValue YGValueZero = {.value = 0, .unit = YGUnitPoint}; #ifdef ANDROID #include @@ -273,7 +273,7 @@ static inline float YGValueResolve(const YGValue *const value, const float paren case YGUnitUndefined: case YGUnitAuto: return YGUndefined; - case YGUnitPixel: + case YGUnitPoint: return value->value; case YGUnitPercent: return value->value * parentSize / 100.0f; @@ -474,10 +474,10 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { #define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL(type, name, paramName, instanceName) \ void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \ if (node->style.instanceName.value != paramName || \ - node->style.instanceName.unit != YGUnitPixel) { \ + node->style.instanceName.unit != YGUnitPoint) { \ node->style.instanceName.value = paramName; \ node->style.instanceName.unit = \ - YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPixel; \ + YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint; \ YGNodeMarkDirtyInternal(node); \ } \ } \ @@ -495,9 +495,9 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { #define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_AUTO_IMPL(type, name, paramName, instanceName) \ void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \ if (node->style.instanceName.value != paramName || \ - node->style.instanceName.unit != YGUnitPixel) { \ + node->style.instanceName.unit != YGUnitPoint) { \ node->style.instanceName.value = YGFloatIsUndefined(paramName) ? YGUndefined : paramName; \ - node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPixel; \ + node->style.instanceName.unit = YGFloatIsUndefined(paramName) ? YGUnitAuto : YGUnitPoint; \ YGNodeMarkDirtyInternal(node); \ } \ } \ @@ -552,10 +552,10 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { #define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(type, name, paramName, instanceName) \ void YGNodeStyleSet##name(const YGNodeRef node, const YGEdge edge, const float paramName) { \ if (node->style.instanceName[edge].value != paramName || \ - node->style.instanceName[edge].unit != YGUnitPixel) { \ + node->style.instanceName[edge].unit != YGUnitPoint) { \ node->style.instanceName[edge].value = paramName; \ node->style.instanceName[edge].unit = \ - YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPixel; \ + YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint; \ YGNodeMarkDirtyInternal(node); \ } \ } \ @@ -579,10 +579,10 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { #define YG_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName) \ void YGNodeStyleSet##name(const YGNodeRef node, const YGEdge edge, const float paramName) { \ if (node->style.instanceName[edge].value != paramName || \ - node->style.instanceName[edge].unit != YGUnitPixel) { \ + node->style.instanceName[edge].unit != YGUnitPoint) { \ node->style.instanceName[edge].value = paramName; \ node->style.instanceName[edge].unit = \ - YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPixel; \ + YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint; \ YGNodeMarkDirtyInternal(node); \ } \ } \ @@ -725,7 +725,7 @@ static void YGPrintNumberIfNotZero(const char *str, const YGValue *const number) "%s: %g%s, ", str, number->value, - number->unit == YGUnitPixel ? "px" : "%"); + number->unit == YGUnitPoint ? "pt" : "%"); } } @@ -741,7 +741,7 @@ static void YGPrintNumberIfNotUndefined(const char *str, const YGValue *const nu "%s: %g%s, ", str, number->value, - number->unit == YGUnitPixel ? "px" : "%"); + number->unit == YGUnitPoint ? "pt" : "%"); } } @@ -1153,7 +1153,7 @@ static inline bool YGNodeIsStyleDimDefined(const YGNodeRef node, const float parentSize) { return !(node->resolvedDimensions[dim[axis]]->unit == YGUnitAuto || node->resolvedDimensions[dim[axis]]->unit == YGUnitUndefined || - (node->resolvedDimensions[dim[axis]]->unit == YGUnitPixel && + (node->resolvedDimensions[dim[axis]]->unit == YGUnitPoint && node->resolvedDimensions[dim[axis]]->value < 0.0f) || (node->resolvedDimensions[dim[axis]]->unit == YGUnitPercent && (node->resolvedDimensions[dim[axis]]->value < 0.0f || YGFloatIsUndefined(parentSize)))); @@ -1775,11 +1775,11 @@ static void YGZeroOutLayoutRecursivly(const YGNodeRef node) { // the width/height attributes. // flex: -1 (or any negative value) is equivalent to flex: 0 1 auto // * Margins cannot be specified as 'auto'. They must be specified in terms of -// pixel +// points // values, and the default value is 0. // * Values of width, maxWidth, minWidth, height, maxHeight and minHeight must // be -// specified as pixel values, not as percentages. +// specified as point values, not as percentages. // * There is no support for calculation of dimensions based on intrinsic // aspect ratios // (e.g. images). @@ -2186,7 +2186,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, // based on its // content. // sizeConsumedOnCurrentLine is negative which means the node will - // allocate 0 pixels for + // allocate 0 points for // its content. Consequently, remainingFreeSpace is 0 - // sizeConsumedOnCurrentLine. remainingFreeSpace = -sizeConsumedOnCurrentLine; @@ -3286,7 +3286,7 @@ bool YGLayoutNodeInternal(const YGNodeRef node, return (needToVisitNode || cachedResults == NULL); } -static void roundToPixelGrid(const YGNodeRef node) { +static void YGRoundToPixelGrid(const YGNodeRef node) { const float fractialLeft = node->layout.position[YGEdgeLeft] - floorf(node->layout.position[YGEdgeLeft]); const float fractialTop = @@ -3301,7 +3301,7 @@ static void roundToPixelGrid(const YGNodeRef node) { const uint32_t childCount = YGNodeListCount(node->children); for (uint32_t i = 0; i < childCount; i++) { - roundToPixelGrid(YGNodeGetChild(node, i)); + YGRoundToPixelGrid(YGNodeGetChild(node, i)); } } @@ -3360,7 +3360,7 @@ void YGNodeCalculateLayout(const YGNodeRef node, YGNodeSetPosition(node, node->layout.direction, availableWidth, availableHeight, availableWidth); if (YGIsExperimentalFeatureEnabled(YGExperimentalFeatureRounding)) { - roundToPixelGrid(node); + YGRoundToPixelGrid(node); } if (gPrintTree) { diff --git a/ReactCommon/yoga/yoga/Yoga.h b/ReactCommon/yoga/yoga/Yoga.h index 858a29146..4969f17c1 100644 --- a/ReactCommon/yoga/yoga/Yoga.h +++ b/ReactCommon/yoga/yoga/Yoga.h @@ -209,7 +209,7 @@ YG_NODE_LAYOUT_PROPERTY(float, Height); YG_NODE_LAYOUT_PROPERTY(YGDirection, Direction); // Get the computed values for these nodes after performing layout. If they were set using -// pixel values then the returned value will be the same as YGNodeStyleGetXXX. However if +// point values then the returned value will be the same as YGNodeStyleGetXXX. However if // they were set using a percentage value then the returned value is the computed value used // during layout. YG_NODE_LAYOUT_EDGE_PROPERTY(float, Margin);