public void Test_do_not_clamp_height_of_absolute_node_to_height_of_its_overflow_hidden_parent()
        {
            YogaNode root = new YogaNode();

            root.FlexDirection = YogaFlexDirection.Row;
            root.Overflow      = YogaOverflow.Hidden;
            root.Width         = 50f;
            root.Height        = 50f;

            YogaNode root_child0 = new YogaNode();

            root_child0.PositionType = YogaPositionType.Absolute;
            root_child0.SetPosition(YogaEdge.Start, 0f);
            root_child0.SetPosition(YogaEdge.Top, 0f);
            root.Insert(0, root_child0);

            YogaNode root_child0_child0 = new YogaNode();

            root_child0_child0.Width  = 100f;
            root_child0_child0.Height = 100f;
            root_child0.Insert(0, root_child0_child0);
            root.StyleDirection = YogaDirection.LTR;
            root.CalculateLayout();

            Assert.AreEqual(0f, root.LayoutX);
            Assert.AreEqual(0f, root.LayoutY);
            Assert.AreEqual(50f, root.LayoutWidth);
            Assert.AreEqual(50f, root.LayoutHeight);

            Assert.AreEqual(0f, root_child0.LayoutX);
            Assert.AreEqual(0f, root_child0.LayoutY);
            Assert.AreEqual(100f, root_child0.LayoutWidth);
            Assert.AreEqual(100f, root_child0.LayoutHeight);

            Assert.AreEqual(0f, root_child0_child0.LayoutX);
            Assert.AreEqual(0f, root_child0_child0.LayoutY);
            Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
            Assert.AreEqual(100f, root_child0_child0.LayoutHeight);

            root.StyleDirection = YogaDirection.RTL;
            root.CalculateLayout();

            Assert.AreEqual(0f, root.LayoutX);
            Assert.AreEqual(0f, root.LayoutY);
            Assert.AreEqual(50f, root.LayoutWidth);
            Assert.AreEqual(50f, root.LayoutHeight);

            Assert.AreEqual(-50f, root_child0.LayoutX);
            Assert.AreEqual(0f, root_child0.LayoutY);
            Assert.AreEqual(100f, root_child0.LayoutWidth);
            Assert.AreEqual(100f, root_child0.LayoutHeight);

            Assert.AreEqual(0f, root_child0_child0.LayoutX);
            Assert.AreEqual(0f, root_child0_child0.LayoutY);
            Assert.AreEqual(100f, root_child0_child0.LayoutWidth);
            Assert.AreEqual(100f, root_child0_child0.LayoutHeight);
        }
        public void Test_absolute_layout_width_height_start_top_end_bottom()
        {
            YogaNode root = new YogaNode();

            root.Width  = 100f;
            root.Height = 100f;

            YogaNode root_child0 = new YogaNode();

            root_child0.PositionType = YogaPositionType.Absolute;
            root_child0.SetPosition(YogaEdge.Start, 10f);
            root_child0.SetPosition(YogaEdge.Top, 10f);
            root_child0.SetPosition(YogaEdge.End, 10f);
            root_child0.SetPosition(YogaEdge.Bottom, 10f);
            root_child0.Width  = 10f;
            root_child0.Height = 10f;
            root.Insert(0, root_child0);
            root.StyleDirection = YogaDirection.LTR;
            root.CalculateLayout();

            Assert.AreEqual(0f, root.LayoutX);
            Assert.AreEqual(0f, root.LayoutY);
            Assert.AreEqual(100f, root.LayoutWidth);
            Assert.AreEqual(100f, root.LayoutHeight);

            Assert.AreEqual(10f, root_child0.LayoutX);
            Assert.AreEqual(10f, root_child0.LayoutY);
            Assert.AreEqual(10f, root_child0.LayoutWidth);
            Assert.AreEqual(10f, root_child0.LayoutHeight);

            root.StyleDirection = YogaDirection.RTL;
            root.CalculateLayout();

            Assert.AreEqual(0f, root.LayoutX);
            Assert.AreEqual(0f, root.LayoutY);
            Assert.AreEqual(100f, root.LayoutWidth);
            Assert.AreEqual(100f, root.LayoutHeight);

            Assert.AreEqual(80f, root_child0.LayoutX);
            Assert.AreEqual(10f, root_child0.LayoutY);
            Assert.AreEqual(10f, root_child0.LayoutWidth);
            Assert.AreEqual(10f, root_child0.LayoutHeight);
        }
