fixed some cpp tests compilation issues, improved c# value struct

This commit is contained in:
Lukas Woehrl
2016-12-20 07:32:47 +01:00
parent 08eb9ff8f7
commit 2424fc2b12
4 changed files with 92 additions and 82 deletions

View File

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

View File

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

View File

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

View File

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