Rename YGUnitPixel to YGPoint... #375

Closed
hartbit wants to merge 1 commits from pixel-to-point into master
17 changed files with 186 additions and 165 deletions
Showing only changes of commit 9f192b0372 - Show all commits

View File

@@ -25,7 +25,7 @@
- (CGFloat)lowercased_name \ - (CGFloat)lowercased_name \
{ \ { \
YGValue value = YGNodeStyleGet##capitalized_name(self.node); \ YGValue value = YGNodeStyleGet##capitalized_name(self.node); \
if (value.unit == YGUnitPixel) { \ if (value.unit == YGUnitPoint) { \
return value.value; \ return value.value; \
} else { \ } else { \
return YGUndefined; \ return YGUndefined; \
@@ -67,7 +67,7 @@ YG_EDGE_PROPERTY_SETTER(lowercased_name, capitalized_name, property, edge)
- (CGFloat)objc_lowercased_name \ - (CGFloat)objc_lowercased_name \
{ \ { \
YGValue value = YGNodeStyleGet##c_name(self.node, edge); \ YGValue value = YGNodeStyleGet##c_name(self.node, edge); \
if (value.unit == YGUnitPixel) { \ if (value.unit == YGUnitPoint) { \
return value.value; \ return value.value; \
} else { \ } else { \
return YGUndefined; \ return YGUndefined; \
@@ -353,7 +353,7 @@ static void YGRemoveAllChildren(const YGNodeRef node)
} }
} }
static CGFloat YGRoundPixelValue(CGFloat value) static CGFloat YGRoundPointValue(CGFloat value)
{ {
static CGFloat scale; static CGFloat scale;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
@@ -387,12 +387,12 @@ static void YGApplyLayoutToViewHierarchy(UIView *view)
view.frame = (CGRect) { view.frame = (CGRect) {
.origin = { .origin = {
.x = YGRoundPixelValue(topLeft.x), .x = YGRoundPointValue(topLeft.x),
.y = YGRoundPixelValue(topLeft.y), .y = YGRoundPointValue(topLeft.y),
}, },
.size = { .size = {
.width = YGRoundPixelValue(bottomRight.x) - YGRoundPixelValue(topLeft.x), .width = YGRoundPointValue(bottomRight.x) - YGRoundPointValue(topLeft.x),
.height = YGRoundPixelValue(bottomRight.y) - YGRoundPixelValue(topLeft.y), .height = YGRoundPointValue(bottomRight.y) - YGRoundPointValue(topLeft.y),
}, },
}; };

View File

@@ -417,32 +417,32 @@
view.yoga.left = 1; view.yoga.left = 1;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeLeft).value, 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); XCTAssertEqual(view.yoga.left, 1);
view.yoga.right = 2; view.yoga.right = 2;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeRight).value, 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); XCTAssertEqual(view.yoga.right, 2);
view.yoga.top = 3; view.yoga.top = 3;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeTop).value, 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); XCTAssertEqual(view.yoga.top, 3);
view.yoga.bottom = 4; view.yoga.bottom = 4;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeBottom).value, 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); XCTAssertEqual(view.yoga.bottom, 4);
view.yoga.start = 5; view.yoga.start = 5;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeStart).value, 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); XCTAssertEqual(view.yoga.start, 5);
view.yoga.end = 6; view.yoga.end = 6;
XCTAssertEqual(YGNodeStyleGetPosition(view.yoga.node, YGEdgeEnd).value, 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); XCTAssertEqual(view.yoga.end, 6);
} }
@@ -452,67 +452,67 @@
view.yoga.margin = 1; view.yoga.margin = 1;
XCTAssertEqual(view.yoga.marginLeft, 1); XCTAssertEqual(view.yoga.marginLeft, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.marginRight, 1); XCTAssertEqual(view.yoga.marginRight, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.marginStart, 1); XCTAssertEqual(view.yoga.marginStart, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.marginEnd, 1); XCTAssertEqual(view.yoga.marginEnd, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.marginTop, 1); XCTAssertEqual(view.yoga.marginTop, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.marginBottom, 1); XCTAssertEqual(view.yoga.marginBottom, 1);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPoint);
XCTAssertTrue(isnan(view.yoga.marginHorizontal)); XCTAssertTrue(isnan(view.yoga.marginHorizontal));
XCTAssertTrue(isnan(view.yoga.marginVertical)); XCTAssertTrue(isnan(view.yoga.marginVertical));
XCTAssertTrue(isnan(view.yoga.margin)); XCTAssertTrue(isnan(view.yoga.margin));
view.yoga.marginHorizontal = 2; view.yoga.marginHorizontal = 2;
XCTAssertEqual(view.yoga.marginLeft, 2); XCTAssertEqual(view.yoga.marginLeft, 2);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.marginRight, 2); XCTAssertEqual(view.yoga.marginRight, 2);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.marginStart, 2); XCTAssertEqual(view.yoga.marginStart, 2);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.marginEnd, 2); XCTAssertEqual(view.yoga.marginEnd, 2);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).unit, YGUnitPoint);
XCTAssertTrue(isnan(view.yoga.marginHorizontal)); XCTAssertTrue(isnan(view.yoga.marginHorizontal));
view.yoga.marginVertical = 3; view.yoga.marginVertical = 3;
XCTAssertEqual(view.yoga.marginTop, 3); XCTAssertEqual(view.yoga.marginTop, 3);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.marginBottom, 3); XCTAssertEqual(view.yoga.marginBottom, 3);
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).unit, YGUnitPoint);
XCTAssertTrue(isnan(view.yoga.marginVertical)); XCTAssertTrue(isnan(view.yoga.marginVertical));
view.yoga.marginLeft = 4; view.yoga.marginLeft = 4;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeLeft).value, 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); XCTAssertEqual(view.yoga.marginLeft, 4);
view.yoga.marginRight = 5; view.yoga.marginRight = 5;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeRight).value, 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); XCTAssertEqual(view.yoga.marginRight, 5);
view.yoga.marginTop = 6; view.yoga.marginTop = 6;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeTop).value, 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); XCTAssertEqual(view.yoga.marginTop, 6);
view.yoga.marginBottom = 7; view.yoga.marginBottom = 7;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeBottom).value, 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); XCTAssertEqual(view.yoga.marginBottom, 7);
view.yoga.marginStart = 8; view.yoga.marginStart = 8;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeStart).value, 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); XCTAssertEqual(view.yoga.marginStart, 8);
view.yoga.marginEnd = 9; view.yoga.marginEnd = 9;
XCTAssertEqual(YGNodeStyleGetMargin(view.yoga.node, YGEdgeEnd).value, 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); XCTAssertEqual(view.yoga.marginEnd, 9);
} }
@@ -522,67 +522,67 @@
view.yoga.padding = 1; view.yoga.padding = 1;
XCTAssertEqual(view.yoga.paddingLeft, 1); XCTAssertEqual(view.yoga.paddingLeft, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.paddingRight, 1); XCTAssertEqual(view.yoga.paddingRight, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.paddingStart, 1); XCTAssertEqual(view.yoga.paddingStart, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.paddingEnd, 1); XCTAssertEqual(view.yoga.paddingEnd, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.paddingTop, 1); XCTAssertEqual(view.yoga.paddingTop, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.paddingBottom, 1); XCTAssertEqual(view.yoga.paddingBottom, 1);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPoint);
XCTAssertTrue(isnan(view.yoga.paddingHorizontal)); XCTAssertTrue(isnan(view.yoga.paddingHorizontal));
XCTAssertTrue(isnan(view.yoga.paddingVertical)); XCTAssertTrue(isnan(view.yoga.paddingVertical));
XCTAssertTrue(isnan(view.yoga.padding)); XCTAssertTrue(isnan(view.yoga.padding));
view.yoga.paddingHorizontal = 2; view.yoga.paddingHorizontal = 2;
XCTAssertEqual(view.yoga.paddingLeft, 2); XCTAssertEqual(view.yoga.paddingLeft, 2);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.paddingRight, 2); XCTAssertEqual(view.yoga.paddingRight, 2);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.paddingStart, 2); XCTAssertEqual(view.yoga.paddingStart, 2);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.paddingEnd, 2); XCTAssertEqual(view.yoga.paddingEnd, 2);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).unit, YGUnitPoint);
XCTAssertTrue(isnan(view.yoga.paddingHorizontal)); XCTAssertTrue(isnan(view.yoga.paddingHorizontal));
view.yoga.paddingVertical = 3; view.yoga.paddingVertical = 3;
XCTAssertEqual(view.yoga.paddingTop, 3); XCTAssertEqual(view.yoga.paddingTop, 3);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).unit, YGUnitPoint);
XCTAssertEqual(view.yoga.paddingBottom, 3); XCTAssertEqual(view.yoga.paddingBottom, 3);
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPixel); XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).unit, YGUnitPoint);
XCTAssertTrue(isnan(view.yoga.paddingVertical)); XCTAssertTrue(isnan(view.yoga.paddingVertical));
view.yoga.paddingLeft = 4; view.yoga.paddingLeft = 4;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeLeft).value, 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); XCTAssertEqual(view.yoga.paddingLeft, 4);
view.yoga.paddingRight = 5; view.yoga.paddingRight = 5;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeRight).value, 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); XCTAssertEqual(view.yoga.paddingRight, 5);
view.yoga.paddingTop = 6; view.yoga.paddingTop = 6;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeTop).value, 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); XCTAssertEqual(view.yoga.paddingTop, 6);
view.yoga.paddingBottom = 7; view.yoga.paddingBottom = 7;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeBottom).value, 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); XCTAssertEqual(view.yoga.paddingBottom, 7);
view.yoga.paddingStart = 8; view.yoga.paddingStart = 8;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeStart).value, 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); XCTAssertEqual(view.yoga.paddingStart, 8);
view.yoga.paddingEnd = 9; view.yoga.paddingEnd = 9;
XCTAssertEqual(YGNodeStyleGetPadding(view.yoga.node, YGEdgeEnd).value, 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); XCTAssertEqual(view.yoga.paddingEnd, 9);
} }

