2016-09-22 16:22:34 -07:00
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
|
2016-10-07 11:07:51 -07:00
|
|
|
|
private WeakReference _parent;
|
2016-09-22 16:22:34 -07:00
|
|
|
|
private List<CSSNode> _children;
|
|
|
|
|
private MeasureFunction _measureFunction;
|
|
|
|
|
private CSSMeasureFunc _measureFunc;
|
|
|
|
|
private CSSPrintFunc _printFunc;
|
|
|
|
|
private object _data;
|
|
|
|
|
|
|
|
|
|
public CSSNode()
|
|
|
|
|
{
|
|
|
|
|
_measureFunc = MeasureInternal;
|
|
|
|
|
_printFunc = PrintInternal;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-06 06:04:56 -07:00
|
|
|
|
private void AssertNativeInstance()
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
if (_isDisposed)
|
|
|
|
|
{
|
|
|
|
|
throw new ObjectDisposedException("CSSNode");
|
|
|
|
|
}
|
2016-10-06 06:04:56 -07:00
|
|
|
|
|
|
|
|
|
if (_cssNode == IntPtr.Zero)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Null native pointer");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~CSSNode()
|
|
|
|
|
{
|
|
|
|
|
Dispose(false);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
if (!_isDisposed)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
if (disposing)
|
|
|
|
|
{
|
|
|
|
|
FreeManaged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FreeUnmanaged();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
_isDisposed = true;
|
2016-10-06 06:04:56 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FreeManaged()
|
|
|
|
|
{
|
|
|
|
|
_children = null;
|
|
|
|
|
_parent = null;
|
|
|
|
|
_measureFunction = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FreeUnmanaged()
|
|
|
|
|
{
|
|
|
|
|
if (_cssNode != IntPtr.Zero)
|
|
|
|
|
{
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeFree(_cssNode);
|
2016-10-06 06:04:56 -07:00
|
|
|
|
_cssNode = IntPtr.Zero;
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
if (_cssNode != IntPtr.Zero)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Allready initialized node");
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-22 16:22:34 -07:00
|
|
|
|
_cssNode = Native.CSSNodeNew();
|
|
|
|
|
_children = new List<CSSNode>(4);
|
|
|
|
|
Native.CSSNodeSetPrintFunc(_cssNode, _printFunc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
|
|
|
|
FreeManaged();
|
|
|
|
|
FreeUnmanaged();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsDirty
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeIsDirty(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void MarkDirty()
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeMarkDirty(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsTextNode
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeGetIsTextnode(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeSetIsTextnode(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool HasNewLayout
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeGetHasNewLayout(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MarkHasNewLayout()
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeSetHasNewLayout(_cssNode, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSNode Parent
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-10-07 11:07:51 -07:00
|
|
|
|
return _parent != null ? _parent.Target as CSSNode : null;
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsMeasureDefined
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _measureFunction != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSDirection StyleDirection
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetDirection(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetDirection(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSFlexDirection FlexDirection
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetFlexDirection(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetFlexDirection(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSJustify JustifyContent
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetJustifyContent(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetJustifyContent(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSAlign AlignItems
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetAlignItems(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetAlignItems(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSAlign AlignSelf
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetAlignSelf(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetAlignSelf(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSAlign AlignContent
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetAlignContent(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetAlignContent(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSPositionType PositionType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetPositionType(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetPositionType(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSWrap Wrap
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetFlexWrap(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetFlexWrap(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float Flex
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetFlex(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetFlex(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float FlexGrow
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetFlexGrow(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetFlexGrow(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float FlexShrink
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetFlexShrink(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetFlexShrink(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float FlexBasis
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetFlexBasis(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetFlexBasis(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Spacing GetMargin()
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetMargin(_cssNode, edge, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Spacing GetPadding()
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetPadding(_cssNode, edge, padding);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Spacing GetBorder()
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetBorder(_cssNode, edge, border);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Spacing GetPosition()
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float StyleWidth
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetWidth(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetWidth(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float StyleHeight
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetHeight(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetHeight(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float StyleMaxWidth
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetMaxWidth(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetMaxWidth(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float StyleMaxHeight
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetMaxHeight(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetMaxHeight(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float StyleMinWidth
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetMinWidth(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetMinWidth(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float StyleMinHeight
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetMinHeight(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetMinHeight(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float LayoutX
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeLayoutGetLeft(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float LayoutY
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeLayoutGetTop(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float LayoutWidth
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeLayoutGetWidth(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float LayoutHeight
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeLayoutGetHeight(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSDirection LayoutDirection
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeLayoutGetDirection(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSOverflow Overflow
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return Native.CSSNodeStyleGetOverflow(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetOverflow(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object Data
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return _data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
_data = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSNode this[int index]
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return _children[index];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Count
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return _children.Count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MarkLayoutSeen()
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
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)
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
_children.Insert(index, node);
|
2016-10-07 11:07:51 -07:00
|
|
|
|
node._parent = new WeakReference(this);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
Native.CSSNodeInsertChild(_cssNode, node._cssNode, (uint)index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveAt(int index)
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
var child = _children[index];
|
|
|
|
|
child._parent = null;
|
|
|
|
|
_children.RemoveAt(index);
|
|
|
|
|
Native.CSSNodeRemoveChild(_cssNode, child._cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int IndexOf(CSSNode node)
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
return _children.IndexOf(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetMeasureFunction(MeasureFunction measureFunction)
|
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
_measureFunction = measureFunction;
|
|
|
|
|
Native.CSSNodeSetMeasureFunc(_cssNode, measureFunction != null ? _measureFunc : null);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-27 04:34:52 -07:00
|
|
|
|
public void CalculateLayout()
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-10-06 06:04:56 -07:00
|
|
|
|
AssertNativeInstance();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
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();
|
|
|
|
|
}
|
2016-10-07 11:07:50 -07:00
|
|
|
|
|
|
|
|
|
public static int GetInstanceCount()
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeGetInstanceCount();
|
|
|
|
|
}
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
2016-10-07 11:07:48 -07:00
|
|
|
|
}
|