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 1146013e9e
commit 9d2839f8ca
18 changed files with 96 additions and 96 deletions

View File

@@ -25,7 +25,7 @@
- (CGFloat)lowercased_name \
{ \
YGValue value = YGNodeStyleGet##capitalized_name(self.node); \
if (value.unit == YGUnitPixel) { \
if (value.unit == YGUnitPoint) { \
return value.value; \
} else { \
return YGUndefined; \
@@ -57,7 +57,7 @@ YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
- (CGFloat)objc_lowercased_name \
{ \
YGValue value = YGNodeStyleGet##c_name(self.node, edge); \
if (value.unit == YGUnitPixel) { \
if (value.unit == YGUnitPoint) { \
return value.value; \
} else { \
return YGUndefined; \

View File

@@ -479,32 +479,32 @@
view.yoga.left = 1;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeLeft).value, 1);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeLeft).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.left, 1);
view.yoga.right = 2;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeRight).value, 2);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeRight).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.right, 2);
view.yoga.top = 3;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeTop).value, 3);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeTop).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.top, 3);
view.yoga.bottom = 4;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeBottom).value, 4);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeBottom).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.bottom, 4);
view.yoga.start = 5;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeStart).value, 5);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeStart).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.start, 5);
view.yoga.end = 6;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeEnd).value, 6);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeEnd).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.end, 6);
}
@@ -537,32 +537,32 @@
view.yoga.marginLeft = 4;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).value, 4);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.marginLeft, 4);
view.yoga.marginRight = 5;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).value, 5);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.marginRight, 5);
view.yoga.marginTop = 6;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).value, 6);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.marginTop, 6);
view.yoga.marginBottom = 7;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).value, 7);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.marginBottom, 7);
view.yoga.marginStart = 8;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).value, 8);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.marginStart, 8);
view.yoga.marginEnd = 9;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).value, 9);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.marginEnd, 9);
}
@@ -595,32 +595,32 @@
view.yoga.paddingLeft = 4;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).value, 4);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.paddingLeft, 4);
view.yoga.paddingRight = 5;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).value, 5);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.paddingRight, 5);
view.yoga.paddingTop = 6;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).value, 6);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.paddingTop, 6);
view.yoga.paddingBottom = 7;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).value, 7);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.paddingBottom, 7);
view.yoga.paddingStart = 8;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).value, 8);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.paddingStart, 8);
view.yoga.paddingEnd = 9;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).value, 9);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.paddingEnd, 9);
}

View File

@@ -12,7 +12,7 @@ namespace Facebook.Yoga
public enum YogaUnit
{
Undefined,
Pixel,
Point,
Percent,
Auto,
}

View File

@@ -33,12 +33,12 @@ namespace Facebook.Yoga
}
}
public static YogaValue Pixel(float value)
public static YogaValue Point(float value)
{
return new YogaValue
{
value = value,
unit = YogaConstants.IsUndefined(value) ? YogaUnit.Undefined : YogaUnit.Pixel
unit = YogaConstants.IsUndefined(value) ? YogaUnit.Undefined : YogaUnit.Point
};
}
@@ -88,9 +88,9 @@ namespace Facebook.Yoga
};
}
public static implicit operator YogaValue(float pixelValue)
public static implicit operator YogaValue(float pointValue)
{
return Pixel(pixelValue);
return Point(pointValue);
}
}
}

View File

@@ -16,9 +16,9 @@ namespace Facebook.Yoga
return YogaValue.Percent(value);
}
public static YogaValue Px(this float value)
public static YogaValue Pt(this float value)
{
return YogaValue.Pixel(value);
return YogaValue.Point(value);
}
public static YogaValue Percent(this int value)
@@ -26,9 +26,9 @@ namespace Facebook.Yoga
return YogaValue.Percent(value);
}
public static YogaValue Px(this int value)
public static YogaValue Pt(this int value)
{
return YogaValue.Pixel(value);
return YogaValue.Point(value);
}
}
}

View File

@@ -854,9 +854,9 @@ namespace Facebook.YogaKit
}
}
static double RoundPixelValue(float value)
static double RoundPointValue(float value)
{
float scale = NativePixelScale;
float scale = NativePointScale;
return Math.Round(value * scale) / scale;
}

View File

@@ -30,7 +30,7 @@ namespace Facebook.YogaKit
{
var topLeft = new CGPoint(node.LayoutX, node.LayoutY);
var bottomRight = new CGPoint(topLeft.X + node.LayoutWidth, topLeft.Y + node.LayoutHeight);
view.Frame = new CGRect(RoundPixelValue((float)topLeft.X), RoundPixelValue((float)topLeft.Y), RoundPixelValue((float)bottomRight.X) - RoundPixelValue((float)topLeft.X), RoundPixelValue((float)bottomRight.Y) - RoundPixelValue((float)topLeft.Y));
view.Frame = new CGRect(RoundPointValue((float)topLeft.X), RoundPointValue((float)topLeft.Y), RoundPointValue((float)bottomRight.X) - RoundPointValue((float)topLeft.X), RoundPointValue((float)bottomRight.Y) - RoundPointValue((float)topLeft.Y));
}
bool _disposed;