View File

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

View File

@@ -33,12 +33,12 @@ namespace Facebook.Yoga
} }
} }
public static YogaValue Pixel(float value) public static YogaValue Point(float value)
{ {
return new YogaValue return new YogaValue
{ {
value = value, value = value,
unit = YogaConstants.IsUndefined(value) ? YogaUnit.Undefined : YogaUnit.Pixel unit = YogaConstants.IsUndefined(value) ? YogaUnit.Undefined : YogaUnit.Point
}; };
} }
@@ -79,9 +79,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); 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) public static YogaValue Percent(this int value)
@@ -26,9 +26,9 @@ namespace Facebook.Yoga
return YogaValue.Percent(value); 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; return Math.Round(value * scale) / scale;
} }

View File

@@ -30,7 +30,7 @@ namespace Facebook.YogaKit
{ {
var topLeft = new CGPoint(node.LayoutX, node.LayoutY); var topLeft = new CGPoint(node.LayoutX, node.LayoutY);
var bottomRight = new CGPoint(topLeft.X + node.LayoutWidth, topLeft.Y + node.LayoutHeight); 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; bool _disposed;

View File

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

View File

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

View File

@@ -14,7 +14,7 @@ import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip @DoNotStrip
public interface YogaBaselineFunction { 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. * default to the computed height of the node.
*/ */
@DoNotStrip @DoNotStrip

View File

@@ -14,7 +14,7 @@ import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip @DoNotStrip
public enum YogaUnit { public enum YogaUnit {
UNDEFINED(0), UNDEFINED(0),
PIXEL(1), POINT(1),
PERCENT(2); PERCENT(2);
private int mIntValue; private int mIntValue;
@@ -30,7 +30,7 @@ public enum YogaUnit {
public static YogaUnit fromInt(int value) { public static YogaUnit fromInt(int value) {
switch (value) { switch (value) {
case 0: return UNDEFINED; case 0: return UNDEFINED;
case 1: return PIXEL; case 1: return POINT;
case 2: return PERCENT; case 2: return PERCENT;
default: throw new IllegalArgumentException("Unknown enum value: " + value); default: throw new IllegalArgumentException("Unknown enum value: " + value);
} }

View File

@@ -14,7 +14,7 @@ import com.facebook.proguard.annotations.DoNotStrip;
@DoNotStrip @DoNotStrip
public class YogaValue { public class YogaValue {
static final YogaValue UNDEFINED = new YogaValue(YogaConstants.UNDEFINED, YogaUnit.UNDEFINED); 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 float value;
public final YogaUnit unit; public final YogaUnit unit;

View File

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

View File

@@ -102,7 +102,7 @@ module.exports = function (bind, lib) {
switch (this.unit) { switch (this.unit) {
case constants.UNIT_PIXEL: case constants.UNIT_POINT:
return `${this.value}`; return `${this.value}`;
case constants.UNIT_PERCENT: case constants.UNIT_PERCENT:
@@ -126,7 +126,7 @@ module.exports = function (bind, lib) {
for (let fnName of [ `setPosition`, `setMargin`, `setFlexBasis`, `setWidth`, `setHeight`, `setMinWidth`, `setMinHeight`, `setMaxWidth`, `setMaxHeight`, `setPadding` ]) { 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)) if (Object.keys(methods).some(method => methods[method] == null))
throw new Error(`Assertion failed; some unit derivates of ${fnName} seem missing`); throw new Error(`Assertion failed; some unit derivates of ${fnName} seem missing`);
@@ -146,7 +146,7 @@ module.exports = function (bind, lib) {
} else { } 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); asNumber = parseFloat(value);
} }

View File

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

View File

@@ -188,7 +188,7 @@ YGCalloc gYGCalloc = &calloc;
YGRealloc gYGRealloc = &realloc; YGRealloc gYGRealloc = &realloc;
YGFree gYGFree = &free; YGFree gYGFree = &free;
static YGValue YGValueZero = {.value = 0, .unit = YGUnitPixel}; static YGValue YGValueZero = {.value = 0, .unit = YGUnitPoint};
#ifdef ANDROID #ifdef ANDROID
#include <android/log.h> #include <android/log.h>
@@ -265,7 +265,7 @@ static inline float YGValueResolve(const YGValue *const value, const float paren
switch (value->unit) { switch (value->unit) {
case YGUnitUndefined: case YGUnitUndefined:
return YGUndefined; return YGUndefined;
case YGUnitPixel: case YGUnitPoint:
return value->value; return value->value;
case YGUnitPercent: case YGUnitPercent:
return value->value * parentSize / 100.0f; return value->value * parentSize / 100.0f;
@@ -462,10 +462,10 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
#define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL(type, name, paramName, instanceName) \ #define YG_NODE_STYLE_PROPERTY_SETTER_UNIT_IMPL(type, name, paramName, instanceName) \
void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \ void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
if (node->style.instanceName.value != 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.value = paramName; \
node->style.instanceName.unit = \ node->style.instanceName.unit = \
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPixel; \ YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint; \
YGNodeMarkDirtyInternal(node); \ YGNodeMarkDirtyInternal(node); \
} \ } \
} \ } \
@@ -497,10 +497,10 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
#define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(type, name, paramName, instanceName) \ #define YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(type, name, paramName, instanceName) \
void YGNodeStyleSet##name(const YGNodeRef node, const YGEdge edge, const float paramName) { \ void YGNodeStyleSet##name(const YGNodeRef node, const YGEdge edge, const float paramName) { \
if (node->style.instanceName[edge].value != 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].value = paramName; \
node->style.instanceName[edge].unit = \ node->style.instanceName[edge].unit = \
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPixel; \ YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint; \
YGNodeMarkDirtyInternal(node); \ YGNodeMarkDirtyInternal(node); \
} \ } \
} \ } \
@@ -524,10 +524,10 @@ void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
#define YG_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName) \ #define YG_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName) \
void YGNodeStyleSet##name(const YGNodeRef node, const YGEdge edge, const float paramName) { \ void YGNodeStyleSet##name(const YGNodeRef node, const YGEdge edge, const float paramName) { \
if (node->style.instanceName[edge].value != 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].value = paramName; \
node->style.instanceName[edge].unit = \ node->style.instanceName[edge].unit = \
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPixel; \ YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint; \
YGNodeMarkDirtyInternal(node); \ YGNodeMarkDirtyInternal(node); \
} \ } \
} \ } \
@@ -671,7 +671,7 @@ static void YGPrintNumberIfNotZero(const char *str, const YGValue *const number)
"%s: %g%s, ", "%s: %g%s, ",
str, str,
number->value, number->value,
number->unit == YGUnitPixel ? "px" : "%"); number->unit == YGUnitPoint ? "pt" : "%");
} }
} }
@@ -687,7 +687,7 @@ static void YGPrintNumberIfNotUndefined(const char *str, const YGValue *const nu
"%s: %g%s, ", "%s: %g%s, ",
str, str,
number->value, number->value,
number->unit == YGUnitPixel ? "px" : "%"); number->unit == YGUnitPoint ? "pt" : "%");
} }
} }
@@ -1098,7 +1098,7 @@ static inline bool YGNodeIsStyleDimDefined(const YGNodeRef node,
const YGFlexDirection axis, const YGFlexDirection axis,
const float parentSize) { const float parentSize) {
return !(node->resolvedDimensions[dim[axis]].unit == YGUnitUndefined || return !(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]].value < 0.0f) ||
(node->resolvedDimensions[dim[axis]].unit == YGUnitPercent && (node->resolvedDimensions[dim[axis]].unit == YGUnitPercent &&
YGFloatIsUndefined(parentSize))); YGFloatIsUndefined(parentSize)));
@@ -1723,11 +1723,11 @@ static void YGZeroOutLayoutRecursivly(const YGNodeRef node) {
// the width/height attributes. // the width/height attributes.
// flex: -1 (or any negative value) is equivalent to flex: 0 1 auto // 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 // * Margins cannot be specified as 'auto'. They must be specified in terms of
// pixel // points
// values, and the default value is 0. // values, and the default value is 0.
// * Values of width, maxWidth, minWidth, height, maxHeight and minHeight must // * Values of width, maxWidth, minWidth, height, maxHeight and minHeight must
// be // 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 // * There is no support for calculation of dimensions based on intrinsic
// aspect ratios // aspect ratios
// (e.g. images). // (e.g. images).
@@ -2122,7 +2122,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
// based on its // based on its
// content. // content.
// sizeConsumedOnCurrentLine is negative which means the node will // sizeConsumedOnCurrentLine is negative which means the node will
// allocate 0 pixels for // allocate 0 points for
// its content. Consequently, remainingFreeSpace is 0 - // its content. Consequently, remainingFreeSpace is 0 -
// sizeConsumedOnCurrentLine. // sizeConsumedOnCurrentLine.
remainingFreeSpace = -sizeConsumedOnCurrentLine; remainingFreeSpace = -sizeConsumedOnCurrentLine;
@@ -3144,7 +3144,7 @@ bool YGLayoutNodeInternal(const YGNodeRef node,
return (needToVisitNode || cachedResults == NULL); return (needToVisitNode || cachedResults == NULL);
} }
static void roundToPixelGrid(const YGNodeRef node) { static void roundToPointGrid(const YGNodeRef node) {
const float fractialLeft = const float fractialLeft =
node->layout.position[YGEdgeLeft] - floorf(node->layout.position[YGEdgeLeft]); node->layout.position[YGEdgeLeft] - floorf(node->layout.position[YGEdgeLeft]);
const float fractialTop = const float fractialTop =
@@ -3159,7 +3159,7 @@ static void roundToPixelGrid(const YGNodeRef node) {
const uint32_t childCount = YGNodeListCount(node->children); const uint32_t childCount = YGNodeListCount(node->children);
for (uint32_t i = 0; i < childCount; i++) { for (uint32_t i = 0; i < childCount; i++) {
roundToPixelGrid(YGNodeGetChild(node, i)); roundToPointGrid(YGNodeGetChild(node, i));
} }
} }
@@ -3219,7 +3219,7 @@ void YGNodeCalculateLayout(const YGNodeRef node,
YGNodeSetPosition(node, node->layout.direction, availableWidth, availableHeight, availableWidth); YGNodeSetPosition(node, node->layout.direction, availableWidth, availableHeight, availableWidth);
if (YGIsExperimentalFeatureEnabled(YGExperimentalFeatureRounding)) { if (YGIsExperimentalFeatureEnabled(YGExperimentalFeatureRounding)) {
roundToPixelGrid(node); roundToPointGrid(node);
} }
if (gPrintTree) { if (gPrintTree) {

View File

@@ -200,7 +200,7 @@ YG_NODE_LAYOUT_PROPERTY(float, Height);
YG_NODE_LAYOUT_PROPERTY(YGDirection, Direction); YG_NODE_LAYOUT_PROPERTY(YGDirection, Direction);
// Get the computed values for these nodes after performing layout. If they were set using // 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 // they were set using a percentage value then the returned value is the computed value used
// during layout. // during layout.
YG_NODE_LAYOUT_EDGE_PROPERTY(float, Margin); YG_NODE_LAYOUT_EDGE_PROPERTY(float, Margin);