Exemple #3
0
        public static YogaNode Create(
            YogaDirection?styleDirection    = null,
            YogaFlexDirection?flexDirection = null,
            YogaJustify?justifyContent      = null,
            YogaAlign?alignContent          = null,
            YogaAlign?alignItems            = null,
            YogaAlign?alignSelf             = null,
            YogaPositionType?positionType   = null,
            YogaWrap?wrap         = null,
            YogaOverflow?overflow = null,
            float?flex            = null,
            float?flexGrow        = null,
            float?flexShrink      = null,
            float?flexBasis       = null,
            Spacing position      = null,
            Spacing margin        = null,
            Spacing padding       = null,
            Spacing border        = null,
            float?width           = null,
            float?height          = null,
            float?maxWidth        = null,
            float?maxHeight       = null,
            float?minWidth        = null,
            float?minHeight       = null)
        {
            YogaNode node = new YogaNode();

            if (styleDirection.HasValue)
            {
                node.StyleDirection = styleDirection.Value;
            }

            if (flexDirection.HasValue)
            {
                node.FlexDirection = flexDirection.Value;
            }

            if (justifyContent.HasValue)
            {
                node.JustifyContent = justifyContent.Value;
            }

            if (alignContent.HasValue)
            {
                node.AlignContent = alignContent.Value;
            }

            if (alignItems.HasValue)
            {
                node.AlignItems = alignItems.Value;
            }

            if (alignSelf.HasValue)
            {
                node.AlignSelf = alignSelf.Value;
            }

            if (positionType.HasValue)
            {
                node.PositionType = positionType.Value;
            }

            if (wrap.HasValue)
            {
                node.Wrap = wrap.Value;
            }

            if (overflow.HasValue)
            {
                node.Overflow = overflow.Value;
            }

            if (flex.HasValue)
            {
                node.Flex = flex.Value;
            }

            if (flexGrow.HasValue)
            {
                node.FlexGrow = flexGrow.Value;
            }

            if (flexShrink.HasValue)
            {
                node.FlexShrink = flexShrink.Value;
            }

            if (flexBasis.HasValue)
            {
                node.FlexBasis = flexBasis.Value;
            }

            if (position != null)
            {
                if (position.Top.HasValue)
                {
                    node.SetPosition(YogaEdge.Top, position.Top.Value);
                }

                if (position.Bottom.HasValue)
                {
                    node.SetPosition(YogaEdge.Bottom, position.Bottom.Value);
                }

                if (position.Left.HasValue)
                {
                    node.SetPosition(YogaEdge.Left, position.Left.Value);
                }

                if (position.Right.HasValue)
                {
                    node.SetPosition(YogaEdge.Right, position.Right.Value);
                }
            }

            if (margin != null)
            {
                if (margin.Top.HasValue)
                {
                    node.SetMargin(YogaEdge.Top, margin.Top.Value);
                }

                if (margin.Bottom.HasValue)
                {
                    node.SetMargin(YogaEdge.Bottom, margin.Bottom.Value);
                }

                if (margin.Left.HasValue)
                {
                    node.SetMargin(YogaEdge.Left, margin.Left.Value);
                }

                if (margin.Right.HasValue)
                {
                    node.SetMargin(YogaEdge.Right, margin.Right.Value);
                }
            }

            if (padding != null)
            {
                if (padding.Top.HasValue)
                {
                    node.SetPadding(YogaEdge.Top, padding.Top.Value);
                }

                if (padding.Bottom.HasValue)
                {
                    node.SetPadding(YogaEdge.Bottom, padding.Bottom.Value);
                }

                if (padding.Left.HasValue)
                {
                    node.SetPadding(YogaEdge.Left, padding.Left.Value);
                }

                if (padding.Right.HasValue)
                {
                    node.SetPadding(YogaEdge.Right, padding.Right.Value);
                }
            }

            if (border != null)
            {
                if (border.Top.HasValue)
                {
                    node.SetBorder(YogaEdge.Top, border.Top.Value);
                }

                if (border.Bottom.HasValue)
                {
                    node.SetBorder(YogaEdge.Bottom, border.Bottom.Value);
                }

                if (border.Left.HasValue)
                {
                    node.SetBorder(YogaEdge.Left, border.Left.Value);
                }

                if (border.Right.HasValue)
                {
                    node.SetBorder(YogaEdge.Right, border.Right.Value);
                }
            }

            if (width.HasValue)
            {
                node.Width = width.Value;
            }

            if (height.HasValue)
            {
                node.Height = height.Value;
            }

            if (minWidth.HasValue)
            {
                node.MinWidth = minWidth.Value;
            }

            if (minHeight.HasValue)
            {
                node.MinHeight = minHeight.Value;
            }

            if (maxWidth.HasValue)
            {
                node.MaxWidth = maxWidth.Value;
            }

            if (maxHeight.HasValue)
            {
                node.MaxHeight = maxHeight.Value;
            }

            return(node);
        }