View File

@@ -19,7 +19,7 @@ ENUMS = {
],
'Unit': [
'Undefined',
'Pixel',
'Point',
'Percent',
'Auto',
],

View File

@@ -201,105 +201,105 @@ function setupTestTree(e, parent, node, genericNode, nodeName, parentName, index
e.YGNodeStyleSetFlexShrink(nodeName, node.style[style]);
break;
case 'flex-basis':
e.YGNodeStyleSetFlexBasis(nodeName, pixelValue(e, node.style[style]));
e.YGNodeStyleSetFlexBasis(nodeName, pointValue(e, node.style[style]));
break;
case 'left':
if (genericNode.rawStyle.indexOf('start:') >= 0) {
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeStart, pixelValue(e, node.style[style]));
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeStart, pointValue(e, node.style[style]));
} else {
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeLeft, pixelValue(e, node.style[style]));
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeLeft, pointValue(e, node.style[style]));
}
break;
case 'top':
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeTop, pixelValue(e, node.style[style]));
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeTop, pointValue(e, node.style[style]));
break;
case 'right':
if (genericNode.rawStyle.indexOf('end:') >= 0) {
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeEnd, pixelValue(e, node.style[style]));
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeEnd, pointValue(e, node.style[style]));
} else {
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeRight, pixelValue(e, node.style[style]));
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeRight, pointValue(e, node.style[style]));
}
break;
case 'bottom':
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeBottom, pixelValue(e, node.style[style]));
e.YGNodeStyleSetPosition(nodeName, e.YGEdgeBottom, pointValue(e, node.style[style]));
break;
case 'margin-left':
if (genericNode.rawStyle.indexOf('margin-start:') >= 0) {
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeStart, pixelValue(e, node.style[style]));
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeStart, pointValue(e, node.style[style]));
} else {
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeLeft, pixelValue(e, node.style[style]));
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeLeft, pointValue(e, node.style[style]));
}
break;
case 'margin-top':
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeTop, pixelValue(e, node.style[style]));
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeTop, pointValue(e, node.style[style]));
break;
case 'margin-right':
if (genericNode.rawStyle.indexOf('margin-end:') >= 0) {
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeEnd, pixelValue(e, node.style[style]));
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeEnd, pointValue(e, node.style[style]));
} else {
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeRight, pixelValue(e, node.style[style]));
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeRight, pointValue(e, node.style[style]));
}
break;
case 'margin-bottom':
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeBottom, pixelValue(e, node.style[style]));
e.YGNodeStyleSetMargin(nodeName, e.YGEdgeBottom, pointValue(e, node.style[style]));
break;
case 'padding-left':
if (genericNode.rawStyle.indexOf('padding-start:') >= 0) {
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeStart, pixelValue(e, node.style[style]));
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeStart, pointValue(e, node.style[style]));
} else {
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeLeft, pixelValue(e, node.style[style]));
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeLeft, pointValue(e, node.style[style]));
}
break;
case 'padding-top':
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeTop, pixelValue(e, node.style[style]));
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeTop, pointValue(e, node.style[style]));
break;
case 'padding-right':
if (genericNode.rawStyle.indexOf('padding-end:') >= 0) {
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeEnd, pixelValue(e, node.style[style]));
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeEnd, pointValue(e, node.style[style]));
} else {
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeRight, pixelValue(e, node.style[style]));
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeRight, pointValue(e, node.style[style]));
}
break;
case 'padding-bottom':
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeBottom, pixelValue(e, node.style[style]));
e.YGNodeStyleSetPadding(nodeName, e.YGEdgeBottom, pointValue(e, node.style[style]));
break;
case 'border-left-width':
if (genericNode.rawStyle.indexOf('border-start-width:') >= 0) {
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeStart, pixelValue(e, node.style[style]));
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeStart, pointValue(e, node.style[style]));
} else {
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeLeft, pixelValue(e, node.style[style]));
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeLeft, pointValue(e, node.style[style]));
}
break;
case 'border-top-width':
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeTop, pixelValue(e, node.style[style]));
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeTop, pointValue(e, node.style[style]));
break;
case 'border-right-width':
if (genericNode.rawStyle.indexOf('border-end-width:') >= 0) {
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeEnd, pixelValue(e, node.style[style]));
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeEnd, pointValue(e, node.style[style]));
} else {
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeRight, pixelValue(e, node.style[style]));
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeRight, pointValue(e, node.style[style]));
}
break;
case 'border-bottom-width':
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeBottom, pixelValue(e, node.style[style]));
e.YGNodeStyleSetBorder(nodeName, e.YGEdgeBottom, pointValue(e, node.style[style]));
break;
case 'width':
e.YGNodeStyleSetWidth(nodeName, pixelValue(e, node.style[style]));
e.YGNodeStyleSetWidth(nodeName, pointValue(e, node.style[style]));
break;
case 'min-width':
e.YGNodeStyleSetMinWidth(nodeName, pixelValue(e, node.style[style]));
e.YGNodeStyleSetMinWidth(nodeName, pointValue(e, node.style[style]));
break;
case 'max-width':
e.YGNodeStyleSetMaxWidth(nodeName, pixelValue(e, node.style[style]));
e.YGNodeStyleSetMaxWidth(nodeName, pointValue(e, node.style[style]));
break;
case 'height':
e.YGNodeStyleSetHeight(nodeName, pixelValue(e, node.style[style]));
e.YGNodeStyleSetHeight(nodeName, pointValue(e, node.style[style]));
break;
case 'min-height':
e.YGNodeStyleSetMinHeight(nodeName, pixelValue(e, node.style[style]));
e.YGNodeStyleSetMinHeight(nodeName, pointValue(e, node.style[style]));
break;
case 'max-height':
e.YGNodeStyleSetMaxHeight(nodeName, pixelValue(e, node.style[style]));
e.YGNodeStyleSetMaxHeight(nodeName, pointValue(e, node.style[style]));
break;
case 'display':
e.YGNodeStyleSetDisplay(nodeName, displayValue(e, node.style[style]))
@@ -387,7 +387,7 @@ function alignValue(e, value) {
}
}
function pixelValue(e, value) {
function pointValue(e, value) {
switch (value) {
case 'auto': return e.YGAuto;
case 'undefined': return e.YGUndefined;

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

@@ -18,9 +18,9 @@ public class YogaValueTest {
@Test
public void testEquals() {
assertEquals(new YogaValue(0, YogaUnit.UNDEFINED), new YogaValue(0, YogaUnit.UNDEFINED));
assertEquals(new YogaValue(0, YogaUnit.PIXEL), new YogaValue(0, YogaUnit.PIXEL));
assertEquals(new YogaValue(0, YogaUnit.POINT), new YogaValue(0, YogaUnit.POINT));
assertEquals(new YogaValue(0, YogaUnit.PERCENT), new YogaValue(0, YogaUnit.PERCENT));
assertEquals(new YogaValue(0, YogaUnit.UNDEFINED), new YogaValue(1, YogaUnit.UNDEFINED));
assertEquals(new YogaValue(Float.NaN, YogaUnit.PIXEL), new YogaValue(Float.NaN, YogaUnit.PIXEL));
assertEquals(new YogaValue(Float.NaN, YogaUnit.POINT), new YogaValue(Float.NaN, YogaUnit.POINT));
}
}

View File

@@ -88,7 +88,7 @@ module.exports = {
UNIT_COUNT: 4,
UNIT_UNDEFINED: 0,
UNIT_PIXEL: 1,
UNIT_POINT: 1,
UNIT_PERCENT: 2,
UNIT_AUTO: 3,

View File

@@ -102,7 +102,7 @@ module.exports = function (bind, lib) {
switch (this.unit) {
case constants.UNIT_PIXEL:
case constants.UNIT_POINT:
return `${this.value}`;
case constants.UNIT_PERCENT:
@@ -129,7 +129,7 @@ module.exports = function (bind, lib) {
for (let fnName of [ `setPosition`, `setMargin`, `setFlexBasis`, `setWidth`, `setHeight`, `setMinWidth`, `setMinHeight`, `setMaxWidth`, `setMaxHeight`, `setPadding` ]) {
let methods = { [constants.UNIT_PIXEL]: lib.Node.prototype[fnName], [constants.UNIT_PERCENT]: lib.Node.prototype[`${fnName}Percent`] };
let methods = { [constants.UNIT_POINT]: lib.Node.prototype[fnName], [constants.UNIT_PERCENT]: lib.Node.prototype[`${fnName}Percent`] };
if (Object.keys(methods).some(method => methods[method] == null))
throw new Error(`Assertion failed; some unit derivates of ${fnName} seem missing`);
@@ -149,7 +149,7 @@ module.exports = function (bind, lib) {
} else {
unit = typeof value === `string` && value.endsWith(`%`) ? constants.UNIT_PERCENT : constants.UNIT_PIXEL;
unit = typeof value === `string` && value.endsWith(`%`) ? constants.UNIT_PERCENT : constants.UNIT_POINT;
asNumber = parseFloat(value);
}

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