diff --git a/csharp/Facebook.Yoga/YogaNode.Create.cs b/csharp/Facebook.Yoga/YogaNode.Create.cs index d40d9732..ee0726b5 100644 --- a/csharp/Facebook.Yoga/YogaNode.Create.cs +++ b/csharp/Facebook.Yoga/YogaNode.Create.cs @@ -31,12 +31,12 @@ namespace Facebook.Yoga Spacing margin = null, Spacing padding = null, Border border = null, - YogaValue? Width = null, - YogaValue? Height = null, - YogaValue? MaxWidth = null, - YogaValue? MaxHeight = null, - YogaValue? MinWidth = null, - YogaValue? MinHeight = null) + YogaValue? width = null, + YogaValue? height = null, + YogaValue? maxWidth = null, + YogaValue? maxHeight = null, + YogaValue? minWidth = null, + YogaValue? minHeight = null) { YogaNode node = new YogaNode(); @@ -197,34 +197,34 @@ namespace Facebook.Yoga } } - if (Width.HasValue) + if (width.HasValue) { - node.Width = Width.Value; + node.Width = width.Value; } - if (Height.HasValue) + if (height.HasValue) { - node.Height = Height.Value; + node.Height = height.Value; } - if (MinWidth.HasValue) + if (minWidth.HasValue) { - node.MinWidth = MinWidth.Value; + node.MinWidth = minWidth.Value; } - if (MinHeight.HasValue) + if (minHeight.HasValue) { - node.MinHeight = MinHeight.Value; + node.MinHeight = minHeight.Value; } - if (MaxWidth.HasValue) + if (maxWidth.HasValue) { - node.MaxWidth = MaxWidth.Value; + node.MaxWidth = maxWidth.Value; } - if (MaxHeight.HasValue) + if (maxHeight.HasValue) { - node.MaxHeight = MaxHeight.Value; + node.MaxHeight = maxHeight.Value; } return node; diff --git a/csharp/Facebook.Yoga/YogaValue.cs b/csharp/Facebook.Yoga/YogaValue.cs index 15d60e65..7e1acba8 100644 --- a/csharp/Facebook.Yoga/YogaValue.cs +++ b/csharp/Facebook.Yoga/YogaValue.cs @@ -16,7 +16,7 @@ namespace Facebook.Yoga { private float Value; private YogaUnit Unit; - private byte isDefined; + private byte isDefined; /* use byte to keep struct blitable */ public bool IsDefined => isDefined != 0; @@ -25,7 +25,7 @@ namespace Facebook.Yoga return new YogaValue { Value = value, - isDefined = 1, + isDefined = YogaConstants.IsUndefined(value) ? (byte)0 : (byte)1, Unit = YogaUnit.Pixel }; } @@ -49,12 +49,22 @@ namespace Facebook.Yoga } } + public static YogaValue Undefined() + { + return new YogaValue + { + Value = YogaConstants.Undefined, + isDefined = 0, + Unit = YogaUnit.Pixel + }; + } + public static YogaValue Percent(float value) { return new YogaValue { Value = value, - isDefined = 1, + isDefined = YogaConstants.IsUndefined(value) ? (byte)0 : (byte)1,, Unit = YogaUnit.Percent }; } diff --git a/tests/YGAspectRatioTest.cpp b/tests/YGAspectRatioTest.cpp index 22846c9b..7dd4ccc0 100644 --- a/tests/YGAspectRatioTest.cpp +++ b/tests/YGAspectRatioTest.cpp @@ -24,11 +24,11 @@ static YGSize _measure(YGNodeRef node, TEST(YogaTest, aspect_ratio_cross_defined) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetWidth(root_child0, YGPx(50)); YGNodeStyleSetAspectRatio(root_child0, 1); YGNodeInsertChild(root, root_child0, 0); @@ -45,11 +45,11 @@ TEST(YogaTest, aspect_ratio_cross_defined) { TEST(YogaTest, aspect_ratio_main_defined) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetHeight(root_child0, 50); + YGNodeStyleSetHeight(root_child0, YGPx(50)); YGNodeStyleSetAspectRatio(root_child0, 1); YGNodeInsertChild(root, root_child0, 0); @@ -65,11 +65,11 @@ TEST(YogaTest, aspect_ratio_main_defined) { TEST(YogaTest, aspect_ratio_both_dimensions_defined) { const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetHeight(root_child0, 50); + YGNodeStyleSetHeight(root_child0, YGPx(50)); YGNodeStyleSetAspectRatio(root_child0, 1); YGNodeInsertChild(root, root_child0, 0); @@ -85,8 +85,8 @@ TEST(YogaTest, aspect_ratio_both_dimensions_defined) { TEST(YogaTest, aspect_ratio_align_stretch) { const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); YGNodeStyleSetAspectRatio(root_child0, 1); @@ -105,11 +105,11 @@ TEST(YogaTest, aspect_ratio_align_stretch) { TEST(YogaTest, aspect_ratio_flex_grow) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetHeight(root_child0, 50); + YGNodeStyleSetHeight(root_child0, YGPx(50)); YGNodeStyleSetFlexGrow(root_child0, 1); YGNodeStyleSetAspectRatio(root_child0, 1); YGNodeInsertChild(root, root_child0, 0); @@ -127,11 +127,11 @@ TEST(YogaTest, aspect_ratio_flex_grow) { TEST(YogaTest, aspect_ratio_flex_shrink) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetHeight(root_child0, 150); + YGNodeStyleSetHeight(root_child0, YGPx(150)); YGNodeStyleSetFlexShrink(root_child0, 1); YGNodeStyleSetAspectRatio(root_child0, 1); YGNodeInsertChild(root, root_child0, 0); @@ -149,11 +149,11 @@ TEST(YogaTest, aspect_ratio_flex_shrink) { TEST(YogaTest, aspect_ratio_basis) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetFlexBasis(root_child0, 50); + YGNodeStyleSetFlexBasis(root_child0, YGPx(50)); YGNodeStyleSetAspectRatio(root_child0, 1); YGNodeInsertChild(root, root_child0, 0); @@ -169,14 +169,14 @@ TEST(YogaTest, aspect_ratio_basis) { TEST(YogaTest, aspect_ratio_absolute_layout_width_defined) { const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 0); - YGNodeStyleSetPosition(root_child0, YGEdgeTop, 0); - YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetPosition(root_child0, YGEdgeLeft, YGPx(0)); + YGNodeStyleSetPosition(root_child0, YGEdgeTop, YGPx(0)); + YGNodeStyleSetWidth(root_child0, YGPx(50)); YGNodeStyleSetAspectRatio(root_child0, 1); YGNodeInsertChild(root, root_child0, 0); @@ -192,14 +192,14 @@ TEST(YogaTest, aspect_ratio_absolute_layout_width_defined) { TEST(YogaTest, aspect_ratio_absolute_layout_height_defined) { const YGNodeRef root = YGNodeNew(); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); - YGNodeStyleSetPosition(root_child0, YGEdgeLeft, 0); - YGNodeStyleSetPosition(root_child0, YGEdgeTop, 0); - YGNodeStyleSetHeight(root_child0, 50); + YGNodeStyleSetPosition(root_child0, YGEdgeLeft, YGPx(0)); + YGNodeStyleSetPosition(root_child0, YGEdgeTop, YGPx(0)); + YGNodeStyleSetHeight(root_child0, YGPx(50)); YGNodeStyleSetAspectRatio(root_child0, 1); YGNodeInsertChild(root, root_child0, 0); @@ -216,12 +216,12 @@ TEST(YogaTest, aspect_ratio_absolute_layout_height_defined) { TEST(YogaTest, aspect_ratio_with_max_cross_defined) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetHeight(root_child0, 50); - YGNodeStyleSetMaxWidth(root_child0, 40); + YGNodeStyleSetHeight(root_child0, YGPx(50)); + YGNodeStyleSetMaxWidth(root_child0, YGPx(40)); YGNodeStyleSetAspectRatio(root_child0, 1); YGNodeInsertChild(root, root_child0, 0); @@ -238,12 +238,12 @@ TEST(YogaTest, aspect_ratio_with_max_cross_defined) { TEST(YogaTest, aspect_ratio_with_max_main_defined) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); - YGNodeStyleSetMaxHeight(root_child0, 40); + YGNodeStyleSetWidth(root_child0, YGPx(50)); + YGNodeStyleSetMaxHeight(root_child0, YGPx(40)); YGNodeStyleSetAspectRatio(root_child0, 1); YGNodeInsertChild(root, root_child0, 0); @@ -260,12 +260,12 @@ TEST(YogaTest, aspect_ratio_with_max_main_defined) { TEST(YogaTest, aspect_ratio_with_min_cross_defined) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetHeight(root_child0, 30); - YGNodeStyleSetMinWidth(root_child0, 40); + YGNodeStyleSetHeight(root_child0, YGPx(30)); + YGNodeStyleSetMinWidth(root_child0, YGPx(40)); YGNodeStyleSetAspectRatio(root_child0, 1); YGNodeInsertChild(root, root_child0, 0); @@ -282,12 +282,12 @@ TEST(YogaTest, aspect_ratio_with_min_cross_defined) { TEST(YogaTest, aspect_ratio_with_min_main_defined) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 30); - YGNodeStyleSetMinHeight(root_child0, 40); + YGNodeStyleSetWidth(root_child0, YGPx(30)); + YGNodeStyleSetMinHeight(root_child0, YGPx(40)); YGNodeStyleSetAspectRatio(root_child0, 1); YGNodeInsertChild(root, root_child0, 0); @@ -304,11 +304,11 @@ TEST(YogaTest, aspect_ratio_with_min_main_defined) { TEST(YogaTest, aspect_ratio_double_cross) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetHeight(root_child0, 50); + YGNodeStyleSetHeight(root_child0, YGPx(50)); YGNodeStyleSetAspectRatio(root_child0, 2); YGNodeInsertChild(root, root_child0, 0); @@ -325,11 +325,11 @@ TEST(YogaTest, aspect_ratio_double_cross) { TEST(YogaTest, aspect_ratio_half_cross) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetHeight(root_child0, 100); + YGNodeStyleSetHeight(root_child0, YGPx(100)); YGNodeStyleSetAspectRatio(root_child0, 0.5); YGNodeInsertChild(root, root_child0, 0); @@ -346,11 +346,11 @@ TEST(YogaTest, aspect_ratio_half_cross) { TEST(YogaTest, aspect_ratio_double_main) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 50); + YGNodeStyleSetWidth(root_child0, YGPx(50)); YGNodeStyleSetAspectRatio(root_child0, 2); YGNodeInsertChild(root, root_child0, 0); @@ -367,11 +367,11 @@ TEST(YogaTest, aspect_ratio_double_main) { TEST(YogaTest, aspect_ratio_half_main) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); - YGNodeStyleSetWidth(root_child0, 100); + YGNodeStyleSetWidth(root_child0, YGPx(100)); YGNodeStyleSetAspectRatio(root_child0, 0.5); YGNodeInsertChild(root, root_child0, 0); @@ -388,8 +388,8 @@ TEST(YogaTest, aspect_ratio_half_main) { TEST(YogaTest, aspect_ratio_with_measure_func) { const YGNodeRef root = YGNodeNew(); YGNodeStyleSetAlignItems(root, YGAlignFlexStart); - YGNodeStyleSetWidth(root, 100); - YGNodeStyleSetHeight(root, 100); + YGNodeStyleSetWidth(root, YGPx(100)); + YGNodeStyleSetHeight(root, YGPx(100)); const YGNodeRef root_child0 = YGNodeNew(); YGNodeSetMeasureFunc(root_child0, _measure); diff --git a/tests/YGMeasureModeTest.cpp b/tests/YGMeasureModeTest.cpp index ad766043..9bbbbfa9 100644 --- a/tests/YGMeasureModeTest.cpp +++ b/tests/YGMeasureModeTest.cpp @@ -243,7 +243,7 @@ TEST(YogaTest, flex_child_with_flex_basis) { const YGNodeRef root_child0 = YGNodeNew(); YGNodeStyleSetFlexGrow(root_child0, 1); - YGNodeStyleSetFlexBasis(root_child0, 0); + YGNodeStyleSetFlexBasis(root_child0, YGPx(0)); YGNodeSetContext(root_child0, &constraintList); YGNodeSetMeasureFunc(root_child0, _measure); YGNodeInsertChild(root, root_child0, 0);