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;
|
2016-10-19 11:01:24 -07:00
|
|
|
|
using System.Text;
|
2016-09-22 16:22:34 -07:00
|
|
|
|
|
2016-12-02 11:18:16 -08:00
|
|
|
|
namespace Facebook.Yoga
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-12-02 11:18:16 -08:00
|
|
|
|
public partial class YogaNode : IEnumerable<YogaNode>
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-12-23 08:29:31 -08:00
|
|
|
|
private Native.YGNodeHandle _ygNode;
|
2016-10-07 11:07:51 -07:00
|
|
|
|
private WeakReference _parent;
|
2016-12-02 11:18:16 -08:00
|
|
|
|
private List<YogaNode> _children;
|
2016-09-22 16:22:34 -07:00
|
|
|
|
private MeasureFunction _measureFunction;
|
2016-12-03 04:40:18 -08:00
|
|
|
|
private YogaMeasureFunc _ygMeasureFunc;
|
2016-09-22 16:22:34 -07:00
|
|
|
|
private object _data;
|
|
|
|
|
|
2016-12-02 11:18:16 -08:00
|
|
|
|
public YogaNode()
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-12-02 11:18:16 -08:00
|
|
|
|
YogaLogger.Initialize();
|
2016-10-06 06:04:56 -07:00
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
|
_ygNode = Native.YGNodeNew();
|
2016-12-23 08:29:31 -08:00
|
|
|
|
if (_ygNode.IsInvalid)
|
2016-10-06 06:04:56 -07:00
|
|
|
|
{
|
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
|
|
|
|
public void Reset()
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-10-26 07:24:44 -07:00
|
|
|
|
_measureFunction = null;
|
|
|
|
|
_data = null;
|
|
|
|
|
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeReset(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsDirty
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeIsDirty(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void MarkDirty()
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeMarkDirty(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool HasNewLayout
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeGetHasNewLayout(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MarkHasNewLayout()
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeSetHasNewLayout(_ygNode, true);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 11:18:16 -08:00
|
|
|
|
public YogaNode Parent
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-02 11:18:16 -08:00
|
|
|
|
return _parent != null ? _parent.Target as YogaNode : null;
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsMeasureDefined
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _measureFunction != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 11:18:16 -08:00
|
|
|
|
public void CopyStyle(YogaNode srcNode)
|
2016-11-17 09:10:47 -08:00
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeCopyStyle(_ygNode, srcNode._ygNode);
|
2016-11-17 09:10:47 -08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
|
public YogaDirection StyleDirection
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetDirection(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
2016-10-26 06:51:39 -07:00
|
|
|
|
|
2016-09-22 16:22:34 -07:00
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetDirection(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
|
public YogaFlexDirection FlexDirection
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetFlexDirection(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetFlexDirection(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
|
public YogaJustify JustifyContent
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetJustifyContent(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetJustifyContent(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
|
public YogaAlign AlignItems
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetAlignItems(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetAlignItems(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
|
public YogaAlign AlignSelf
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetAlignSelf(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetAlignSelf(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
|
public YogaAlign AlignContent
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetAlignContent(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetAlignContent(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
|
public YogaPositionType PositionType
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetPositionType(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetPositionType(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
|
public YogaWrap Wrap
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetFlexWrap(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetFlexWrap(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float Flex
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetFlex(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float FlexGrow
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetFlexGrow(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetFlexGrow(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float FlexShrink
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetFlexShrink(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetFlexShrink(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 23:01:31 +01:00
|
|
|
|
public YogaValue FlexBasis
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetFlexBasis(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetFlexBasis(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 23:01:31 +01:00
|
|
|
|
public YogaValue GetMargin(YogaEdge edge)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetMargin(_ygNode, edge);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 23:01:31 +01:00
|
|
|
|
public void SetMargin(YogaEdge edge, YogaValue value)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetMargin(_ygNode, edge, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 23:01:31 +01:00
|
|
|
|
public YogaValue GetPadding(YogaEdge edge)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetPadding(_ygNode, edge);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 23:01:31 +01:00
|
|
|
|
public void SetPadding(YogaEdge edge, YogaValue padding)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetPadding(_ygNode, edge, padding);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
|
public float GetBorder(YogaEdge edge)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetBorder(_ygNode, edge);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
|
public void SetBorder(YogaEdge edge, float border)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetBorder(_ygNode, edge, border);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 23:01:31 +01:00
|
|
|
|
public YogaValue GetPosition(YogaEdge edge)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetPosition(_ygNode, edge);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 23:01:31 +01:00
|
|
|
|
public void SetPosition(YogaEdge edge, YogaValue position)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetPosition(_ygNode, edge, position);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 23:01:31 +01:00
|
|
|
|
public YogaValue Width
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetWidth(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetWidth(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 23:01:31 +01:00
|
|
|
|
public YogaValue Height
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetHeight(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetHeight(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 23:01:31 +01:00
|
|
|
|
public YogaValue MaxWidth
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetMaxWidth(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetMaxWidth(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 23:01:31 +01:00
|
|
|
|
public YogaValue MaxHeight
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetMaxHeight(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetMaxHeight(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 23:01:31 +01:00
|
|
|
|
public YogaValue MinWidth
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetMinWidth(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetMinWidth(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-19 23:01:31 +01:00
|
|
|
|
public YogaValue MinHeight
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetMinHeight(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetMinHeight(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 11:18:16 -08:00
|
|
|
|
public float StyleAspectRatio
|
2016-11-21 10:12:26 -08:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetAspectRatio(_ygNode);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetAspectRatio(_ygNode, value);
|
2016-11-21 10:12:26 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-22 16:22:34 -07:00
|
|
|
|
public float LayoutX
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeLayoutGetLeft(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float LayoutY
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeLayoutGetTop(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float LayoutWidth
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeLayoutGetWidth(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float LayoutHeight
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeLayoutGetHeight(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
|
public YogaDirection LayoutDirection
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeLayoutGetDirection(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
|
public YogaOverflow Overflow
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeStyleGetOverflow(_ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleSetOverflow(_ygNode, value);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object Data
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return _data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_data = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 11:18:16 -08:00
|
|
|
|
public YogaNode this[int index]
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
|
|
|
|
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()
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeSetHasNewLayout(_ygNode, false);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 11:18:16 -08:00
|
|
|
|
public void Insert(int index, YogaNode node)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-10-26 06:51:39 -07:00
|
|
|
|
if (_children == null)
|
|
|
|
|
{
|
2016-12-02 11:18:16 -08:00
|
|
|
|
_children = new List<YogaNode>(4);
|
2016-10-26 06:51:39 -07:00
|
|
|
|
}
|
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-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeInsertChild(_ygNode, node._ygNode, (uint)index);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveAt(int index)
|
|
|
|
|
{
|
|
|
|
|
var child = _children[index];
|
|
|
|
|
child._parent = null;
|
|
|
|
|
_children.RemoveAt(index);
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeRemoveChild(_ygNode, child._ygNode);
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
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-12-02 11:18:16 -08:00
|
|
|
|
public int IndexOf(YogaNode node)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
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-12-03 04:40:18 -08:00
|
|
|
|
_ygMeasureFunc = measureFunction != null ? MeasureInternal : (YogaMeasureFunc)null;
|
|
|
|
|
Native.YGNodeSetMeasureFunc(_ygNode, _ygMeasureFunc);
|
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-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeCalculateLayout(
|
|
|
|
|
_ygNode,
|
2016-12-02 05:47:43 -08:00
|
|
|
|
YogaConstants.Undefined,
|
|
|
|
|
YogaConstants.Undefined,
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodeStyleGetDirection(_ygNode));
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 11:18:16 -08:00
|
|
|
|
private YogaSize MeasureInternal(
|
2016-10-27 10:52:11 -07:00
|
|
|
|
IntPtr node,
|
2016-09-22 16:22:34 -07:00
|
|
|
|
float width,
|
2016-12-02 05:47:43 -08:00
|
|
|
|
YogaMeasureMode widthMode,
|
2016-09-22 16:22:34 -07:00
|
|
|
|
float height,
|
2016-12-02 05:47:43 -08:00
|
|
|
|
YogaMeasureMode heightMode)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
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);
|
2016-12-02 11:18:16 -08:00
|
|
|
|
return new YogaSize { width = MeasureOutput.GetWidth(output), height = MeasureOutput.GetHeight(output) };
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
|
public string Print(YogaPrintOptions options =
|
|
|
|
|
YogaPrintOptions.Layout|YogaPrintOptions.Style|YogaPrintOptions.Children)
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-10-19 11:01:24 -07:00
|
|
|
|
StringBuilder sb = new StringBuilder();
|
2016-12-02 11:18:16 -08:00
|
|
|
|
YogaLogger.Func orig = YogaLogger.Logger;
|
|
|
|
|
YogaLogger.Logger = (level, message) => {sb.Append(message);};
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGNodePrint(_ygNode, options);
|
2016-12-02 11:18:16 -08:00
|
|
|
|
YogaLogger.Logger = orig;
|
2016-10-19 11:01:24 -07:00
|
|
|
|
return sb.ToString();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 11:18:16 -08:00
|
|
|
|
public IEnumerator<YogaNode> GetEnumerator()
|
2016-09-22 16:22:34 -07:00
|
|
|
|
{
|
2016-12-02 11:18:16 -08:00
|
|
|
|
return _children != null ? ((IEnumerable<YogaNode>)_children).GetEnumerator() :
|
|
|
|
|
System.Linq.Enumerable.Empty<YogaNode>().GetEnumerator();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
{
|
2016-12-02 11:18:16 -08:00
|
|
|
|
return _children != null ? ((IEnumerable<YogaNode>)_children).GetEnumerator() :
|
|
|
|
|
System.Linq.Enumerable.Empty<YogaNode>().GetEnumerator();
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
2016-10-07 11:07:50 -07:00
|
|
|
|
|
|
|
|
|
public static int GetInstanceCount()
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGNodeGetInstanceCount();
|
2016-10-07 11:07:50 -07:00
|
|
|
|
}
|
2016-11-14 03:27:33 -08:00
|
|
|
|
|
2016-11-23 11:12:51 -08:00
|
|
|
|
public static void SetExperimentalFeatureEnabled(
|
2016-12-02 05:47:43 -08:00
|
|
|
|
YogaExperimentalFeature feature,
|
2016-11-14 03:27:33 -08:00
|
|
|
|
bool enabled)
|
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
Native.YGSetExperimentalFeatureEnabled(feature, enabled);
|
2016-11-14 03:27:33 -08:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-02 05:47:43 -08:00
|
|
|
|
public static bool IsExperimentalFeatureEnabled(YogaExperimentalFeature feature)
|
2016-11-14 03:27:33 -08:00
|
|
|
|
{
|
2016-12-03 04:40:18 -08:00
|
|
|
|
return Native.YGIsExperimentalFeatureEnabled(feature);
|
2016-11-14 03:27:33 -08:00
|
|
|
|
}
|
2016-09-22 16:22:34 -07:00
|
|
|
|
}
|
2016-10-07 11:07:48 -07:00
|
|
|
|
}
|