Introducing .NET version of css-layout using P/Invoke
Summary: This version of the css-layout project includes support for .NET projects. Up in the air is how many configurations of .NET projects we allow for, such as Portable Class Libraries, Universal Windows Platform, .NET Core, etc. Still needs integration with Buck. Closes https://github.com/facebook/css-layout/pull/220 Reviewed By: lucasr Differential Revision: D3909367 Pulled By: emilsjolander fbshipit-source-id: aaaa9c4ff2d3452649f256c3268cf873cf33a0b9
This commit is contained in:
committed by
Facebook Github Bot 2
parent
017fb2c734
commit
ff8f17ac99
20
csharp/Facebook.CSSLayout/CSSAlign.cs
Normal file
20
csharp/Facebook.CSSLayout/CSSAlign.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 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.CSSLayout
|
||||
{
|
||||
public enum CSSAlign
|
||||
{
|
||||
Auto,
|
||||
FlexStart,
|
||||
Center,
|
||||
FlexEnd,
|
||||
Stretch
|
||||
}
|
||||
}
|
21
csharp/Facebook.CSSLayout/CSSConstants.cs
Normal file
21
csharp/Facebook.CSSLayout/CSSConstants.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* 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.CSSLayout
|
||||
{
|
||||
public static class CSSConstants
|
||||
{
|
||||
public const float Undefined = float.NaN;
|
||||
|
||||
public static bool IsUndefined(float value)
|
||||
{
|
||||
return float.IsNaN(value);
|
||||
}
|
||||
}
|
||||
}
|
18
csharp/Facebook.CSSLayout/CSSDIrection.cs
Normal file
18
csharp/Facebook.CSSLayout/CSSDIrection.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 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.CSSLayout
|
||||
{
|
||||
public enum CSSDirection
|
||||
{
|
||||
Inherit,
|
||||
LeftToRight,
|
||||
RightToLeft
|
||||
}
|
||||
}
|
17
csharp/Facebook.CSSLayout/CSSDimension.cs
Normal file
17
csharp/Facebook.CSSLayout/CSSDimension.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.CSSLayout
|
||||
{
|
||||
public enum CSSDimension
|
||||
{
|
||||
Width,
|
||||
Height
|
||||
}
|
||||
}
|
25
csharp/Facebook.CSSLayout/CSSEdge.cs
Normal file
25
csharp/Facebook.CSSLayout/CSSEdge.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 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.CSSLayout
|
||||
{
|
||||
public enum CSSEdge
|
||||
{
|
||||
Left,
|
||||
Top,
|
||||
Right,
|
||||
Bottom,
|
||||
Start,
|
||||
End,
|
||||
Horizontal,
|
||||
Vertical,
|
||||
All,
|
||||
Count,
|
||||
}
|
||||
}
|
19
csharp/Facebook.CSSLayout/CSSFlexDirection.cs
Normal file
19
csharp/Facebook.CSSLayout/CSSFlexDirection.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 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.CSSLayout
|
||||
{
|
||||
public enum CSSFlexDirection
|
||||
{
|
||||
Column,
|
||||
ColumnReverse,
|
||||
Row,
|
||||
RowReverse,
|
||||
}
|
||||
}
|
20
csharp/Facebook.CSSLayout/CSSJustify.cs
Normal file
20
csharp/Facebook.CSSLayout/CSSJustify.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 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.CSSLayout
|
||||
{
|
||||
public enum CSSJustify
|
||||
{
|
||||
FlexStart,
|
||||
Center,
|
||||
FlexEnd,
|
||||
SpaceBetween,
|
||||
SpaceAround,
|
||||
}
|
||||
}
|
17
csharp/Facebook.CSSLayout/CSSLayoutContext.cs
Normal file
17
csharp/Facebook.CSSLayout/CSSLayoutContext.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.CSSLayout
|
||||
{
|
||||
public class CSSLayoutContext
|
||||
{
|
||||
public MeasureOutput measureOutput { get; } = new MeasureOutput();
|
||||
public int CurrentGenerationCount { get; set; }
|
||||
}
|
||||
}
|
20
csharp/Facebook.CSSLayout/CSSMeasureFunc.cs
Normal file
20
csharp/Facebook.CSSLayout/CSSMeasureFunc.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public delegate CSSSize CSSMeasureFunc(
|
||||
IntPtr context,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode);
|
||||
}
|
19
csharp/Facebook.CSSLayout/CSSMeasureMode.cs
Normal file
19
csharp/Facebook.CSSLayout/CSSMeasureMode.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 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.CSSLayout
|
||||
{
|
||||
public enum CSSMeasureMode
|
||||
{
|
||||
Undefined,
|
||||
Exactly,
|
||||
AtMost,
|
||||
Count,
|
||||
}
|
||||
}
|
685
csharp/Facebook.CSSLayout/CSSNode.cs
Normal file
685
csharp/Facebook.CSSLayout/CSSNode.cs
Normal file
@@ -0,0 +1,685 @@
|
||||
/**
|
||||
* 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;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public class CSSNode : IDisposable, IEnumerable<CSSNode>
|
||||
{
|
||||
private bool _isDisposed;
|
||||
private IntPtr _cssNode;
|
||||
private IntPtr _context;
|
||||
|
||||
private CSSNode _parent;
|
||||
private List<CSSNode> _children;
|
||||
private MeasureFunction _measureFunction;
|
||||
private CSSMeasureFunc _measureFunc;
|
||||
private CSSPrintFunc _printFunc;
|
||||
private object _data;
|
||||
|
||||
public CSSNode()
|
||||
{
|
||||
_measureFunc = MeasureInternal;
|
||||
_printFunc = PrintInternal;
|
||||
}
|
||||
|
||||
private void CheckDisposed()
|
||||
{
|
||||
if (_isDisposed)
|
||||
{
|
||||
throw new ObjectDisposedException("CSSNode");
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!_isDisposed && disposing)
|
||||
{
|
||||
_isDisposed = true;
|
||||
Native.CSSNodeFree(_cssNode);
|
||||
GCHandle.FromIntPtr(_context).Free();
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_cssNode = Native.CSSNodeNew();
|
||||
_context = (IntPtr)GCHandle.Alloc(this);
|
||||
Native.CSSNodeSetContext(_cssNode, _context);
|
||||
_children = new List<CSSNode>(4);
|
||||
Native.CSSNodeSetPrintFunc(_cssNode, _printFunc);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Native.CSSNodeFree(_cssNode);
|
||||
GCHandle.FromIntPtr(_context).Free();
|
||||
_children = null;
|
||||
_parent = null;
|
||||
_measureFunction = null;
|
||||
}
|
||||
|
||||
public bool IsDirty
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeIsDirty(_cssNode);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void MarkDirty()
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeMarkDirty(_cssNode);
|
||||
}
|
||||
|
||||
public bool IsTextNode
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeGetIsTextnode(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeSetIsTextnode(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasNewLayout
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeGetHasNewLayout(_cssNode);
|
||||
}
|
||||
}
|
||||
|
||||
public void MarkHasNewLayout()
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeSetHasNewLayout(_cssNode, true);
|
||||
}
|
||||
|
||||
public CSSNode Parent
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return _parent;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsMeasureDefined
|
||||
{
|
||||
get
|
||||
{
|
||||
return _measureFunction != null;
|
||||
}
|
||||
}
|
||||
|
||||
public CSSDirection StyleDirection
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetDirection(_cssNode);
|
||||
}
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetDirection(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSFlexDirection FlexDirection
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetFlexDirection(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetFlexDirection(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSJustify JustifyContent
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetJustifyContent(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetJustifyContent(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSAlign AlignItems
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetAlignItems(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetAlignItems(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSAlign AlignSelf
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetAlignSelf(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetAlignSelf(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSAlign AlignContent
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetAlignContent(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetAlignContent(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSPositionType PositionType
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetPositionType(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetPositionType(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSWrap Wrap
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetFlexWrap(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetFlexWrap(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float Flex
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetFlex(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetFlex(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float FlexGrow
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetFlexGrow(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetFlexGrow(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float FlexShrink
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetFlexShrink(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetFlexShrink(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float FlexBasis
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetFlexBasis(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetFlexBasis(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public Spacing GetMargin()
|
||||
{
|
||||
CheckDisposed();
|
||||
|
||||
var margin = new Spacing();
|
||||
margin.Set(Spacing.Left, Native.CSSNodeStyleGetMargin(_cssNode, CSSEdge.Left));
|
||||
margin.Set(Spacing.Top, Native.CSSNodeStyleGetMargin(_cssNode, CSSEdge.Top));
|
||||
margin.Set(Spacing.Right, Native.CSSNodeStyleGetMargin(_cssNode, CSSEdge.Right));
|
||||
margin.Set(Spacing.Bottom, Native.CSSNodeStyleGetMargin(_cssNode, CSSEdge.Bottom));
|
||||
margin.Set(Spacing.Start, Native.CSSNodeStyleGetMargin(_cssNode, CSSEdge.Start));
|
||||
margin.Set(Spacing.End, Native.CSSNodeStyleGetMargin(_cssNode, CSSEdge.End));
|
||||
|
||||
return margin;
|
||||
}
|
||||
|
||||
public void SetMargin(CSSEdge edge, float value)
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetMargin(_cssNode, edge, value);
|
||||
}
|
||||
|
||||
public Spacing GetPadding()
|
||||
{
|
||||
CheckDisposed();
|
||||
|
||||
var padding = new Spacing();
|
||||
padding.Set(Spacing.Left, Native.CSSNodeStyleGetPadding(_cssNode, CSSEdge.Left));
|
||||
padding.Set(Spacing.Top, Native.CSSNodeStyleGetPadding(_cssNode, CSSEdge.Top));
|
||||
padding.Set(Spacing.Right, Native.CSSNodeStyleGetPadding(_cssNode, CSSEdge.Right));
|
||||
padding.Set(Spacing.Bottom, Native.CSSNodeStyleGetPadding(_cssNode, CSSEdge.Bottom));
|
||||
padding.Set(Spacing.Start, Native.CSSNodeStyleGetPadding(_cssNode, CSSEdge.Start));
|
||||
padding.Set(Spacing.End, Native.CSSNodeStyleGetPadding(_cssNode, CSSEdge.End));
|
||||
|
||||
return padding;
|
||||
}
|
||||
|
||||
public void SetPadding(CSSEdge edge, float padding)
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetPadding(_cssNode, edge, padding);
|
||||
}
|
||||
|
||||
public Spacing GetBorder()
|
||||
{
|
||||
CheckDisposed();
|
||||
|
||||
var border = new Spacing();
|
||||
border.Set(Spacing.Left, Native.CSSNodeStyleGetBorder(_cssNode, CSSEdge.Left));
|
||||
border.Set(Spacing.Top, Native.CSSNodeStyleGetBorder(_cssNode, CSSEdge.Top));
|
||||
border.Set(Spacing.Right, Native.CSSNodeStyleGetBorder(_cssNode, CSSEdge.Right));
|
||||
border.Set(Spacing.Bottom, Native.CSSNodeStyleGetBorder(_cssNode, CSSEdge.Bottom));
|
||||
border.Set(Spacing.Start, Native.CSSNodeStyleGetBorder(_cssNode, CSSEdge.Start));
|
||||
border.Set(Spacing.End, Native.CSSNodeStyleGetBorder(_cssNode, CSSEdge.End));
|
||||
|
||||
return border;
|
||||
}
|
||||
|
||||
public void SetBorder(CSSEdge edge, float border)
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetBorder(_cssNode, edge, border);
|
||||
}
|
||||
|
||||
public Spacing GetPosition()
|
||||
{
|
||||
CheckDisposed();
|
||||
|
||||
var position = new Spacing();
|
||||
position.Set(Spacing.Left, Native.CSSNodeStyleGetPosition(_cssNode, CSSEdge.Left));
|
||||
position.Set(Spacing.Top, Native.CSSNodeStyleGetPosition(_cssNode, CSSEdge.Top));
|
||||
position.Set(Spacing.Right, Native.CSSNodeStyleGetPosition(_cssNode, CSSEdge.Right));
|
||||
position.Set(Spacing.Bottom, Native.CSSNodeStyleGetPosition(_cssNode, CSSEdge.Bottom));
|
||||
position.Set(Spacing.Start, Native.CSSNodeStyleGetPosition(_cssNode, CSSEdge.Start));
|
||||
position.Set(Spacing.End, Native.CSSNodeStyleGetPosition(_cssNode, CSSEdge.End));
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
public void SetPosition(CSSEdge edge, float position)
|
||||
{
|
||||
CheckDisposed();
|
||||
}
|
||||
|
||||
public float StyleWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetWidth(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetWidth(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float StyleHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetHeight(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetHeight(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float StyleMaxWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetMaxWidth(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetMaxWidth(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float StyleMaxHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetMaxHeight(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetMaxHeight(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float StyleMinWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetMinWidth(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetMinWidth(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float StyleMinHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetMinHeight(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetMinHeight(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public float LayoutX
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeLayoutGetLeft(_cssNode);
|
||||
}
|
||||
}
|
||||
|
||||
public float LayoutY
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeLayoutGetTop(_cssNode);
|
||||
}
|
||||
}
|
||||
|
||||
public float LayoutWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeLayoutGetWidth(_cssNode);
|
||||
}
|
||||
}
|
||||
|
||||
public float LayoutHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeLayoutGetHeight(_cssNode);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSDirection LayoutDirection
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeLayoutGetDirection(_cssNode);
|
||||
}
|
||||
}
|
||||
|
||||
public CSSOverflow Overflow
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return Native.CSSNodeStyleGetOverflow(_cssNode);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeStyleSetOverflow(_cssNode, value);
|
||||
}
|
||||
}
|
||||
|
||||
public object Data
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return _data;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
CheckDisposed();
|
||||
_data = value;
|
||||
}
|
||||
}
|
||||
|
||||
public CSSNode this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return _children[index];
|
||||
}
|
||||
}
|
||||
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed();
|
||||
return _children.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public void MarkLayoutSeen()
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeSetHasNewLayout(_cssNode, false);
|
||||
}
|
||||
|
||||
public bool ValuesEqual(float f1, float f2)
|
||||
{
|
||||
if (float.IsNaN(f1) || float.IsNaN(f2))
|
||||
{
|
||||
return float.IsNaN(f1) && float.IsNaN(f2);
|
||||
}
|
||||
|
||||
return Math.Abs(f2 - f1) < float.Epsilon;
|
||||
}
|
||||
|
||||
public void Insert(int index, CSSNode node)
|
||||
{
|
||||
CheckDisposed();
|
||||
_children.Insert(index, node);
|
||||
node._parent = this;
|
||||
Native.CSSNodeInsertChild(_cssNode, node._cssNode, (uint)index);
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
CheckDisposed();
|
||||
var child = _children[index];
|
||||
child._parent = null;
|
||||
_children.RemoveAt(index);
|
||||
Native.CSSNodeRemoveChild(_cssNode, child._cssNode);
|
||||
}
|
||||
|
||||
public int IndexOf(CSSNode node)
|
||||
{
|
||||
CheckDisposed();
|
||||
return _children.IndexOf(node);
|
||||
}
|
||||
|
||||
public void SetMeasureFunction(MeasureFunction measureFunction)
|
||||
{
|
||||
CheckDisposed();
|
||||
_measureFunction = measureFunction;
|
||||
Native.CSSNodeSetMeasureFunc(_cssNode, measureFunction != null ? _measureFunc : null);
|
||||
}
|
||||
|
||||
public void CalculateLayout(CSSLayoutContext layoutContext)
|
||||
{
|
||||
CheckDisposed();
|
||||
Native.CSSNodeCalculateLayout(_cssNode, CSSConstants.Undefined, CSSConstants.Undefined, Native.CSSNodeStyleGetDirection(_cssNode));
|
||||
}
|
||||
|
||||
public long Measure(CSSNode node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode)
|
||||
{
|
||||
if (_measureFunction == null)
|
||||
{
|
||||
throw new InvalidOperationException(@"Measure function is not defined.");
|
||||
}
|
||||
|
||||
var output = new MeasureOutput();
|
||||
|
||||
_measureFunction(this,
|
||||
width,
|
||||
widthMode,
|
||||
height,
|
||||
heightMode,
|
||||
output);
|
||||
|
||||
return ((long)output.Width) << 32 | ((long)output.Height);
|
||||
}
|
||||
|
||||
private CSSSize MeasureInternal(
|
||||
IntPtr context,
|
||||
float width,
|
||||
CSSMeasureMode widthMode,
|
||||
float height,
|
||||
CSSMeasureMode heightMode)
|
||||
{
|
||||
var measureResult = Measure(this, width, widthMode, height, heightMode);
|
||||
var measuredWidth = 0xFFFFFFFF & (measureResult >> 32);
|
||||
var measuredHeight = 0xFFFFFFFF & measureResult;
|
||||
|
||||
return new CSSSize { width = measuredWidth, height = measuredHeight };
|
||||
}
|
||||
|
||||
private void PrintInternal(IntPtr context)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(ToString());
|
||||
}
|
||||
|
||||
public IEnumerator<CSSNode> GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable<CSSNode>)_children).GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable<CSSNode>)_children).GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
17
csharp/Facebook.CSSLayout/CSSOverflow.cs
Normal file
17
csharp/Facebook.CSSLayout/CSSOverflow.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.CSSLayout
|
||||
{
|
||||
public enum CSSOverflow
|
||||
{
|
||||
Visible,
|
||||
Hidden,
|
||||
}
|
||||
}
|
17
csharp/Facebook.CSSLayout/CSSPositionType.cs
Normal file
17
csharp/Facebook.CSSLayout/CSSPositionType.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.CSSLayout
|
||||
{
|
||||
public enum CSSPositionType
|
||||
{
|
||||
Relative,
|
||||
Absolute
|
||||
}
|
||||
}
|
15
csharp/Facebook.CSSLayout/CSSPrintFunc.cs
Normal file
15
csharp/Facebook.CSSLayout/CSSPrintFunc.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
public delegate void CSSPrintFunc(IntPtr context);
|
||||
}
|
18
csharp/Facebook.CSSLayout/CSSPrintOptions.cs
Normal file
18
csharp/Facebook.CSSLayout/CSSPrintOptions.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 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.CSSLayout
|
||||
{
|
||||
public enum CSSPrintOptions
|
||||
{
|
||||
Layout = 1,
|
||||
Style = 2,
|
||||
Children = 4,
|
||||
}
|
||||
}
|
20
csharp/Facebook.CSSLayout/CSSSize.cs
Normal file
20
csharp/Facebook.CSSLayout/CSSSize.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 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.CSSLayout
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct CSSSize
|
||||
{
|
||||
public float width;
|
||||
public float height;
|
||||
}
|
||||
}
|
17
csharp/Facebook.CSSLayout/CSSWrap.cs
Normal file
17
csharp/Facebook.CSSLayout/CSSWrap.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.CSSLayout
|
||||
{
|
||||
public enum CSSWrap
|
||||
{
|
||||
NoWrap,
|
||||
Wrap,
|
||||
}
|
||||
}
|
21
csharp/Facebook.CSSLayout/Facebook.CSSLayout.xproj
Normal file
21
csharp/Facebook.CSSLayout/Facebook.CSSLayout.xproj
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>75bb7605-e54b-4ede-8f5a-ff1f24464236</ProjectGuid>
|
||||
<RootNamespace>Facebook.CSSLayout</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
13
csharp/Facebook.CSSLayout/MeasureFunction.cs
Normal file
13
csharp/Facebook.CSSLayout/MeasureFunction.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 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.CSSLayout
|
||||
{
|
||||
public delegate void MeasureFunction(CSSNode node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode, MeasureOutput measureOutput);
|
||||
}
|
17
csharp/Facebook.CSSLayout/MeasureOutput.cs
Normal file
17
csharp/Facebook.CSSLayout/MeasureOutput.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.CSSLayout
|
||||
{
|
||||
public class MeasureOutput
|
||||
{
|
||||
public float Width { get; set; }
|
||||
public float Height { get; set; }
|
||||
}
|
||||
}
|
263
csharp/Facebook.CSSLayout/Native.cs
Normal file
263
csharp/Facebook.CSSLayout/Native.cs
Normal file
@@ -0,0 +1,263 @@
|
||||
/**
|
||||
* 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;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
internal static class Native
|
||||
{
|
||||
private const string DllName = "CSSLayout.dll";
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern IntPtr CSSNodeNew();
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeInit(IntPtr cssNode);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeFree(IntPtr cssNode);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeInsertChild(IntPtr node, IntPtr child, uint index);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeRemoveChild(IntPtr node, IntPtr child);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern IntPtr CSSNodeGetChild(IntPtr node, uint index);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern uint CSSNodeChildCount(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeCalculateLayout(IntPtr node,
|
||||
float availableWidth,
|
||||
float availableHeight,
|
||||
CSSDirection parentDirection);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeMarkDirty(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern bool CSSNodeIsDirty(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodePrint(IntPtr node, CSSPrintOptions options);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern bool CSSValueIsUndefined(float value);
|
||||
|
||||
#region CSS_NODE_PROPERTY
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeSetContext(IntPtr node, IntPtr context);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern IntPtr CSSNodeGetContext(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeSetMeasureFunc(IntPtr node, CSSMeasureFunc measureFunc);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSMeasureFunc CSSNodeGetMeasureFunc(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeSetPrintFunc(IntPtr node, CSSPrintFunc printFunc);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSPrintFunc CSSNodeGePrintFunc(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeSetIsTextnode(IntPtr node, bool isTextNode);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern bool CSSNodeGetIsTextnode(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeSetHasNewLayout(IntPtr node, bool hasNewLayout);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern bool CSSNodeGetHasNewLayout(IntPtr node);
|
||||
|
||||
#endregion
|
||||
|
||||
#region CSS_NODE_STYLE_PROPERTY
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetDirection(IntPtr node, CSSDirection direction);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSDirection CSSNodeStyleGetDirection(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetFlexDirection(IntPtr node, CSSFlexDirection flexDirection);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSFlexDirection CSSNodeStyleGetFlexDirection(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetJustifyContent(IntPtr node, CSSJustify justifyContent);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSJustify CSSNodeStyleGetJustifyContent(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetAlignContent(IntPtr node, CSSAlign alignContent);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSAlign CSSNodeStyleGetAlignContent(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetAlignItems(IntPtr node, CSSAlign alignItems);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSAlign CSSNodeStyleGetAlignItems(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetAlignSelf(IntPtr node, CSSAlign alignSelf);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSAlign CSSNodeStyleGetAlignSelf(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetPositionType(IntPtr node, CSSPositionType positionType);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSPositionType CSSNodeStyleGetPositionType(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetFlexWrap(IntPtr node, CSSWrap flexWrap);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSWrap CSSNodeStyleGetFlexWrap(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetOverflow(IntPtr node, CSSOverflow flexWrap);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSOverflow CSSNodeStyleGetOverflow(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetFlex(IntPtr node, float flex);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetFlex(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetFlexGrow(IntPtr node, float flexGrow);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetFlexGrow(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetFlexShrink(IntPtr node, float flexShrink);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetFlexShrink(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetFlexBasis(IntPtr node, float flexBasis);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetFlexBasis(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetWidth(IntPtr node, float width);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetWidth(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetHeight(IntPtr node, float height);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetHeight(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetMinWidth(IntPtr node, float minWidth);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetMinWidth(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetMinHeight(IntPtr node, float minHeight);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetMinHeight(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetMaxWidth(IntPtr node, float maxWidth);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetMaxWidth(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetMaxHeight(IntPtr node, float maxHeight);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetMaxHeight(IntPtr node);
|
||||
|
||||
#endregion
|
||||
|
||||
#region CSS_NODE_STYLE_EDGE_PROPERTY
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetPosition(IntPtr node, CSSEdge edge, float position);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetPosition(IntPtr node, CSSEdge edge);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetMargin(IntPtr node, CSSEdge edge, float margin);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetMargin(IntPtr node, CSSEdge edge);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetPadding(IntPtr node, CSSEdge edge, float padding);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetPadding(IntPtr node, CSSEdge edge);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern void CSSNodeStyleSetBorder(IntPtr node, CSSEdge edge, float border);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeStyleGetBorder(IntPtr node, CSSEdge edge);
|
||||
|
||||
#endregion
|
||||
|
||||
#region CSS_NODE_LAYOUT_PROPERTY
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeLayoutGetLeft(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeLayoutGetTop(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeLayoutGetRight(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeLayoutGetBottom(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeLayoutGetWidth(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern float CSSNodeLayoutGetHeight(IntPtr node);
|
||||
|
||||
[DllImport(DllName)]
|
||||
public static extern CSSDirection CSSNodeLayoutGetDirection(IntPtr node);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
32
csharp/Facebook.CSSLayout/Properties/AssemblyInfo.cs
Normal file
32
csharp/Facebook.CSSLayout/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Facebook, Inc.")]
|
||||
[assembly: AssemblyProduct("Facebook.CSSLayout")]
|
||||
[assembly: AssemblyTrademark("Copyright (c) 2014-present, Facebook, Inc.")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("75bb7605-e54b-4ede-8f5a-ff1f24464236")]
|
||||
|
||||
[assembly: NeutralResourcesLanguage("en")]
|
||||
|
||||
[assembly: AssemblyVersion("3.0.0.0")]
|
188
csharp/Facebook.CSSLayout/Spacing.cs
Normal file
188
csharp/Facebook.CSSLayout/Spacing.cs
Normal file
@@ -0,0 +1,188 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
namespace Facebook.CSSLayout
|
||||
{
|
||||
/// <summary>
|
||||
/// Class representing CSS spacing (padding, margin, and borders). This is mostly necessary to
|
||||
/// properly implement interactions and updates for properties like margin, marginLeft, and
|
||||
/// marginHorizontal.
|
||||
/// </summary>
|
||||
public class Spacing
|
||||
{
|
||||
/// <summary>
|
||||
/// Spacing type that represents the left direction. E.g. <code>marginLeft</code>.
|
||||
/// </summary>
|
||||
public const int Left = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Spacing type that represents the top direction. E.g. <code>marginTop</code>.
|
||||
/// </summary>
|
||||
public const int Top = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Spacing type that represents the right direction. E.g. <code>marginRight</code>.
|
||||
/// </summary>
|
||||
public const int Right = 2;
|
||||
|
||||
/// <summary>
|
||||
/// Spacing type that represents the bottom direction. E.g. <code>marginBottom</code>.
|
||||
/// </summary>
|
||||
public const int Bottom = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Spacing type that represents start direction e.g. left in left-to-right, right in right-to-left.
|
||||
/// </summary>
|
||||
public const int Start = 4;
|
||||
|
||||
/// <summary>
|
||||
/// Spacing type that represents end direction e.g. right in left-to-right, left in right-to-left.
|
||||
/// </summary>
|
||||
public const int End = 5;
|
||||
|
||||
/// <summary>
|
||||
/// Spacing type that represents horizontal direction (left and right). E.g. <code>marginHorizontal</code>.
|
||||
/// </summary>
|
||||
public const int Horizontal = 6;
|
||||
|
||||
/// <summary>
|
||||
/// Spacing type that represents vertical direction (top and bottom). E.g. <code>marginVertical</code>.
|
||||
/// </summary>
|
||||
public const int Vertical = 7;
|
||||
|
||||
/// <summary>
|
||||
/// Spacing type that represents all directions (left, top, right, bottom). E.g. <code>margin</code>.
|
||||
/// </summary>
|
||||
public const int All = 8;
|
||||
|
||||
private static readonly int[] _flagsMap = new[]
|
||||
{
|
||||
1, /*LEFT*/
|
||||
2, /*TOP*/
|
||||
4, /*RIGHT*/
|
||||
8, /*BOTTOM*/
|
||||
16, /*START*/
|
||||
32, /*END*/
|
||||
64, /*HORIZONTAL*/
|
||||
128, /*VERTICAL*/
|
||||
256, /*ALL*/
|
||||
};
|
||||
|
||||
private int _valueFlags = 0;
|
||||
private readonly float _defaultValue;
|
||||
private readonly float[] _spacing = NewFullSpacingArray();
|
||||
private bool _hasAliasesSet;
|
||||
|
||||
public Spacing() : this(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Spacing(float defaultValue)
|
||||
{
|
||||
_defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public float Get(int spacingType)
|
||||
{
|
||||
var defaultValue = spacingType == Start || spacingType == End ? CSSConstants.Undefined : _defaultValue;
|
||||
|
||||
if (_valueFlags == 0)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
if ((_valueFlags & _flagsMap[spacingType]) != 0)
|
||||
{
|
||||
return _spacing[spacingType];
|
||||
}
|
||||
|
||||
if (_hasAliasesSet)
|
||||
{
|
||||
var secondType = spacingType == Top || spacingType == Bottom ? Vertical : Horizontal;
|
||||
if ((_valueFlags & _flagsMap[secondType]) != 0)
|
||||
{
|
||||
return _spacing[secondType];
|
||||
}
|
||||
else if ((_valueFlags & _flagsMap[All]) != 0)
|
||||
{
|
||||
return _spacing[All];
|
||||
}
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public float GetRaw(int spacingType)
|
||||
{
|
||||
return _spacing[spacingType];
|
||||
}
|
||||
|
||||
public bool Set(int spacingType, float value)
|
||||
{
|
||||
if (FloatEqual(_spacing[spacingType], value))
|
||||
{
|
||||
_spacing[spacingType] = value;
|
||||
|
||||
if (CSSConstants.IsUndefined(value))
|
||||
{
|
||||
_valueFlags &= ~_flagsMap[spacingType];
|
||||
}
|
||||
else
|
||||
{
|
||||
_valueFlags |= ~_flagsMap[spacingType];
|
||||
}
|
||||
|
||||
_hasAliasesSet =
|
||||
(_valueFlags & _flagsMap[All]) != 0 ||
|
||||
(_valueFlags & _flagsMap[Vertical]) != 0 ||
|
||||
(_valueFlags & _flagsMap[Horizontal]) != 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
for (var i = 0; i < 9; i++) { _spacing[i] = CSSConstants.Undefined; }
|
||||
_hasAliasesSet = false;
|
||||
_valueFlags = 0;
|
||||
}
|
||||
|
||||
private static bool FloatEqual(float f1, float f2)
|
||||
{
|
||||
if (float.IsNaN(f1) || float.IsNaN(f2))
|
||||
{
|
||||
return float.IsNaN(f1) && float.IsNaN(f2);
|
||||
}
|
||||
|
||||
return Math.Abs(f2 - f1) < float.Epsilon;
|
||||
}
|
||||
|
||||
private static float[] NewFullSpacingArray()
|
||||
{
|
||||
return new float[]
|
||||
{
|
||||
CSSConstants.Undefined,
|
||||
CSSConstants.Undefined,
|
||||
CSSConstants.Undefined,
|
||||
CSSConstants.Undefined,
|
||||
CSSConstants.Undefined,
|
||||
CSSConstants.Undefined,
|
||||
CSSConstants.Undefined,
|
||||
CSSConstants.Undefined,
|
||||
CSSConstants.Undefined
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
14
csharp/Facebook.CSSLayout/project.json
Normal file
14
csharp/Facebook.CSSLayout/project.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"language": "en",
|
||||
"version": "3.0.0-*",
|
||||
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.6.0"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"netstandard1.6": {
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user