Exemple #4
0
        public void Test_rounding_fractial_input_4()
        {
            YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);

            YogaNode root = new YogaNode();

            root.SetPosition(YogaEdge.Top, 0.7f);
            root.Width  = 100f;
            root.Height = 113.4f;

            YogaNode root_child0 = new YogaNode();

            root_child0.FlexGrow  = 1f;
            root_child0.FlexBasis = 50f;
            root_child0.Height    = 20f;
            root.Insert(0, root_child0);

            YogaNode root_child1 = new YogaNode();

            root_child1.FlexGrow = 1f;
            root_child1.Height   = 10f;
            root.Insert(1, root_child1);

            YogaNode root_child2 = new YogaNode();

            root_child2.FlexGrow = 1f;
            root_child2.Height   = 10f;
            root.Insert(2, root_child2);
            root.StyleDirection = YogaDirection.LTR;
            root.CalculateLayout();

            Assert.AreEqual(0f, root.LayoutX);
            Assert.AreEqual(1f, root.LayoutY);
            Assert.AreEqual(100f, root.LayoutWidth);
            Assert.AreEqual(113f, root.LayoutHeight);

            Assert.AreEqual(0f, root_child0.LayoutX);
            Assert.AreEqual(0f, root_child0.LayoutY);
            Assert.AreEqual(100f, root_child0.LayoutWidth);
            Assert.AreEqual(64f, root_child0.LayoutHeight);

            Assert.AreEqual(0f, root_child1.LayoutX);
            Assert.AreEqual(64f, root_child1.LayoutY);
            Assert.AreEqual(100f, root_child1.LayoutWidth);
            Assert.AreEqual(25f, root_child1.LayoutHeight);

            Assert.AreEqual(0f, root_child2.LayoutX);
            Assert.AreEqual(89f, root_child2.LayoutY);
            Assert.AreEqual(100f, root_child2.LayoutWidth);
            Assert.AreEqual(24f, root_child2.LayoutHeight);

            root.StyleDirection = YogaDirection.RTL;
            root.CalculateLayout();

            Assert.AreEqual(0f, root.LayoutX);
            Assert.AreEqual(1f, root.LayoutY);
            Assert.AreEqual(100f, root.LayoutWidth);
            Assert.AreEqual(113f, root.LayoutHeight);

            Assert.AreEqual(0f, root_child0.LayoutX);
            Assert.AreEqual(0f, root_child0.LayoutY);
            Assert.AreEqual(100f, root_child0.LayoutWidth);
            Assert.AreEqual(64f, root_child0.LayoutHeight);

            Assert.AreEqual(0f, root_child1.LayoutX);
            Assert.AreEqual(64f, root_child1.LayoutY);
            Assert.AreEqual(100f, root_child1.LayoutWidth);
            Assert.AreEqual(25f, root_child1.LayoutHeight);

            Assert.AreEqual(0f, root_child2.LayoutX);
            Assert.AreEqual(89f, root_child2.LayoutY);
            Assert.AreEqual(100f, root_child2.LayoutWidth);
            Assert.AreEqual(24f, root_child2.LayoutHeight);

            YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, false);
        }
