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
This commit is contained in:
David Hart 2017-02-14 14:26:13 -08:00 committed by Facebook Github Bot
parent dbaa687518
commit 67f6b32409
12 changed files with 36 additions and 36 deletions

View File

@ -32,7 +32,7 @@
- (void)testNumberPoints
{
YGValue value = [RCTConvert YGValue:@100];
XCTAssertEqual(value.unit, YGUnitPixel);
XCTAssertEqual(value.unit, YGUnitPoint);
XCTAssertEqual(value.value, 100);
}

View File

@ -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:@"%"]) {

View File

@ -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
);
}

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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 <android/log.h>
@ -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) {

View File

@ -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);