public YogaNode(
            YogaPrint print,
            bool hasNewLayout,
            YogaNodeType nodeType,
            YogaMeasure measure,
            YogaBaseline baseline,
            YogaDirtied dirtied,
            YogaStyle style,
            YogaLayout layout,
            int lineIndex,
            YogaNode owner,
            List <YogaNode> children,
            YogaNode nextChild,
            YogaConfig config,
            bool isDirty,
            YogaValue[] resolvedDimensions)
        {
            _print              = print;
            _hasNewLayout       = hasNewLayout;
            _nodeType           = nodeType;
            _measure            = measure;
            _baseline           = baseline;
            _dirtied            = dirtied;
            _style              = style;
            _layout             = layout;
            _lineIndex          = lineIndex;
            _owner              = owner;
            _children           = new List <YogaNode>(children);
            _nextChild          = nextChild;
            _config             = config;
            _isDirty            = isDirty;
            _resolvedDimensions = YogaArray.From(resolvedDimensions);

            Interlocked.Increment(ref _instanceCount);
        }
        public void Reset()
        {
            if (_children.Count > 0)
            {
                throw new InvalidOperationException("Cannot reset a node which still has children attached");
            }

            if (_owner != null)
            {
                throw new InvalidOperationException("Cannot reset a node still attached to a owner");
            }

            Clear();

            _print              = null;
            _hasNewLayout       = true;
            _nodeType           = YogaNodeType.Default;
            _measure            = null;
            _baseline           = null;
            _dirtied            = null;
            _style              = new YogaStyle();
            _layout             = new YogaLayout();
            _lineIndex          = 0;
            _owner              = null;
            _children           = new List <YogaNode>();
            _nextChild          = null;
            _isDirty            = false;
            _resolvedDimensions = new YogaArray <YogaValue>(new YogaValue[] { YogaValue.Undefined, YogaValue.Undefined });

            if (_config.UseWebDefaults)
            {
                Style.FlexDirection = YogaFlexDirection.Row;
                Style.AlignContent  = YogaAlign.Stretch;
            }
        }
        private static YogaValue ComputedEdgeValue(YogaArray <YogaValue> edges, YogaEdge edge, YogaValue defaultValue)
        {
            if (edges[edge].Unit != YogaUnit.Undefined)
            {
                return(edges[edge]);
            }

            if ((edge == YogaEdge.Top || edge == YogaEdge.Bottom) && edges[YogaEdge.Vertical].Unit != YogaUnit.Undefined)
            {
                return(edges[YogaEdge.Vertical]);
            }

            if ((edge == YogaEdge.Left || edge == YogaEdge.Right || edge == YogaEdge.Start || edge == YogaEdge.End) && edges[YogaEdge.Horizontal].Unit != YogaUnit.Undefined)
            {
                return(edges[YogaEdge.Horizontal]);
            }

            if (edges[YogaEdge.All].Unit != YogaUnit.Undefined)
            {
                return(edges[YogaEdge.All]);
            }

            if (edge == YogaEdge.Start || edge == YogaEdge.End)
            {
                return(YogaValue.Undefined);
            }

            return(defaultValue);
        }
        public static bool operator ==(YogaLayout self, YogaLayout layout)
        {
            if (object.ReferenceEquals(self, layout))
            {
                return(true);
            }

            if (object.ReferenceEquals(self, null) || object.ReferenceEquals(layout, null))
            {
                return(false);
            }

            var isEqual = YogaArray.Equal(self.Position, layout.Position) &&
                          YogaArray.Equal(self.Dimensions, layout.Dimensions) &&
                          YogaArray.Equal(self.Margin, layout.Margin) &&
                          YogaArray.Equal(self.Border, layout.Border) &&
                          YogaArray.Equal(self.Padding, layout.Padding) &&
                          self.Direction == layout.Direction &&
                          self.HadOverflow == layout.HadOverflow &&
                          self.LastOwnerDirection == layout.LastOwnerDirection &&
                          self.NextCachedMeasurementsIndex == layout.NextCachedMeasurementsIndex &&
                          self.CachedLayout == layout.CachedLayout;

            for (var i = 0; i < MaxCachedResultCount && isEqual; ++i)
            {
                isEqual = isEqual && self.CachedMeasurements[i] == layout.CachedMeasurements[i];
            }

            isEqual = isEqual && (self.ComputedFlexBasis == layout.ComputedFlexBasis);
            isEqual = isEqual && (self.MeasuredDimensions[0] == layout.MeasuredDimensions[0]);
            isEqual = isEqual && (self.MeasuredDimensions[1] == layout.MeasuredDimensions[1]);

            return(isEqual);
        }
        public YogaLayout()
        {
            var cached = new YogaCachedMeasurement[MaxCachedResultCount];

            for (var i = 0; i < cached.Length; i++)
            {
                cached[i] = new YogaCachedMeasurement();
            }

            Position   = new YogaArray <float?>(4);
            Dimensions = YogaArray.From(DefaultDimensionValues);
            Margin     = new YogaArray <float?>(6);
            Border     = new YogaArray <float>(6);
            Padding    = new YogaArray <float>(6);
            Direction  = YogaDirection.Inherit;
            ComputedFlexBasisGeneration = 0;
            ComputedFlexBasis           = null;
            HadOverflow                        = false;
            GenerationCount                    = 0;
            LastOwnerDirection                 = (YogaDirection)(-1);
            NextCachedMeasurementsIndex        = 0;
            CachedMeasurements                 = cached;
            MeasuredDimensions                 = YogaArray.From(DefaultDimensionValues);
            CachedLayout                       = new YogaCachedMeasurement();
            DidUseLegacyFlag                   = false;
            DoesLegacyStretchFlagAffectsLayout = false;
        }
 public YogaStyle()
 {
     Direction      = YogaDirection.Inherit;
     FlexDirection  = YogaFlexDirection.Column;
     JustifyContent = YogaJustify.FlexStart;
     AlignContent   = YogaAlign.FlexStart;
     AlignItems     = YogaAlign.Stretch;
     AlignSelf      = YogaAlign.Auto;
     PositionType   = YogaPositionType.Relative;
     FlexWrap       = YogaWrap.NoWrap;
     Overflow       = YogaOverflow.Visible;
     Display        = YogaDisplay.Flex;
     Flex           = null;
     FlexGrow       = null;
     FlexShrink     = null;
     FlexBasis      = YogaValue.Auto;
     Margin         = YogaArray.From(DefaultEdgeValuesUnit);
     Position       = YogaArray.From(DefaultEdgeValuesUnit);
     Padding        = YogaArray.From(DefaultEdgeValuesUnit);
     Border         = YogaArray.From(DefaultEdgeValuesUnit);
     Dimensions     = YogaArray.From(DefaultDimensionValuesAutoUnit);
     MinDimensions  = YogaArray.From(DefaultDimensionValuesUnit);
     MaxDimensions  = YogaArray.From(DefaultDimensionValuesUnit);
     AspectRatio    = null;
 }
        public static YogaArray <T> From <T>(YogaArray <T> other)
        {
            var result = new T[other.Length];

            for (var i = 0; i < result.Length; i++)
            {
                result[i] = other[i];
            }
            return(new YogaArray <T>(result));
        }
        public static bool Equal(YogaArray <YogaValue> val1, YogaArray <YogaValue> val2)
        {
            var areEqual = true;

            for (var i = 0; i < val1.Length && areEqual; ++i)
            {
                areEqual = val1[i].Equals(val2[i]);
            }

            return(areEqual);
        }
        public static bool Equal(YogaArray <float?> val1, YogaArray <float?> val2)
        {
            var areEqual = true;

            for (var i = 0; i < val1.Length && areEqual; ++i)
            {
                areEqual = FloatsEqual(val1[i], val2[i]);
            }

            return(areEqual);
        }
        public YogaNode(YogaNode node)
        {
            _print              = node._print;
            _hasNewLayout       = node._hasNewLayout;
            _nodeType           = node._nodeType;
            _measure            = node._measure;
            _baseline           = node._baseline;
            _dirtied            = node._dirtied;
            _style              = node._style;
            _layout             = node._layout;
            _lineIndex          = node._lineIndex;
            _owner              = node._owner;
            _children           = new List <YogaNode>(node._children);
            _nextChild          = node._nextChild;
            _config             = node._config;
            _isDirty            = node._isDirty;
            _resolvedDimensions = YogaArray.From(node._resolvedDimensions);

            Interlocked.Increment(ref _instanceCount);
        }
        private YogaArray <YogaValue> _resolvedDimensions; // [2]

        public YogaNode()
        {
            _print              = null;
            _hasNewLayout       = true;
            _nodeType           = YogaNodeType.Default;
            _measure            = null;
            _baseline           = null;
            _dirtied            = null;
            _style              = new YogaStyle();
            _layout             = new YogaLayout();
            _lineIndex          = 0;
            _owner              = null;
            _children           = new List <YogaNode>();
            _nextChild          = null;
            _config             = new YogaConfig();
            _isDirty            = false;
            _resolvedDimensions = new YogaArray <YogaValue>(new YogaValue[] { YogaValue.Undefined, YogaValue.Undefined });

            Interlocked.Increment(ref _instanceCount);
        }
        // Yoga specific properties, not compatible with flexbox specification
        public static bool operator ==(YogaStyle self, YogaStyle style)
        {
            if (object.ReferenceEquals(self, style))
            {
                return(true);
            }

            if (object.ReferenceEquals(self, null) || object.ReferenceEquals(style, null))
            {
                return(false);
            }

            var areNonFloatValuesEqual =
                self.Direction == style.Direction &&
                self.FlexDirection == style.FlexDirection &&
                self.JustifyContent == style.JustifyContent &&
                self.AlignContent == style.AlignContent &&
                self.AlignItems == style.AlignItems &&
                self.AlignSelf == style.AlignSelf &&
                self.PositionType == style.PositionType &&
                self.FlexWrap == style.FlexWrap &&
                self.Overflow == style.Overflow &&
                self.Display == style.Display &&
                self.FlexBasis.Equals(style.FlexBasis) &&
                YogaArray.Equal(self.Margin, style.Margin) &&
                YogaArray.Equal(self.Position, style.Position) &&
                YogaArray.Equal(self.Padding, style.Padding) &&
                YogaArray.Equal(self.Border, style.Border) &&
                YogaArray.Equal(self.Dimensions, style.Dimensions) &&
                YogaArray.Equal(self.MinDimensions, style.MinDimensions) &&
                YogaArray.Equal(self.MaxDimensions, style.MaxDimensions);

            areNonFloatValuesEqual = areNonFloatValuesEqual && self.Flex == style.Flex;

            areNonFloatValuesEqual = areNonFloatValuesEqual && self.FlexGrow == style.FlexGrow;
            areNonFloatValuesEqual = areNonFloatValuesEqual && self.FlexShrink == style.FlexShrink;
            areNonFloatValuesEqual = areNonFloatValuesEqual && self.AspectRatio == style.AspectRatio;

            return(areNonFloatValuesEqual);
        }