update c# interop to use percentage
This commit is contained in:
31
csharp/Facebook.Yoga/Border.cs
Normal file
31
csharp/Facebook.Yoga/Border.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
public class Border
|
||||
{
|
||||
public float? Top;
|
||||
public float? Bottom;
|
||||
public float? Left;
|
||||
public float? Right;
|
||||
|
||||
public Border(
|
||||
float? top = null,
|
||||
float? bottom = null,
|
||||
float? left = null,
|
||||
float? right = null)
|
||||
{
|
||||
Top = top;
|
||||
Bottom = bottom;
|
||||
Left = left;
|
||||
Right = right;
|
||||
}
|
||||
}
|
||||
}
|
@@ -181,46 +181,46 @@ namespace Facebook.Yoga
|
||||
public static extern float YGNodeStyleGetFlexShrink(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void YGNodeStyleSetFlexBasis(IntPtr node, float flexBasis);
|
||||
public static extern void YGNodeStyleSetFlexBasis(IntPtr node, YogaValue flexBasis);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float YGNodeStyleGetFlexBasis(IntPtr node);
|
||||
public static extern YogaValue YGNodeStyleGetFlexBasis(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void YGNodeStyleSetWidth(IntPtr node, float width);
|
||||
public static extern void YGNodeStyleSetWidth(IntPtr node, YogaValue width);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float YGNodeStyleGetWidth(IntPtr node);
|
||||
public static extern YogaValue YGNodeStyleGetWidth(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void YGNodeStyleSetHeight(IntPtr node, float height);
|
||||
public static extern void YGNodeStyleSetHeight(IntPtr node, YogaValue height);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float YGNodeStyleGetHeight(IntPtr node);
|
||||
public static extern YogaValue YGNodeStyleGetHeight(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void YGNodeStyleSetMinWidth(IntPtr node, float minWidth);
|
||||
public static extern void YGNodeStyleSetMinWidth(IntPtr node, YogaValue minWidth);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float YGNodeStyleGetMinWidth(IntPtr node);
|
||||
public static extern YogaValue YGNodeStyleGetMinWidth(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void YGNodeStyleSetMinHeight(IntPtr node, float minHeight);
|
||||
public static extern void YGNodeStyleSetMinHeight(IntPtr node, YogaValue minHeight);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float YGNodeStyleGetMinHeight(IntPtr node);
|
||||
public static extern YogaValue YGNodeStyleGetMinHeight(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void YGNodeStyleSetMaxWidth(IntPtr node, float maxWidth);
|
||||
public static extern void YGNodeStyleSetMaxWidth(IntPtr node, YogaValue maxWidth);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float YGNodeStyleGetMaxWidth(IntPtr node);
|
||||
public static extern YogaValue YGNodeStyleGetMaxWidth(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void YGNodeStyleSetMaxHeight(IntPtr node, float maxHeight);
|
||||
public static extern void YGNodeStyleSetMaxHeight(IntPtr node, YogaValue maxHeight);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float YGNodeStyleGetMaxHeight(IntPtr node);
|
||||
public static extern YogaValue YGNodeStyleGetMaxHeight(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void YGNodeStyleSetAspectRatio(IntPtr node, float aspectRatio);
|
||||
@@ -233,22 +233,22 @@ namespace Facebook.Yoga
|
||||
#region YG_NODE_STYLE_EDGE_PROPERTY
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void YGNodeStyleSetPosition(IntPtr node, YogaEdge edge, float position);
|
||||
public static extern void YGNodeStyleSetPosition(IntPtr node, YogaEdge edge, YogaValue position);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float YGNodeStyleGetPosition(IntPtr node, YogaEdge edge);
|
||||
public static extern YogaValue YGNodeStyleGetPosition(IntPtr node, YogaEdge edge);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void YGNodeStyleSetMargin(IntPtr node, YogaEdge edge, float margin);
|
||||
public static extern void YGNodeStyleSetMargin(IntPtr node, YogaEdge edge, YogaValue margin);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float YGNodeStyleGetMargin(IntPtr node, YogaEdge edge);
|
||||
public static extern YogaValue YGNodeStyleGetMargin(IntPtr node, YogaEdge edge);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void YGNodeStyleSetPadding(IntPtr node, YogaEdge edge, float padding);
|
||||
public static extern void YGNodeStyleSetPadding(IntPtr node, YogaEdge edge, YogaValue padding);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float YGNodeStyleGetPadding(IntPtr node, YogaEdge edge);
|
||||
public static extern YogaValue YGNodeStyleGetPadding(IntPtr node, YogaEdge edge);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void YGNodeStyleSetBorder(IntPtr node, YogaEdge edge, float border);
|
||||
|
@@ -11,16 +11,16 @@ namespace Facebook.Yoga
|
||||
{
|
||||
public class Spacing
|
||||
{
|
||||
public float? Top;
|
||||
public float? Bottom;
|
||||
public float? Left;
|
||||
public float? Right;
|
||||
public YogaValue? Top;
|
||||
public YogaValue? Bottom;
|
||||
public YogaValue? Left;
|
||||
public YogaValue? Right;
|
||||
|
||||
public Spacing(
|
||||
float? top = null,
|
||||
float? bottom = null,
|
||||
float? left = null,
|
||||
float? right = null)
|
||||
YogaValue? top = null,
|
||||
YogaValue? bottom = null,
|
||||
YogaValue? left = null,
|
||||
YogaValue? right = null)
|
||||
{
|
||||
Top = top;
|
||||
Bottom = bottom;
|
||||
|
@@ -17,5 +17,10 @@ namespace Facebook.Yoga
|
||||
{
|
||||
return float.IsNaN(value);
|
||||
}
|
||||
|
||||
public static bool IsUndefined(YogaValue value)
|
||||
{
|
||||
return !value.IsDefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,17 +26,17 @@ namespace Facebook.Yoga
|
||||
float? flex = null,
|
||||
float? flexGrow = null,
|
||||
float? flexShrink = null,
|
||||
float? flexBasis = null,
|
||||
YogaValue? flexBasis = null,
|
||||
Spacing position = null,
|
||||
Spacing margin = null,
|
||||
Spacing padding = null,
|
||||
Spacing border = null,
|
||||
float? Width = null,
|
||||
float? Height = null,
|
||||
float? MaxWidth = null,
|
||||
float? MaxHeight = null,
|
||||
float? MinWidth = null,
|
||||
float? MinHeight = null)
|
||||
Border border = null,
|
||||
YogaValue? Width = null,
|
||||
YogaValue? Height = null,
|
||||
YogaValue? MaxWidth = null,
|
||||
YogaValue? MaxHeight = null,
|
||||
YogaValue? MinWidth = null,
|
||||
YogaValue? MinHeight = null)
|
||||
{
|
||||
YogaNode node = new YogaNode();
|
||||
|
||||
|
@@ -10,7 +10,6 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Facebook.Yoga
|
||||
@@ -233,7 +232,7 @@ namespace Facebook.Yoga
|
||||
}
|
||||
}
|
||||
|
||||
public float FlexBasis
|
||||
public YogaValue FlexBasis
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -246,22 +245,22 @@ namespace Facebook.Yoga
|
||||
}
|
||||
}
|
||||
|
||||
public float GetMargin(YogaEdge edge)
|
||||
public YogaValue GetMargin(YogaEdge edge)
|
||||
{
|
||||
return Native.YGNodeStyleGetMargin(_ygNode, edge);
|
||||
}
|
||||
|
||||
public void SetMargin(YogaEdge edge, float value)
|
||||
public void SetMargin(YogaEdge edge, YogaValue value)
|
||||
{
|
||||
Native.YGNodeStyleSetMargin(_ygNode, edge, value);
|
||||
}
|
||||
|
||||
public float GetPadding(YogaEdge edge)
|
||||
public YogaValue GetPadding(YogaEdge edge)
|
||||
{
|
||||
return Native.YGNodeStyleGetPadding(_ygNode, edge);
|
||||
}
|
||||
|
||||
public void SetPadding(YogaEdge edge, float padding)
|
||||
public void SetPadding(YogaEdge edge, YogaValue padding)
|
||||
{
|
||||
Native.YGNodeStyleSetPadding(_ygNode, edge, padding);
|
||||
}
|
||||
@@ -276,17 +275,17 @@ namespace Facebook.Yoga
|
||||
Native.YGNodeStyleSetBorder(_ygNode, edge, border);
|
||||
}
|
||||
|
||||
public float GetPosition(YogaEdge edge)
|
||||
public YogaValue GetPosition(YogaEdge edge)
|
||||
{
|
||||
return Native.YGNodeStyleGetPosition(_ygNode, edge);
|
||||
}
|
||||
|
||||
public void SetPosition(YogaEdge edge, float position)
|
||||
public void SetPosition(YogaEdge edge, YogaValue position)
|
||||
{
|
||||
Native.YGNodeStyleSetPosition(_ygNode, edge, position);
|
||||
}
|
||||
|
||||
public float Width
|
||||
public YogaValue Width
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -299,7 +298,7 @@ namespace Facebook.Yoga
|
||||
}
|
||||
}
|
||||
|
||||
public float Height
|
||||
public YogaValue Height
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -312,7 +311,7 @@ namespace Facebook.Yoga
|
||||
}
|
||||
}
|
||||
|
||||
public float MaxWidth
|
||||
public YogaValue MaxWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -325,7 +324,7 @@ namespace Facebook.Yoga
|
||||
}
|
||||
}
|
||||
|
||||
public float MaxHeight
|
||||
public YogaValue MaxHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -338,7 +337,7 @@ namespace Facebook.Yoga
|
||||
}
|
||||
}
|
||||
|
||||
public float MinWidth
|
||||
public YogaValue MinWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -351,7 +350,7 @@ namespace Facebook.Yoga
|
||||
}
|
||||
}
|
||||
|
||||
public float MinHeight
|
||||
public YogaValue MinHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
|
17
csharp/Facebook.Yoga/YogaUnit.cs
Normal file
17
csharp/Facebook.Yoga/YogaUnit.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
public enum YogaUnit
|
||||
{
|
||||
Pixel,
|
||||
Percent
|
||||
}
|
||||
}
|
67
csharp/Facebook.Yoga/YogaValue.cs
Normal file
67
csharp/Facebook.Yoga/YogaValue.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct YogaValue
|
||||
{
|
||||
private float Value;
|
||||
private YogaUnit Unit;
|
||||
private byte isDefined;
|
||||
|
||||
public bool IsDefined => isDefined != 0;
|
||||
|
||||
public static YogaValue Pixel(float value)
|
||||
{
|
||||
return new YogaValue
|
||||
{
|
||||
Value = value,
|
||||
isDefined = 1,
|
||||
Unit = YogaUnit.Pixel
|
||||
};
|
||||
}
|
||||
|
||||
public bool Equals(YogaValue other)
|
||||
{
|
||||
return Value.Equals(other.Value) && Unit == other.Unit;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
return obj is YogaValue && Equals((YogaValue) obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return (Value.GetHashCode() * 397) ^ (int) Unit;
|
||||
}
|
||||
}
|
||||
|
||||
public static YogaValue Percent(float value)
|
||||
{
|
||||
return new YogaValue
|
||||
{
|
||||
Value = value,
|
||||
isDefined = 1,
|
||||
Unit = YogaUnit.Percent
|
||||
};
|
||||
}
|
||||
|
||||
public static implicit operator YogaValue(float pixelValue)
|
||||
{
|
||||
return Pixel(pixelValue);
|
||||
}
|
||||
}
|
||||
}
|
34
csharp/Facebook.Yoga/YogaValueExtensions.cs
Normal file
34
csharp/Facebook.Yoga/YogaValueExtensions.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
public static class YogaValueExtensions
|
||||
{
|
||||
public static YogaValue Percent(this float value)
|
||||
{
|
||||
return YogaValue.Percent(value);
|
||||
}
|
||||
|
||||
public static YogaValue Px(this float value)
|
||||
{
|
||||
return YogaValue.Pixel(value);
|
||||
}
|
||||
|
||||
public static YogaValue Percent(this int value)
|
||||
{
|
||||
return YogaValue.Percent(value);
|
||||
}
|
||||
|
||||
public static YogaValue Px(this int value)
|
||||
{
|
||||
return YogaValue.Pixel(value);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user