Exemple #5
0
        public void Test_rounding_total_fractial_nested()
        {
            YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, true);

            YogaNode root = new YogaNode();

            root.Width  = 87.4f;
            root.Height = 113.4f;

            YogaNode root_child0 = new YogaNode();

            root_child0.FlexGrow  = 0.7f;
            root_child0.FlexBasis = 50.3f;
            root_child0.Height    = 20.3f;
            root.Insert(0, root_child0);

            YogaNode root_child0_child0 = new YogaNode();

            root_child0_child0.FlexGrow  = 1f;
            root_child0_child0.FlexBasis = 0.3f;
            root_child0_child0.SetPosition(YogaEdge.Bottom, 13.3f);
            root_child0_child0.Height = 9.9f;
            root_child0.Insert(0, root_child0_child0);

            YogaNode root_child0_child1 = new YogaNode();

            root_child0_child1.FlexGrow  = 4f;
            root_child0_child1.FlexBasis = 0.3f;
            root_child0_child1.SetPosition(YogaEdge.Top, 13.3f);
            root_child0_child1.Height = 1.1f;
            root_child0.Insert(1, root_child0_child1);

            YogaNode root_child1 = new YogaNode();

            root_child1.FlexGrow = 1.6f;
            root_child1.Height   = 10f;
            root.Insert(1, root_child1);

            YogaNode root_child2 = new YogaNode();

            root_child2.FlexGrow = 1.1f;
            root_child2.Height   = 10.7f;
            root.Insert(2, root_child2);
            root.StyleDirection = YogaDirection.LTR;
            root.CalculateLayout();

            Assert.AreEqual(0f, root.LayoutX);
            Assert.AreEqual(0f, root.LayoutY);
            Assert.AreEqual(87f, root.LayoutWidth);
            Assert.AreEqual(113f, root.LayoutHeight);

            Assert.AreEqual(0f, root_child0.LayoutX);
            Assert.AreEqual(0f, root_child0.LayoutY);
            Assert.AreEqual(87f, root_child0.LayoutWidth);
            Assert.AreEqual(59f, root_child0.LayoutHeight);

            Assert.AreEqual(0f, root_child0_child0.LayoutX);
            Assert.AreEqual(-13f, root_child0_child0.LayoutY);
            Assert.AreEqual(87f, root_child0_child0.LayoutWidth);
            Assert.AreEqual(12f, root_child0_child0.LayoutHeight);

            Assert.AreEqual(0f, root_child0_child1.LayoutX);
            Assert.AreEqual(25f, root_child0_child1.LayoutY);
            Assert.AreEqual(87f, root_child0_child1.LayoutWidth);
            Assert.AreEqual(47f, root_child0_child1.LayoutHeight);

            Assert.AreEqual(0f, root_child1.LayoutX);
            Assert.AreEqual(59f, root_child1.LayoutY);
            Assert.AreEqual(87f, root_child1.LayoutWidth);
            Assert.AreEqual(30f, root_child1.LayoutHeight);

            Assert.AreEqual(0f, root_child2.LayoutX);
            Assert.AreEqual(89f, root_child2.LayoutY);
            Assert.AreEqual(87f, root_child2.LayoutWidth);
            Assert.AreEqual(24f, root_child2.LayoutHeight);

            root.StyleDirection = YogaDirection.RTL;
            root.CalculateLayout();

            Assert.AreEqual(0f, root.LayoutX);
            Assert.AreEqual(0f, root.LayoutY);
            Assert.AreEqual(87f, root.LayoutWidth);
            Assert.AreEqual(113f, root.LayoutHeight);

            Assert.AreEqual(0f, root_child0.LayoutX);
            Assert.AreEqual(0f, root_child0.LayoutY);
            Assert.AreEqual(87f, root_child0.LayoutWidth);
            Assert.AreEqual(59f, root_child0.LayoutHeight);

            Assert.AreEqual(0f, root_child0_child0.LayoutX);
            Assert.AreEqual(-13f, root_child0_child0.LayoutY);
            Assert.AreEqual(87f, root_child0_child0.LayoutWidth);
            Assert.AreEqual(12f, root_child0_child0.LayoutHeight);

            Assert.AreEqual(0f, root_child0_child1.LayoutX);
            Assert.AreEqual(25f, root_child0_child1.LayoutY);
            Assert.AreEqual(87f, root_child0_child1.LayoutWidth);
            Assert.AreEqual(47f, root_child0_child1.LayoutHeight);

            Assert.AreEqual(0f, root_child1.LayoutX);
            Assert.AreEqual(59f, root_child1.LayoutY);
            Assert.AreEqual(87f, root_child1.LayoutWidth);
            Assert.AreEqual(30f, root_child1.LayoutHeight);

            Assert.AreEqual(0f, root_child2.LayoutX);
            Assert.AreEqual(89f, root_child2.LayoutY);
            Assert.AreEqual(87f, root_child2.LayoutWidth);
            Assert.AreEqual(24f, root_child2.LayoutHeight);

            YogaNode.SetExperimentalFeatureEnabled(YogaExperimentalFeature.Rounding, false);
        }
        public void Test_absolute_layout_within_border()
        {
            YogaNode root = new YogaNode();

            root.SetMargin(YogaEdge.Left, 10f);
            root.SetMargin(YogaEdge.Top, 10f);
            root.SetMargin(YogaEdge.Right, 10f);
            root.SetMargin(YogaEdge.Bottom, 10f);
            root.SetPadding(YogaEdge.Left, 10f);
            root.SetPadding(YogaEdge.Top, 10f);
            root.SetPadding(YogaEdge.Right, 10f);
            root.SetPadding(YogaEdge.Bottom, 10f);
            root.SetBorder(YogaEdge.Left, 10f);
            root.SetBorder(YogaEdge.Top, 10f);
            root.SetBorder(YogaEdge.Right, 10f);
            root.SetBorder(YogaEdge.Bottom, 10f);
            root.Width  = 100f;
            root.Height = 100f;

            YogaNode root_child0 = new YogaNode();

            root_child0.PositionType = YogaPositionType.Absolute;
            root_child0.SetPosition(YogaEdge.Left, 0f);
            root_child0.SetPosition(YogaEdge.Top, 0f);
            root_child0.Width  = 50f;
            root_child0.Height = 50f;
            root.Insert(0, root_child0);

            YogaNode root_child1 = new YogaNode();

            root_child1.PositionType = YogaPositionType.Absolute;
            root_child1.SetPosition(YogaEdge.Right, 0f);
            root_child1.SetPosition(YogaEdge.Bottom, 0f);
            root_child1.Width  = 50f;
            root_child1.Height = 50f;
            root.Insert(1, root_child1);
            root.StyleDirection = YogaDirection.LTR;
            root.CalculateLayout();

            Assert.AreEqual(10f, root.LayoutX);
            Assert.AreEqual(10f, root.LayoutY);
            Assert.AreEqual(100f, root.LayoutWidth);
            Assert.AreEqual(100f, root.LayoutHeight);

            Assert.AreEqual(10f, root_child0.LayoutX);
            Assert.AreEqual(10f, root_child0.LayoutY);
            Assert.AreEqual(50f, root_child0.LayoutWidth);
            Assert.AreEqual(50f, root_child0.LayoutHeight);

            Assert.AreEqual(40f, root_child1.LayoutX);
            Assert.AreEqual(40f, root_child1.LayoutY);
            Assert.AreEqual(50f, root_child1.LayoutWidth);
            Assert.AreEqual(50f, root_child1.LayoutHeight);

            root.StyleDirection = YogaDirection.RTL;
            root.CalculateLayout();

            Assert.AreEqual(10f, root.LayoutX);
            Assert.AreEqual(10f, root.LayoutY);
            Assert.AreEqual(100f, root.LayoutWidth);
            Assert.AreEqual(100f, root.LayoutHeight);

            Assert.AreEqual(10f, root_child0.LayoutX);
            Assert.AreEqual(10f, root_child0.LayoutY);
            Assert.AreEqual(50f, root_child0.LayoutWidth);
            Assert.AreEqual(50f, root_child0.LayoutHeight);

            Assert.AreEqual(40f, root_child1.LayoutX);
            Assert.AreEqual(40f, root_child1.LayoutY);
            Assert.AreEqual(50f, root_child1.LayoutWidth);
            Assert.AreEqual(50f, root_child1.LayoutHeight);
        }