changed the csharp interop code to use new functions
This commit is contained in:
@@ -194,43 +194,64 @@ namespace Facebook.Yoga
|
|||||||
public static extern float YGNodeStyleGetFlexShrink(YGNodeHandle node);
|
public static extern float YGNodeStyleGetFlexShrink(YGNodeHandle node);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void YGNodeStyleSetFlexBasis(YGNodeHandle node, YogaValue flexBasis);
|
public static extern void YGNodeStyleSetFlexBasis(YGNodeHandle node, float flexBasis);
|
||||||
|
|
||||||
|
[DllImport(DllName)]
|
||||||
|
public static extern void YGNodeStyleSetFlexBasisPercent(YGNodeHandle node, float flexBasis);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern YogaValue YGNodeStyleGetFlexBasis(YGNodeHandle node);
|
public static extern YogaValue YGNodeStyleGetFlexBasis(YGNodeHandle node);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void YGNodeStyleSetWidth(YGNodeHandle node, YogaValue width);
|
public static extern void YGNodeStyleSetWidth(YGNodeHandle node, float width);
|
||||||
|
|
||||||
|
[DllImport(DllName)]
|
||||||
|
public static extern void YGNodeStyleSetWidthPercent(YGNodeHandle node, float width);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern YogaValue YGNodeStyleGetWidth(YGNodeHandle node);
|
public static extern YogaValue YGNodeStyleGetWidth(YGNodeHandle node);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void YGNodeStyleSetHeight(YGNodeHandle node, YogaValue height);
|
public static extern void YGNodeStyleSetHeight(YGNodeHandle node, float height);
|
||||||
|
|
||||||
|
[DllImport(DllName)]
|
||||||
|
public static extern void YGNodeStyleSetHeightPercent(YGNodeHandle node, float height);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern YogaValue YGNodeStyleGetHeight(YGNodeHandle node);
|
public static extern YogaValue YGNodeStyleGetHeight(YGNodeHandle node);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void YGNodeStyleSetMinWidth(YGNodeHandle node, YogaValue minWidth);
|
public static extern void YGNodeStyleSetMinWidth(YGNodeHandle node, float minWidth);
|
||||||
|
|
||||||
|
[DllImport(DllName)]
|
||||||
|
public static extern void YGNodeStyleSetMinWidthPercent(YGNodeHandle node, float minWidth);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern YogaValue YGNodeStyleGetMinWidth(YGNodeHandle node);
|
public static extern YogaValue YGNodeStyleGetMinWidth(YGNodeHandle node);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void YGNodeStyleSetMinHeight(YGNodeHandle node, YogaValue minHeight);
|
public static extern void YGNodeStyleSetMinHeight(YGNodeHandle node, float minHeight);
|
||||||
|
|
||||||
|
[DllImport(DllName)]
|
||||||
|
public static extern void YGNodeStyleSetMinHeightPercent(YGNodeHandle node, float minHeight);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern YogaValue YGNodeStyleGetMinHeight(YGNodeHandle node);
|
public static extern YogaValue YGNodeStyleGetMinHeight(YGNodeHandle node);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void YGNodeStyleSetMaxWidth(YGNodeHandle node, YogaValue maxWidth);
|
public static extern void YGNodeStyleSetMaxWidth(YGNodeHandle node, float maxWidth);
|
||||||
|
|
||||||
|
[DllImport(DllName)]
|
||||||
|
public static extern void YGNodeStyleSetMaxWidthPercent(YGNodeHandle node, float maxWidth);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern YogaValue YGNodeStyleGetMaxWidth(YGNodeHandle node);
|
public static extern YogaValue YGNodeStyleGetMaxWidth(YGNodeHandle node);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void YGNodeStyleSetMaxHeight(YGNodeHandle node, YogaValue maxHeight);
|
public static extern void YGNodeStyleSetMaxHeight(YGNodeHandle node, float maxHeight);
|
||||||
|
|
||||||
|
[DllImport(DllName)]
|
||||||
|
public static extern void YGNodeStyleSetMaxHeightPercent(YGNodeHandle node, float maxHeight);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern YogaValue YGNodeStyleGetMaxHeight(YGNodeHandle node);
|
public static extern YogaValue YGNodeStyleGetMaxHeight(YGNodeHandle node);
|
||||||
@@ -246,19 +267,28 @@ namespace Facebook.Yoga
|
|||||||
#region YG_NODE_STYLE_EDGE_PROPERTY
|
#region YG_NODE_STYLE_EDGE_PROPERTY
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void YGNodeStyleSetPosition(YGNodeHandle node, YogaEdge edge, YogaValue position);
|
public static extern void YGNodeStyleSetPosition(YGNodeHandle node, YogaEdge edge, float position);
|
||||||
|
|
||||||
|
[DllImport(DllName)]
|
||||||
|
public static extern void YGNodeStyleSetPositionPercent(YGNodeHandle node, YogaEdge edge, float position);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern YogaValue YGNodeStyleGetPosition(YGNodeHandle node, YogaEdge edge);
|
public static extern YogaValue YGNodeStyleGetPosition(YGNodeHandle node, YogaEdge edge);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void YGNodeStyleSetMargin(YGNodeHandle node, YogaEdge edge, YogaValue margin);
|
public static extern void YGNodeStyleSetMargin(YGNodeHandle node, YogaEdge edge, float margin);
|
||||||
|
|
||||||
|
[DllImport(DllName)]
|
||||||
|
public static extern void YGNodeStyleSetMarginPercent(YGNodeHandle node, YogaEdge edge, float margin);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern YogaValue YGNodeStyleGetMargin(YGNodeHandle node, YogaEdge edge);
|
public static extern YogaValue YGNodeStyleGetMargin(YGNodeHandle node, YogaEdge edge);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern void YGNodeStyleSetPadding(YGNodeHandle node, YogaEdge edge, YogaValue padding);
|
public static extern void YGNodeStyleSetPadding(YGNodeHandle node, YogaEdge edge, float padding);
|
||||||
|
|
||||||
|
[DllImport(DllName)]
|
||||||
|
public static extern void YGNodeStyleSetPaddingPercent(YGNodeHandle node, YogaEdge edge, float padding);
|
||||||
|
|
||||||
[DllImport(DllName)]
|
[DllImport(DllName)]
|
||||||
public static extern YogaValue YGNodeStyleGetPadding(YGNodeHandle node, YogaEdge edge);
|
public static extern YogaValue YGNodeStyleGetPadding(YGNodeHandle node, YogaEdge edge);
|
||||||
|
@@ -20,7 +20,7 @@ namespace Facebook.Yoga
|
|||||||
|
|
||||||
public static bool IsUndefined(YogaValue value)
|
public static bool IsUndefined(YogaValue value)
|
||||||
{
|
{
|
||||||
return !value.IsDefined;
|
return value.Unit == YogaUnit.Undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -236,7 +236,14 @@ namespace Facebook.Yoga
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Native.YGNodeStyleSetFlexBasis(_ygNode, value);
|
if (value.Unit == YogaUnit.Percent)
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetFlexBasisPercent(_ygNode, value.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetFlexBasis(_ygNode, value.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,7 +254,14 @@ namespace Facebook.Yoga
|
|||||||
|
|
||||||
public void SetMargin(YogaEdge edge, YogaValue value)
|
public void SetMargin(YogaEdge edge, YogaValue value)
|
||||||
{
|
{
|
||||||
Native.YGNodeStyleSetMargin(_ygNode, edge, value);
|
if (value.Unit == YogaUnit.Percent)
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetMarginPercent(_ygNode, edge, value.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetMargin(_ygNode, edge, value.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public YogaValue GetPadding(YogaEdge edge)
|
public YogaValue GetPadding(YogaEdge edge)
|
||||||
@@ -255,9 +269,16 @@ namespace Facebook.Yoga
|
|||||||
return Native.YGNodeStyleGetPadding(_ygNode, edge);
|
return Native.YGNodeStyleGetPadding(_ygNode, edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPadding(YogaEdge edge, YogaValue padding)
|
public void SetPadding(YogaEdge edge, YogaValue value)
|
||||||
{
|
{
|
||||||
Native.YGNodeStyleSetPadding(_ygNode, edge, padding);
|
if (value.Unit == YogaUnit.Percent)
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetPaddingPercent(_ygNode, edge, value.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetPadding(_ygNode, edge, value.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetBorder(YogaEdge edge)
|
public float GetBorder(YogaEdge edge)
|
||||||
@@ -275,9 +296,16 @@ namespace Facebook.Yoga
|
|||||||
return Native.YGNodeStyleGetPosition(_ygNode, edge);
|
return Native.YGNodeStyleGetPosition(_ygNode, edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPosition(YogaEdge edge, YogaValue position)
|
public void SetPosition(YogaEdge edge, YogaValue value)
|
||||||
{
|
{
|
||||||
Native.YGNodeStyleSetPosition(_ygNode, edge, position);
|
if (value.Unit == YogaUnit.Percent)
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetPositionPercent(_ygNode, edge, value.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetPosition(_ygNode, edge, value.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public YogaValue Width
|
public YogaValue Width
|
||||||
@@ -289,7 +317,14 @@ namespace Facebook.Yoga
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Native.YGNodeStyleSetWidth(_ygNode, value);
|
if (value.Unit == YogaUnit.Percent)
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetWidthPercent(_ygNode, value.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetWidth(_ygNode, value.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,7 +337,14 @@ namespace Facebook.Yoga
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Native.YGNodeStyleSetHeight(_ygNode, value);
|
if (value.Unit == YogaUnit.Percent)
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetHeightPercent(_ygNode, value.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetHeight(_ygNode, value.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,7 +357,14 @@ namespace Facebook.Yoga
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Native.YGNodeStyleSetMaxWidth(_ygNode, value);
|
if (value.Unit == YogaUnit.Percent)
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetMaxWidthPercent(_ygNode, value.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetMaxWidth(_ygNode, value.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,7 +377,14 @@ namespace Facebook.Yoga
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Native.YGNodeStyleSetMaxHeight(_ygNode, value);
|
if (value.Unit == YogaUnit.Percent)
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetMaxHeightPercent(_ygNode, value.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetMaxHeight(_ygNode, value.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -341,7 +397,14 @@ namespace Facebook.Yoga
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Native.YGNodeStyleSetMinWidth(_ygNode, value);
|
if (value.Unit == YogaUnit.Percent)
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetMinWidthPercent(_ygNode, value.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetMinWidth(_ygNode, value.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,7 +417,14 @@ namespace Facebook.Yoga
|
|||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
Native.YGNodeStyleSetMinHeight(_ygNode, value);
|
if (value.Unit == YogaUnit.Percent)
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetMinHeightPercent(_ygNode, value.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Native.YGNodeStyleSetMinHeight(_ygNode, value.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,6 +11,7 @@ namespace Facebook.Yoga
|
|||||||
{
|
{
|
||||||
public enum YogaUnit
|
public enum YogaUnit
|
||||||
{
|
{
|
||||||
|
Undefined,
|
||||||
Pixel,
|
Pixel,
|
||||||
Percent
|
Percent
|
||||||
}
|
}
|
||||||
|
@@ -14,25 +14,24 @@ namespace Facebook.Yoga
|
|||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct YogaValue
|
public struct YogaValue
|
||||||
{
|
{
|
||||||
private float Value;
|
private float value;
|
||||||
private YogaUnit Unit;
|
private YogaUnit unit;
|
||||||
private byte isDefined; /* use byte to keep struct blitable */
|
|
||||||
|
|
||||||
public bool IsDefined => isDefined != 0;
|
public YogaUnit Unit => unit;
|
||||||
|
public float Value => value;
|
||||||
|
|
||||||
public static YogaValue Pixel(float value)
|
public static YogaValue Pixel(float value)
|
||||||
{
|
{
|
||||||
return new YogaValue
|
return new YogaValue
|
||||||
{
|
{
|
||||||
Value = value,
|
value = value,
|
||||||
isDefined = YogaConstants.IsUndefined(value) ? (byte)0 : (byte)1,
|
unit = YogaConstants.IsUndefined(value) ? YogaUnit.Undefined : YogaUnit.Pixel
|
||||||
Unit = YogaUnit.Pixel
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Equals(YogaValue other)
|
public bool Equals(YogaValue other)
|
||||||
{
|
{
|
||||||
return Value.Equals(other.Value) && Unit == other.Unit;
|
return Unit == other.Unit && (Value.Equals(other.Value) || Unit == YogaUnit.Undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
@@ -53,9 +52,8 @@ namespace Facebook.Yoga
|
|||||||
{
|
{
|
||||||
return new YogaValue
|
return new YogaValue
|
||||||
{
|
{
|
||||||
Value = YogaConstants.Undefined,
|
value = YogaConstants.Undefined,
|
||||||
isDefined = 0,
|
unit = YogaUnit.Undefined
|
||||||
Unit = YogaUnit.Pixel
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,9 +61,8 @@ namespace Facebook.Yoga
|
|||||||
{
|
{
|
||||||
return new YogaValue
|
return new YogaValue
|
||||||
{
|
{
|
||||||
Value = value,
|
value = value,
|
||||||
isDefined = YogaConstants.IsUndefined(value) ? (byte)0 : (byte)1,
|
unit = YogaConstants.IsUndefined(value) ? YogaUnit.Undefined : YogaUnit.Percent
|
||||||
Unit = YogaUnit.Percent
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -212,7 +212,7 @@ namespace Facebook.Yoga
|
|||||||
parent.Insert(0, child0);
|
parent.Insert(0, child0);
|
||||||
parent.Insert(0, child1);
|
parent.Insert(0, child1);
|
||||||
parent.CalculateLayout();
|
parent.CalculateLayout();
|
||||||
Assert.AreEqual(parent.Print(), "{layout: {width: 100, height: 120, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 100px, height: 120px, children: [\n {layout: {width: 35, height: 45, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 35px, height: 45px, },\n {layout: {width: 30, height: 40, top: 45, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 30px, height: 40px, },\n]},\n");
|
Assert.AreEqual("{layout: {width: 100, height: 120, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 100px, height: 120px, children: [\n {layout: {width: 35, height: 45, top: 0, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 35px, height: 45px, },\n {layout: {width: 30, height: 40, top: 45, left: 0}, flexDirection: 'column', alignItems: 'stretch', flexGrow: 0, flexShrink: 0, overflow: 'visible', width: 30px, height: 40px, },\n]},\n", parent.Print());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
14
yoga/Yoga.c
14
yoga/Yoga.c
@@ -145,7 +145,7 @@ typedef struct YGNode {
|
|||||||
[YGDimensionHeight] = YG_UNDEFINED_VALUES, \
|
[YGDimensionHeight] = YG_UNDEFINED_VALUES, \
|
||||||
}
|
}
|
||||||
|
|
||||||
YGNode gYGNodeDefaults = {
|
static YGNode gYGNodeDefaults = {
|
||||||
.parent = NULL,
|
.parent = NULL,
|
||||||
.children = NULL,
|
.children = NULL,
|
||||||
.hasNewLayout = true,
|
.hasNewLayout = true,
|
||||||
@@ -195,10 +195,7 @@ YGCalloc gYGCalloc = &calloc;
|
|||||||
YGRealloc gYGRealloc = &realloc;
|
YGRealloc gYGRealloc = &realloc;
|
||||||
YGFree gYGFree = &free;
|
YGFree gYGFree = &free;
|
||||||
|
|
||||||
static YGValue YGValueUndefined = {
|
static YGValue YGValueUndefined = YG_UNDEFINED_VALUES;
|
||||||
.value = YGUndefined,
|
|
||||||
.unit = YGUnitUndefined
|
|
||||||
};
|
|
||||||
|
|
||||||
static YGValue YGValueZero = {
|
static YGValue YGValueZero = {
|
||||||
.value = 0,
|
.value = 0,
|
||||||
@@ -598,9 +595,14 @@ inline bool YGFloatIsUndefined(const float value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline bool YGValueEqual(const YGValue a, const YGValue b) {
|
static inline bool YGValueEqual(const YGValue a, const YGValue b) {
|
||||||
if (a.unit != YGUnitUndefined != b.unit != YGUnitUndefined || a.unit != b.unit) {
|
if (a.unit != b.unit) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(a.unit == YGUnitUndefined)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return fabs(a.value - b.value) < 0.0001f;
|
return fabs(a.value - b.value) < 0.0001f;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user