Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing .NET version of css-layout using P/Invoke #220

Closed
wants to merge 12 commits into from
10 changes: 7 additions & 3 deletions csharp/Facebook.CSSLayout/CSSNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,16 @@ public CSSDirection StyleDirection
{
get
{
throw new NotImplementedException();
return Style.Direction;
}

set
{
throw new NotImplementedException();
if (Style.Direction != value)
{
Style.Direction = value;
MarkDirty();
}
}
}

Expand Down Expand Up @@ -391,7 +395,7 @@ public float StyleWidth
}
}

public CSSWrapType Wrap
public CSSWrap Wrap
{
get
{
Expand Down
92 changes: 61 additions & 31 deletions csharp/Facebook.CSSLayout/CSSStyle.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,65 @@
using System.Runtime.InteropServices;

namespace Facebook.CSSLayout
namespace Facebook.CSSLayout
{
[StructLayout(LayoutKind.Sequential)]
public struct CSSStyle
public class CSSStyle
{
CSSDirection direction;
CSSFlexDirection flexDirection;
CSSJustify justifyContent;
CSSAlign alignContent;
CSSAlign alignItems;
CSSAlign alignSelf;
CSSPositionType positionType;
CSSWrapType flexWrap;
CSSOverflow overflow;
float flexGrow;
float flexShrink;
float flexBasis;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)]
float[] margin;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)]
float[] position;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)]
float[] padding;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)]
float[] border;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
float[] dimensions;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
float[] minDimensions;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
float[] maxDimensions;
public CSSDirection Direction { get; set; }
public CSSFlexDirection FlexDirection { get; set; }
public CSSJustify JustifyContent { get; set; }
public CSSAlign AlignContent { get; set; }
public CSSAlign AlignItems { get; set; }
public CSSAlign AlignSelf { get; set; }
public CSSPositionType PositionType { get; set; }
public CSSWrap FlexWrap { get; set; }
public CSSOverflow Overflow { get; set; }
public float FlexGrow { get; set; }
public float FlexShrink { get; set; }
public float FlexBasis { get; set; }

public Spacing Margin { get; } = new Spacing();
public Spacing Padding { get; } = new Spacing();
public Spacing Border { get; } = new Spacing();
public Spacing Position { get; } = new Spacing(CSSConstants.UNDEFINED);

public float[] Dimensions { get; } = new float[2];

public float MinWidth { get; set; } = CSSConstants.UNDEFINED;
public float MinHeight { get; set; } = CSSConstants.UNDEFINED;

public float MaxWidth { get; set; } = CSSConstants.UNDEFINED;
public float MaxHeight { get; set; } = CSSConstants.UNDEFINED;

public CSSStyle()
{
Reset();
}

public void Reset()
{
Direction = CSSDirection.Inherit;
FlexDirection = CSSFlexDirection.Column;
JustifyContent = CSSJustify.FlexStart;
AlignContent = CSSAlign.FlexStart;
AlignItems = CSSAlign.Stretch;
AlignSelf = CSSAlign.Auto;
PositionType = CSSPositionType.Relative;
FlexWrap = CSSWrap.NoWrap;
Overflow = CSSOverflow.Visible;
FlexGrow = 0;
FlexShrink = 0;
FlexBasis = CSSConstants.UNDEFINED;

Margin.Reset();
Padding.Reset();
Border.Reset();
Position.Reset();

for (var i = 0; i < 2; i++) { Dimensions[i] = CSSConstants.UNDEFINED; }

MinWidth = CSSConstants.UNDEFINED;
MinHeight = CSSConstants.UNDEFINED;

MaxWidth = CSSConstants.UNDEFINED;
MaxHeight = CSSConstants.UNDEFINED;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Facebook.CSSLayout
{
public enum CSSWrapType
public enum CSSWrap
{
NoWrap,
Wrap,
Expand Down
4 changes: 2 additions & 2 deletions csharp/Facebook.CSSLayout/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ public static extern void CSSNodeCalculateLayout(IntPtr node,
public static extern CSSPositionType CSSNodeStyleGetPositionType(IntPtr node);

[DllImport(DllName)]
public static extern void CSSNodeStyleSetFlexWrap(IntPtr node, CSSWrapType flexWrap);
public static extern void CSSNodeStyleSetFlexWrap(IntPtr node, CSSWrap flexWrap);

[DllImport(DllName)]
public static extern CSSWrapType CSSNodeStyleGetFlexWrap(IntPtr node);
public static extern CSSWrap CSSNodeStyleGetFlexWrap(IntPtr node);

[DllImport(DllName)]
public static extern void CSSNodeStyleSetOverflow(IntPtr node, CSSOverflow flexWrap);
Expand Down