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;
|
2016-10-19 11:01:24 -07:00
|
|
|
|
using System.Text;
|
2016-09-22 16:22:34 -07:00
|
|
|
|
|
|
|
|
|
namespace Facebook.CSSLayout
|
|
|
|
|
{
|
2016-10-25 07:38:06 -07:00
|
|
|
|
public class CSSNode : IEnumerable<CSSNode>
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
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;
|
2016-10-26 06:51:39 -07:00
|
|
|
|
private CSSMeasureFunc _cssMeasureFunc;
|
2016-09-22 16:22:34 -07:00
|
|
|
|
private object _data;
|
|
|
|
|
|
|
|
|
|
public CSSNode()
|
|
|
|
|
{
|
2016-10-24 10:35:41 -07:00
|
|
|
|
CSSLogger.Initialize();
|
2016-10-06 06:04:56 -07:00
|
|
|
|
|
2016-10-24 10:35:41 -07:00
|
|
|
|
_cssNode = Native.CSSNodeNew();
|
2016-10-06 06:04:56 -07:00
|
|
|
|
if (_cssNode == IntPtr.Zero)
|
|
|
|
|
{
|
2016-10-24 10:35:41 -07:00
|
|
|
|
throw new InvalidOperationException("Failed to allocate native memory");
|
2016-10-06 06:04:56 -07:00
|
|
|
|
}
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-24 10:35:41 -07:00
|
|
|
|
~CSSNode()
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-10-24 10:35:41 -07:00
|
|
|
|
Native.CSSNodeFree(_cssNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-24 10:35:41 -07:00
|
|
|
|
public void Reset()
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-10-26 07:24:44 -07:00
|
|
|
|
_measureFunction = null;
|
|
|
|
|
_data = null;
|
|
|
|
|
|
2016-10-24 10:35:41 -07:00
|
|
|
|
Native.CSSNodeReset(_cssNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsDirty
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeIsDirty(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void MarkDirty()
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeMarkDirty(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool HasNewLayout
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeGetHasNewLayout(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MarkHasNewLayout()
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeSetHasNewLayout(_cssNode, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSNode Parent
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
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
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetDirection(_cssNode);
|
|
|
|
|
}
|
2016-10-26 06:51:39 -07:00
|
|
|
|
|
2016-09-22 16:22:34 -07:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetDirection(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSFlexDirection FlexDirection
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetFlexDirection(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetFlexDirection(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSJustify JustifyContent
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetJustifyContent(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetJustifyContent(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSAlign AlignItems
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetAlignItems(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetAlignItems(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSAlign AlignSelf
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetAlignSelf(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetAlignSelf(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSAlign AlignContent
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetAlignContent(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetAlignContent(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSPositionType PositionType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetPositionType(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetPositionType(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSWrap Wrap
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetFlexWrap(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetFlexWrap(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float Flex
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetFlex(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float FlexGrow
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetFlexGrow(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetFlexGrow(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float FlexShrink
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetFlexShrink(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetFlexShrink(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float FlexBasis
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetFlexBasis(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetFlexBasis(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-24 10:35:43 -07:00
|
|
|
|
public float GetMargin(CSSEdge edge)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-10-24 10:35:43 -07:00
|
|
|
|
return Native.CSSNodeStyleGetMargin(_cssNode, edge);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetMargin(CSSEdge edge, float value)
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetMargin(_cssNode, edge, value);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-24 10:35:43 -07:00
|
|
|
|
public float GetPadding(CSSEdge edge)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-10-24 10:35:43 -07:00
|
|
|
|
return Native.CSSNodeStyleGetPadding(_cssNode, edge);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetPadding(CSSEdge edge, float padding)
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetPadding(_cssNode, edge, padding);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-24 10:35:43 -07:00
|
|
|
|
public float GetBorder(CSSEdge edge)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-10-24 10:35:43 -07:00
|
|
|
|
return Native.CSSNodeStyleGetBorder(_cssNode, edge);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetBorder(CSSEdge edge, float border)
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetBorder(_cssNode, edge, border);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-24 10:35:43 -07:00
|
|
|
|
public float GetPosition(CSSEdge edge)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-10-24 10:35:43 -07:00
|
|
|
|
return Native.CSSNodeStyleGetPosition(_cssNode, edge);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetPosition(CSSEdge edge, float position)
|
|
|
|
|
{
|
2016-10-12 09:08:34 -07:00
|
|
|
|
Native.CSSNodeStyleSetPosition(_cssNode, edge, position);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float StyleWidth
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetWidth(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetWidth(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float StyleHeight
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetHeight(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetHeight(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float StyleMaxWidth
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetMaxWidth(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetMaxWidth(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float StyleMaxHeight
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetMaxHeight(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetMaxHeight(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float StyleMinWidth
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetMinWidth(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetMinWidth(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float StyleMinHeight
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetMinHeight(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetMinHeight(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float LayoutX
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeLayoutGetLeft(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float LayoutY
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeLayoutGetTop(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float LayoutWidth
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeLayoutGetWidth(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float LayoutHeight
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeLayoutGetHeight(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSDirection LayoutDirection
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeLayoutGetDirection(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSOverflow Overflow
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Native.CSSNodeStyleGetOverflow(_cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Native.CSSNodeStyleSetOverflow(_cssNode, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object Data
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_data = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CSSNode this[int index]
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _children[index];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Count
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-26 06:51:39 -07:00
|
|
|
|
return _children != null ? _children.Count : 0;
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MarkLayoutSeen()
|
|
|
|
|
{
|
|
|
|
|
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-26 06:51:39 -07:00
|
|
|
|
if (_children == null)
|
|
|
|
|
{
|
|
|
|
|
_children = new List<CSSNode>(4);
|
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
|
|
|
|
var child = _children[index];
|
|
|
|
|
child._parent = null;
|
|
|
|
|
_children.RemoveAt(index);
|
|
|
|
|
Native.CSSNodeRemoveChild(_cssNode, child._cssNode);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-25 07:38:06 -07:00
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
2016-10-26 06:51:39 -07:00
|
|
|
|
if (_children != null)
|
2016-10-25 07:38:06 -07:00
|
|
|
|
{
|
2016-10-26 06:51:39 -07:00
|
|
|
|
while (_children.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
RemoveAt(_children.Count-1);
|
|
|
|
|
}
|
2016-10-25 07:38:06 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-22 16:22:34 -07:00
|
|
|
|
public int IndexOf(CSSNode node)
|
|
|
|
|
{
|
2016-10-26 06:51:39 -07:00
|
|
|
|
return _children != null ? _children.IndexOf(node) : -1;
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetMeasureFunction(MeasureFunction measureFunction)
|
|
|
|
|
{
|
|
|
|
|
_measureFunction = measureFunction;
|
2016-10-27 11:38:32 -07:00
|
|
|
|
_cssMeasureFunc = measureFunction != null ? MeasureInternal : (CSSMeasureFunc)null;
|
2016-10-26 06:51:39 -07:00
|
|
|
|
Native.CSSNodeSetMeasureFunc(_cssNode, _cssMeasureFunc);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-27 04:34:52 -07:00
|
|
|
|
public void CalculateLayout()
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-10-26 06:51:39 -07:00
|
|
|
|
Native.CSSNodeCalculateLayout(
|
|
|
|
|
_cssNode,
|
|
|
|
|
CSSConstants.Undefined,
|
|
|
|
|
CSSConstants.Undefined,
|
|
|
|
|
Native.CSSNodeStyleGetDirection(_cssNode));
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CSSSize MeasureInternal(
|
2016-10-27 10:52:11 -07:00
|
|
|
|
IntPtr node,
|
2016-09-22 16:22:34 -07:00
|
|
|
|
float width,
|
|
|
|
|
CSSMeasureMode widthMode,
|
|
|
|
|
float height,
|
|
|
|
|
CSSMeasureMode heightMode)
|
|
|
|
|
{
|
2016-10-13 07:52:46 -07:00
|
|
|
|
if (_measureFunction == null)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Measure function is not defined.");
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-27 10:52:09 -07:00
|
|
|
|
long output = _measureFunction(this, width, widthMode, height, heightMode);
|
|
|
|
|
return new CSSSize { width = MeasureOutput.GetWidth(output), height = MeasureOutput.GetHeight(output) };
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-26 06:51:39 -07:00
|
|
|
|
public string Print(CSSPrintOptions options =
|
|
|
|
|
CSSPrintOptions.Layout|CSSPrintOptions.Style|CSSPrintOptions.Children)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-10-19 11:01:24 -07:00
|
|
|
|
StringBuilder sb = new StringBuilder();
|
2016-11-09 10:14:22 -08:00
|
|
|
|
CSSLogger.Func orig = CSSLogger.Logger;
|
|
|
|
|
CSSLogger.Logger = (level, message) => {sb.Append(message);};
|
2016-10-19 11:01:24 -07:00
|
|
|
|
Native.CSSNodePrint(_cssNode, options);
|
2016-11-09 10:14:22 -08:00
|
|
|
|
CSSLogger.Logger = orig;
|
2016-10-19 11:01:24 -07:00
|
|
|
|
return sb.ToString();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerator<CSSNode> GetEnumerator()
|
|
|
|
|
{
|
2016-10-26 06:51:39 -07:00
|
|
|
|
return _children != null ? ((IEnumerable<CSSNode>)_children).GetEnumerator() :
|
|
|
|
|
System.Linq.Enumerable.Empty<CSSNode>().GetEnumerator();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
{
|
2016-10-26 06:51:39 -07:00
|
|
|
|
return _children != null ? ((IEnumerable<CSSNode>)_children).GetEnumerator() :
|
|
|
|
|
System.Linq.Enumerable.Empty<CSSNode>().GetEnumerator();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
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
|
|
|
|
}
|