public void Test_align_baseline_with_no_baseline_func_and_no_parent_ht()
        {
            var config = new YogaConfig();

            var root = new YogaNode(config);

            root.Style.FlexDirection = YogaFlexDirection.Row;
            root.Style.AlignItems    = YogaAlign.Baseline;
            root.Width = 150;

            var root_child0 = new YogaNode(config);

            root_child0.Width  = 50;
            root_child0.Height = 80;
            root.Insert(0, root_child0);

            var root_child1 = new YogaNode(config);

            root_child1.Width  = 50;
            root_child1.Height = 50;
            root.Insert(1, root_child1);

            root.CalculateLayout(null, null, YogaDirection.LeftToRight);

            Assert.AreEqual(0, root.LayoutX);
            Assert.AreEqual(0, root.LayoutY);
            Assert.AreEqual(150, root.LayoutWidth);
            Assert.AreEqual(80, root.LayoutHeight);

            Assert.AreEqual(0, root_child0.LayoutX);
            Assert.AreEqual(0, root_child0.LayoutY);
            Assert.AreEqual(50, root_child0.LayoutWidth);
            Assert.AreEqual(80, root_child0.LayoutHeight);

            Assert.AreEqual(50, root_child1.LayoutX);
            Assert.AreEqual(30, root_child1.LayoutY);
            Assert.AreEqual(50, root_child1.LayoutWidth);
            Assert.AreEqual(50, root_child1.LayoutHeight);
        }
Esempio n. 2
0
        public void TestChildren()
        {
            YogaNode parent = new YogaNode();

            foreach (YogaNode node in parent)
            {
                Assert.Fail(node.ToString());
            }

            YogaNode child0 = new YogaNode();

            Assert.AreEqual(-1, parent.IndexOf(child0));
            parent.Insert(0, child0);
            foreach (YogaNode node in parent)
            {
                Assert.AreEqual(0, parent.IndexOf(node));
            }

            YogaNode child1 = new YogaNode();

            parent.Insert(1, child1);
            int index = 0;

            foreach (YogaNode node in parent)
            {
                Assert.AreEqual(index++, parent.IndexOf(node));
            }

            parent.RemoveAt(0);
            Assert.AreEqual(-1, parent.IndexOf(child0));
            Assert.AreEqual(0, parent.IndexOf(child1));

            parent.Clear();
            Assert.AreEqual(0, parent.Count);

            parent.Clear();
            Assert.AreEqual(0, parent.Count);
        }
Esempio n. 3
0
        public void Test_padding_side_overrides_all()
        {
            var edges = new[] { YogaEdge.Top,
                                YogaEdge.Bottom,
                                YogaEdge.Start,
                                YogaEdge.End,
                                YogaEdge.Left,
                                YogaEdge.Right };

            for (float edgeValue = 0; edgeValue < 2; ++edgeValue)
            {
                foreach (var edge in edges)
                {
                    var root = new YogaNode();
                    root.Width  = 100;
                    root.Height = 100;
                    root.Style.Padding[YogaEdge.All] = 10;
                    root.Style.Padding[edge]         = edgeValue;
                    root.CalculateLayout(100, 100, YogaDirection.LeftToRight);
                    Assert.AreEqual(edgeValue, root.GetLayoutPadding(edge));
                }
            }
        }
        public void Test_percentage_width_height_undefined_parent_size()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

            YogaNode root_child0 = new YogaNode(config);

            root_child0.Width  = 50.Percent();
            root_child0.Height = 50.Percent();
            root.Insert(0, root_child0);
            root.StyleDirection = YogaDirection.LeftToRight;
            root.CalculateLayout();

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

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

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

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

            Assert.AreEqual(0f, root_child0.LayoutX);
            Assert.AreEqual(0f, root_child0.LayoutY);
            Assert.AreEqual(0f, root_child0.LayoutWidth);
            Assert.AreEqual(0f, root_child0.LayoutHeight);
        }
        public void Test_rounding_flex_basis_flex_grow_row_prime_number_width()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

            root.FlexDirection = YogaFlexDirection.Row;
            root.Width         = 113;
            root.Height        = 100;

            YogaNode root_child0 = new YogaNode(config);

            root_child0.FlexGrow = 1;
            root.Insert(0, root_child0);

            YogaNode root_child1 = new YogaNode(config);

            root_child1.FlexGrow = 1;
            root.Insert(1, root_child1);

            YogaNode root_child2 = new YogaNode(config);

            root_child2.FlexGrow = 1;
            root.Insert(2, root_child2);

            YogaNode root_child3 = new YogaNode(config);

            root_child3.FlexGrow = 1;
            root.Insert(3, root_child3);

            YogaNode root_child4 = new YogaNode(config);

            root_child4.FlexGrow = 1;
            root.Insert(4, root_child4);
            root.StyleDirection = YogaDirection.LeftToRight;
            root.CalculateLayout();

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

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

            Assert.AreEqual(23f, root_child1.LayoutX);
            Assert.AreEqual(0f, root_child1.LayoutY);
            Assert.AreEqual(22f, root_child1.LayoutWidth);
            Assert.AreEqual(100f, root_child1.LayoutHeight);

            Assert.AreEqual(45f, root_child2.LayoutX);
            Assert.AreEqual(0f, root_child2.LayoutY);
            Assert.AreEqual(23f, root_child2.LayoutWidth);
            Assert.AreEqual(100f, root_child2.LayoutHeight);

            Assert.AreEqual(68f, root_child3.LayoutX);
            Assert.AreEqual(0f, root_child3.LayoutY);
            Assert.AreEqual(22f, root_child3.LayoutWidth);
            Assert.AreEqual(100f, root_child3.LayoutHeight);

            Assert.AreEqual(90f, root_child4.LayoutX);
            Assert.AreEqual(0f, root_child4.LayoutY);
            Assert.AreEqual(23f, root_child4.LayoutWidth);
            Assert.AreEqual(100f, root_child4.LayoutHeight);

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

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

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

            Assert.AreEqual(68f, root_child1.LayoutX);
            Assert.AreEqual(0f, root_child1.LayoutY);
            Assert.AreEqual(22f, root_child1.LayoutWidth);
            Assert.AreEqual(100f, root_child1.LayoutHeight);

            Assert.AreEqual(45f, root_child2.LayoutX);
            Assert.AreEqual(0f, root_child2.LayoutY);
            Assert.AreEqual(23f, root_child2.LayoutWidth);
            Assert.AreEqual(100f, root_child2.LayoutHeight);

            Assert.AreEqual(23f, root_child3.LayoutX);
            Assert.AreEqual(0f, root_child3.LayoutY);
            Assert.AreEqual(22f, root_child3.LayoutWidth);
            Assert.AreEqual(100f, root_child3.LayoutHeight);

            Assert.AreEqual(0f, root_child4.LayoutX);
            Assert.AreEqual(0f, root_child4.LayoutY);
            Assert.AreEqual(23f, root_child4.LayoutWidth);
            Assert.AreEqual(100f, root_child4.LayoutHeight);
        }
        public void Test_percentage_multiple_nested_with_padding_margin_and_percentage_values()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

            root.Width  = 200;
            root.Height = 200;

            YogaNode root_child0 = new YogaNode(config);

            root_child0.FlexGrow      = 1;
            root_child0.FlexBasis     = 10.Percent();
            root_child0.MarginLeft    = 5;
            root_child0.MarginTop     = 5;
            root_child0.MarginRight   = 5;
            root_child0.MarginBottom  = 5;
            root_child0.PaddingLeft   = 3;
            root_child0.PaddingTop    = 3;
            root_child0.PaddingRight  = 3;
            root_child0.PaddingBottom = 3;
            root_child0.MinWidth      = 60.Percent();
            root.Insert(0, root_child0);

            YogaNode root_child0_child0 = new YogaNode(config);

            root_child0_child0.MarginLeft    = 5;
            root_child0_child0.MarginTop     = 5;
            root_child0_child0.MarginRight   = 5;
            root_child0_child0.MarginBottom  = 5;
            root_child0_child0.PaddingLeft   = 3.Percent();
            root_child0_child0.PaddingTop    = 3.Percent();
            root_child0_child0.PaddingRight  = 3.Percent();
            root_child0_child0.PaddingBottom = 3.Percent();
            root_child0_child0.Width         = 50.Percent();
            root_child0.Insert(0, root_child0_child0);

            YogaNode root_child0_child0_child0 = new YogaNode(config);

            root_child0_child0_child0.MarginLeft    = 5.Percent();
            root_child0_child0_child0.MarginTop     = 5.Percent();
            root_child0_child0_child0.MarginRight   = 5.Percent();
            root_child0_child0_child0.MarginBottom  = 5.Percent();
            root_child0_child0_child0.PaddingLeft   = 3;
            root_child0_child0_child0.PaddingTop    = 3;
            root_child0_child0_child0.PaddingRight  = 3;
            root_child0_child0_child0.PaddingBottom = 3;
            root_child0_child0_child0.Width         = 45.Percent();
            root_child0_child0.Insert(0, root_child0_child0_child0);

            YogaNode root_child1 = new YogaNode(config);

            root_child1.FlexGrow  = 4;
            root_child1.FlexBasis = 15.Percent();
            root_child1.MinWidth  = 20.Percent();
            root.Insert(1, root_child1);
            root.StyleDirection = YogaDirection.LeftToRight;
            root.CalculateLayout();

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

            Assert.AreEqual(5f, root_child0.LayoutX);
            Assert.AreEqual(5f, root_child0.LayoutY);
            Assert.AreEqual(190f, root_child0.LayoutWidth);
            Assert.AreEqual(48f, root_child0.LayoutHeight);

            Assert.AreEqual(8f, root_child0_child0.LayoutX);
            Assert.AreEqual(8f, root_child0_child0.LayoutY);
            Assert.AreEqual(92f, root_child0_child0.LayoutWidth);
            Assert.AreEqual(25f, root_child0_child0.LayoutHeight);

            Assert.AreEqual(10f, root_child0_child0_child0.LayoutX);
            Assert.AreEqual(10f, root_child0_child0_child0.LayoutY);
            Assert.AreEqual(36f, root_child0_child0_child0.LayoutWidth);
            Assert.AreEqual(6f, root_child0_child0_child0.LayoutHeight);

            Assert.AreEqual(0f, root_child1.LayoutX);
            Assert.AreEqual(58f, root_child1.LayoutY);
            Assert.AreEqual(200f, root_child1.LayoutWidth);
            Assert.AreEqual(142f, root_child1.LayoutHeight);

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

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

            Assert.AreEqual(5f, root_child0.LayoutX);
            Assert.AreEqual(5f, root_child0.LayoutY);
            Assert.AreEqual(190f, root_child0.LayoutWidth);
            Assert.AreEqual(48f, root_child0.LayoutHeight);

            Assert.AreEqual(90f, root_child0_child0.LayoutX);
            Assert.AreEqual(8f, root_child0_child0.LayoutY);
            Assert.AreEqual(92f, root_child0_child0.LayoutWidth);
            Assert.AreEqual(25f, root_child0_child0.LayoutHeight);

            Assert.AreEqual(46f, root_child0_child0_child0.LayoutX);
            Assert.AreEqual(10f, root_child0_child0_child0.LayoutY);
            Assert.AreEqual(36f, root_child0_child0_child0.LayoutWidth);
            Assert.AreEqual(6f, root_child0_child0_child0.LayoutHeight);

            Assert.AreEqual(0f, root_child1.LayoutX);
            Assert.AreEqual(58f, root_child1.LayoutY);
            Assert.AreEqual(200f, root_child1.LayoutWidth);
            Assert.AreEqual(142f, root_child1.LayoutHeight);
        }
        private static float _baselineFunc(YogaNode node, float?width, float?height)
        {
            var result = height / 2;

            return(result ?? 0);
        }
        public void Test_rounding_inner_node_controversy_vertical()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

            root.Height = 320;

            YogaNode root_child0 = new YogaNode(config);

            root_child0.FlexGrow = 1;
            root_child0.Width    = 10;
            root.Insert(0, root_child0);

            YogaNode root_child1 = new YogaNode(config);

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

            YogaNode root_child1_child0 = new YogaNode(config);

            root_child1_child0.FlexGrow = 1;
            root_child1_child0.Width    = 10;
            root_child1.Insert(0, root_child1_child0);

            YogaNode root_child2 = new YogaNode(config);

            root_child2.FlexGrow = 1;
            root_child2.Width    = 10;
            root.Insert(2, root_child2);
            root.StyleDirection = YogaDirection.LeftToRight;
            root.CalculateLayout();

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

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

            Assert.AreEqual(0f, root_child1.LayoutX);
            Assert.AreEqual(107f, root_child1.LayoutY);
            Assert.AreEqual(10f, root_child1.LayoutWidth);
            Assert.AreEqual(106f, root_child1.LayoutHeight);

            Assert.AreEqual(0f, root_child1_child0.LayoutX);
            Assert.AreEqual(0f, root_child1_child0.LayoutY);
            Assert.AreEqual(10f, root_child1_child0.LayoutWidth);
            Assert.AreEqual(106f, root_child1_child0.LayoutHeight);

            Assert.AreEqual(0f, root_child2.LayoutX);
            Assert.AreEqual(213f, root_child2.LayoutY);
            Assert.AreEqual(10f, root_child2.LayoutWidth);
            Assert.AreEqual(107f, root_child2.LayoutHeight);

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

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

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

            Assert.AreEqual(0f, root_child1.LayoutX);
            Assert.AreEqual(107f, root_child1.LayoutY);
            Assert.AreEqual(10f, root_child1.LayoutWidth);
            Assert.AreEqual(106f, root_child1.LayoutHeight);

            Assert.AreEqual(0f, root_child1_child0.LayoutX);
            Assert.AreEqual(0f, root_child1_child0.LayoutY);
            Assert.AreEqual(10f, root_child1_child0.LayoutWidth);
            Assert.AreEqual(106f, root_child1_child0.LayoutHeight);

            Assert.AreEqual(0f, root_child2.LayoutX);
            Assert.AreEqual(213f, root_child2.LayoutY);
            Assert.AreEqual(10f, root_child2.LayoutWidth);
            Assert.AreEqual(107f, root_child2.LayoutHeight);
        }
        public void Test_rounding_fractial_input_4()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

            root.Top    = 0.7f;
            root.Width  = 100;
            root.Height = 113.4f;

            YogaNode root_child0 = new YogaNode(config);

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

            YogaNode root_child1 = new YogaNode(config);

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

            YogaNode root_child2 = new YogaNode(config);

            root_child2.FlexGrow = 1;
            root_child2.Height   = 10;
            root.Insert(2, root_child2);
            root.StyleDirection = YogaDirection.LeftToRight;
            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.RightToLeft;
            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);
        }
Esempio n. 10
0
        public void TestRemoveAtFromEmpty()
        {
            YogaNode parent = new YogaNode();

            Assert.Throws <ArgumentOutOfRangeException>(() => parent.RemoveAt(0));
        }
Esempio n. 11
0
        public void Test_flex_grow_less_than_factor_one()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

            root.Width  = 200;
            root.Height = 500;

            YogaNode root_child0 = new YogaNode(config);

            root_child0.FlexGrow  = 0.2f;
            root_child0.FlexBasis = 40;
            root.Insert(0, root_child0);

            YogaNode root_child1 = new YogaNode(config);

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

            YogaNode root_child2 = new YogaNode(config);

            root_child2.FlexGrow = 0.4f;
            root.Insert(2, root_child2);
            root.StyleDirection = YogaDirection.LeftToRight;
            root.CalculateLayout();

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

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

            Assert.AreEqual(0f, root_child1.LayoutX);
            Assert.AreEqual(132f, root_child1.LayoutY);
            Assert.AreEqual(200f, root_child1.LayoutWidth);
            Assert.AreEqual(92f, root_child1.LayoutHeight);

            Assert.AreEqual(0f, root_child2.LayoutX);
            Assert.AreEqual(224f, root_child2.LayoutY);
            Assert.AreEqual(200f, root_child2.LayoutWidth);
            Assert.AreEqual(184f, root_child2.LayoutHeight);

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

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

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

            Assert.AreEqual(0f, root_child1.LayoutX);
            Assert.AreEqual(132f, root_child1.LayoutY);
            Assert.AreEqual(200f, root_child1.LayoutWidth);
            Assert.AreEqual(92f, root_child1.LayoutHeight);

            Assert.AreEqual(0f, root_child2.LayoutX);
            Assert.AreEqual(224f, root_child2.LayoutY);
            Assert.AreEqual(200f, root_child2.LayoutWidth);
            Assert.AreEqual(184f, root_child2.LayoutHeight);
        }
Esempio n. 12
0
        public void Test_flex_basis_overrides_main_size()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

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

            YogaNode root_child0 = new YogaNode(config);

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

            YogaNode root_child1 = new YogaNode(config);

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

            YogaNode root_child2 = new YogaNode(config);

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

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

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

            Assert.AreEqual(0f, root_child1.LayoutX);
            Assert.AreEqual(60f, root_child1.LayoutY);
            Assert.AreEqual(100f, root_child1.LayoutWidth);
            Assert.AreEqual(20f, root_child1.LayoutHeight);

            Assert.AreEqual(0f, root_child2.LayoutX);
            Assert.AreEqual(80f, root_child2.LayoutY);
            Assert.AreEqual(100f, root_child2.LayoutWidth);
            Assert.AreEqual(20f, root_child2.LayoutHeight);

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

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

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

            Assert.AreEqual(0f, root_child1.LayoutX);
            Assert.AreEqual(60f, root_child1.LayoutY);
            Assert.AreEqual(100f, root_child1.LayoutWidth);
            Assert.AreEqual(20f, root_child1.LayoutHeight);

            Assert.AreEqual(0f, root_child2.LayoutX);
            Assert.AreEqual(80f, root_child2.LayoutY);
            Assert.AreEqual(100f, root_child2.LayoutWidth);
            Assert.AreEqual(20f, root_child2.LayoutHeight);
        }
Esempio n. 13
0
        public void Test_flex_shrink_to_zero()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

            root.Height = 75;

            YogaNode root_child0 = new YogaNode(config);

            root_child0.Width  = 50;
            root_child0.Height = 50;
            root.Insert(0, root_child0);

            YogaNode root_child1 = new YogaNode(config);

            root_child1.FlexShrink = 1;
            root_child1.Width      = 50;
            root_child1.Height     = 50;
            root.Insert(1, root_child1);

            YogaNode root_child2 = new YogaNode(config);

            root_child2.Width  = 50;
            root_child2.Height = 50;
            root.Insert(2, root_child2);
            root.StyleDirection = YogaDirection.LeftToRight;
            root.CalculateLayout();

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

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

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

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

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

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

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

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

            Assert.AreEqual(0f, root_child2.LayoutX);
            Assert.AreEqual(50f, root_child2.LayoutY);
            Assert.AreEqual(50f, root_child2.LayoutWidth);
            Assert.AreEqual(50f, root_child2.LayoutHeight);
        }
Esempio n. 14
0
        public void Test_absolute_layout_percentage_bottom_based_on_parent_height()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

            root.Width  = 100;
            root.Height = 200;

            YogaNode root_child0 = new YogaNode(config);

            root_child0.PositionType = YogaPositionType.Absolute;
            root_child0.Top          = 50.Percent();
            root_child0.Width        = 10;
            root_child0.Height       = 10;
            root.Insert(0, root_child0);

            YogaNode root_child1 = new YogaNode(config);

            root_child1.PositionType = YogaPositionType.Absolute;
            root_child1.Bottom       = 50.Percent();
            root_child1.Width        = 10;
            root_child1.Height       = 10;
            root.Insert(1, root_child1);

            YogaNode root_child2 = new YogaNode(config);

            root_child2.PositionType = YogaPositionType.Absolute;
            root_child2.Top          = 10.Percent();
            root_child2.Bottom       = 10.Percent();
            root_child2.Width        = 10;
            root.Insert(2, root_child2);
            root.StyleDirection = YogaDirection.LeftToRight;
            root.CalculateLayout();

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

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

            Assert.AreEqual(0f, root_child1.LayoutX);
            Assert.AreEqual(90f, root_child1.LayoutY);
            Assert.AreEqual(10f, root_child1.LayoutWidth);
            Assert.AreEqual(10f, root_child1.LayoutHeight);

            Assert.AreEqual(0f, root_child2.LayoutX);
            Assert.AreEqual(20f, root_child2.LayoutY);
            Assert.AreEqual(10f, root_child2.LayoutWidth);
            Assert.AreEqual(160f, root_child2.LayoutHeight);

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

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

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

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

            Assert.AreEqual(90f, root_child2.LayoutX);
            Assert.AreEqual(20f, root_child2.LayoutY);
            Assert.AreEqual(10f, root_child2.LayoutWidth);
            Assert.AreEqual(160f, root_child2.LayoutHeight);
        }
Esempio n. 15
0
        public void Test_absolute_layout_within_border()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

            root.MarginLeft        = 10;
            root.MarginTop         = 10;
            root.MarginRight       = 10;
            root.MarginBottom      = 10;
            root.PaddingLeft       = 10;
            root.PaddingTop        = 10;
            root.PaddingRight      = 10;
            root.PaddingBottom     = 10;
            root.BorderLeftWidth   = 10;
            root.BorderTopWidth    = 10;
            root.BorderRightWidth  = 10;
            root.BorderBottomWidth = 10;
            root.Width             = 100;
            root.Height            = 100;

            YogaNode root_child0 = new YogaNode(config);

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

            YogaNode root_child1 = new YogaNode(config);

            root_child1.PositionType = YogaPositionType.Absolute;
            root_child1.Right        = 0;
            root_child1.Bottom       = 0;
            root_child1.Width        = 50;
            root_child1.Height       = 50;
            root.Insert(1, root_child1);

            YogaNode root_child2 = new YogaNode(config);

            root_child2.PositionType = YogaPositionType.Absolute;
            root_child2.Left         = 0;
            root_child2.Top          = 0;
            root_child2.MarginLeft   = 10;
            root_child2.MarginTop    = 10;
            root_child2.MarginRight  = 10;
            root_child2.MarginBottom = 10;
            root_child2.Width        = 50;
            root_child2.Height       = 50;
            root.Insert(2, root_child2);

            YogaNode root_child3 = new YogaNode(config);

            root_child3.PositionType = YogaPositionType.Absolute;
            root_child3.Right        = 0;
            root_child3.Bottom       = 0;
            root_child3.MarginLeft   = 10;
            root_child3.MarginTop    = 10;
            root_child3.MarginRight  = 10;
            root_child3.MarginBottom = 10;
            root_child3.Width        = 50;
            root_child3.Height       = 50;
            root.Insert(3, root_child3);
            root.StyleDirection = YogaDirection.LeftToRight;
            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);

            Assert.AreEqual(20f, root_child2.LayoutX);
            Assert.AreEqual(20f, root_child2.LayoutY);
            Assert.AreEqual(50f, root_child2.LayoutWidth);
            Assert.AreEqual(50f, root_child2.LayoutHeight);

            Assert.AreEqual(30f, root_child3.LayoutX);
            Assert.AreEqual(30f, root_child3.LayoutY);
            Assert.AreEqual(50f, root_child3.LayoutWidth);
            Assert.AreEqual(50f, root_child3.LayoutHeight);

            root.StyleDirection = YogaDirection.RightToLeft;
            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);

            Assert.AreEqual(20f, root_child2.LayoutX);
            Assert.AreEqual(20f, root_child2.LayoutY);
            Assert.AreEqual(50f, root_child2.LayoutWidth);
            Assert.AreEqual(50f, root_child2.LayoutHeight);

            Assert.AreEqual(30f, root_child3.LayoutX);
            Assert.AreEqual(30f, root_child3.LayoutY);
            Assert.AreEqual(50f, root_child3.LayoutWidth);
            Assert.AreEqual(50f, root_child3.LayoutHeight);
        }
Esempio n. 16
0
        public void Test_rounding_flex_basis_flex_shrink_row()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

            root.FlexDirection = YogaFlexDirection.Row;
            root.Width         = 101;
            root.Height        = 100;

            YogaNode root_child0 = new YogaNode(config);

            root_child0.FlexShrink = 1;
            root_child0.FlexBasis  = 100;
            root.Insert(0, root_child0);

            YogaNode root_child1 = new YogaNode(config);

            root_child1.FlexBasis = 25;
            root.Insert(1, root_child1);

            YogaNode root_child2 = new YogaNode(config);

            root_child2.FlexBasis = 25;
            root.Insert(2, root_child2);
            root.StyleDirection = YogaDirection.LeftToRight;
            root.CalculateLayout();

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

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

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

            Assert.AreEqual(76f, root_child2.LayoutX);
            Assert.AreEqual(0f, root_child2.LayoutY);
            Assert.AreEqual(25f, root_child2.LayoutWidth);
            Assert.AreEqual(100f, root_child2.LayoutHeight);

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

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

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

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

            Assert.AreEqual(0f, root_child2.LayoutX);
            Assert.AreEqual(0f, root_child2.LayoutY);
            Assert.AreEqual(25f, root_child2.LayoutWidth);
            Assert.AreEqual(100f, root_child2.LayoutHeight);
        }
Esempio n. 17
0
        public void Test_rounding_total_fractial_nested()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

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

            YogaNode root_child0 = new YogaNode(config);

            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(config);

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

            YogaNode root_child0_child1 = new YogaNode(config);

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

            YogaNode root_child1 = new YogaNode(config);

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

            YogaNode root_child2 = new YogaNode(config);

            root_child2.FlexGrow = 1.1f;
            root_child2.Height   = 10.7f;
            root.Insert(2, root_child2);
            root.StyleDirection = YogaDirection.LeftToRight;
            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.RightToLeft;
            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);
        }
        public void Test_percent_within_flex_grow()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

            root.FlexDirection = YogaFlexDirection.Row;
            root.Width         = 350;
            root.Height        = 100;

            YogaNode root_child0 = new YogaNode(config);

            root_child0.Width = 100;
            root.Insert(0, root_child0);

            YogaNode root_child1 = new YogaNode(config);

            root_child1.FlexGrow = 1;
            root.Insert(1, root_child1);

            YogaNode root_child1_child0 = new YogaNode(config);

            root_child1_child0.Width = 100.Percent();
            root_child1.Insert(0, root_child1_child0);

            YogaNode root_child2 = new YogaNode(config);

            root_child2.Width = 100;
            root.Insert(2, root_child2);
            root.StyleDirection = YogaDirection.LeftToRight;
            root.CalculateLayout();

            Assert.AreEqual(0f, root.LayoutX);
            Assert.AreEqual(0f, root.LayoutY);
            Assert.AreEqual(350f, root.LayoutWidth);
            Assert.AreEqual(100f, 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(100f, root_child1.LayoutX);
            Assert.AreEqual(0f, root_child1.LayoutY);
            Assert.AreEqual(150f, root_child1.LayoutWidth);
            Assert.AreEqual(100f, root_child1.LayoutHeight);

            Assert.AreEqual(0f, root_child1_child0.LayoutX);
            Assert.AreEqual(0f, root_child1_child0.LayoutY);
            Assert.AreEqual(150f, root_child1_child0.LayoutWidth);
            Assert.AreEqual(0f, root_child1_child0.LayoutHeight);

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

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

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

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

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

            Assert.AreEqual(0f, root_child1_child0.LayoutX);
            Assert.AreEqual(0f, root_child1_child0.LayoutY);
            Assert.AreEqual(150f, root_child1_child0.LayoutWidth);
            Assert.AreEqual(0f, root_child1_child0.LayoutHeight);

            Assert.AreEqual(0f, root_child2.LayoutX);
            Assert.AreEqual(0f, root_child2.LayoutY);
            Assert.AreEqual(100f, root_child2.LayoutWidth);
            Assert.AreEqual(100f, root_child2.LayoutHeight);
        }
Esempio n. 19
0
        public void Test_rounding_flex_basis_flex_grow_row_width_of_100()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

            root.FlexDirection = YogaFlexDirection.Row;
            root.Width         = 100;
            root.Height        = 100;

            YogaNode root_child0 = new YogaNode(config);

            root_child0.FlexGrow = 1;
            root.Insert(0, root_child0);

            YogaNode root_child1 = new YogaNode(config);

            root_child1.FlexGrow = 1;
            root.Insert(1, root_child1);

            YogaNode root_child2 = new YogaNode(config);

            root_child2.FlexGrow = 1;
            root.Insert(2, root_child2);
            root.StyleDirection = YogaDirection.LeftToRight;
            root.CalculateLayout();

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

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

            Assert.AreEqual(33f, root_child1.LayoutX);
            Assert.AreEqual(0f, root_child1.LayoutY);
            Assert.AreEqual(34f, root_child1.LayoutWidth);
            Assert.AreEqual(100f, root_child1.LayoutHeight);

            Assert.AreEqual(67f, root_child2.LayoutX);
            Assert.AreEqual(0f, root_child2.LayoutY);
            Assert.AreEqual(33f, root_child2.LayoutWidth);
            Assert.AreEqual(100f, root_child2.LayoutHeight);

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

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

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

            Assert.AreEqual(33f, root_child1.LayoutX);
            Assert.AreEqual(0f, root_child1.LayoutY);
            Assert.AreEqual(34f, root_child1.LayoutWidth);
            Assert.AreEqual(100f, root_child1.LayoutHeight);

            Assert.AreEqual(0f, root_child2.LayoutX);
            Assert.AreEqual(0f, root_child2.LayoutY);
            Assert.AreEqual(33f, root_child2.LayoutWidth);
            Assert.AreEqual(100f, root_child2.LayoutHeight);
        }
        public void Test_percentage_container_in_wrapping_container()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

            root.JustifyContent = YogaJustify.Center;
            root.AlignItems     = YogaAlign.Center;
            root.Width          = 200;
            root.Height         = 200;

            YogaNode root_child0 = new YogaNode(config);

            root.Insert(0, root_child0);

            YogaNode root_child0_child0 = new YogaNode(config);

            root_child0_child0.FlexDirection  = YogaFlexDirection.Row;
            root_child0_child0.JustifyContent = YogaJustify.Center;
            root_child0_child0.Width          = 100.Percent();
            root_child0.Insert(0, root_child0_child0);

            YogaNode root_child0_child0_child0 = new YogaNode(config);

            root_child0_child0_child0.Width  = 50;
            root_child0_child0_child0.Height = 50;
            root_child0_child0.Insert(0, root_child0_child0_child0);

            YogaNode root_child0_child0_child1 = new YogaNode(config);

            root_child0_child0_child1.Width  = 50;
            root_child0_child0_child1.Height = 50;
            root_child0_child0.Insert(1, root_child0_child0_child1);
            root.StyleDirection = YogaDirection.LeftToRight;
            root.CalculateLayout();

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

            Assert.AreEqual(50f, root_child0.LayoutX);
            Assert.AreEqual(75f, root_child0.LayoutY);
            Assert.AreEqual(100f, root_child0.LayoutWidth);
            Assert.AreEqual(50f, 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(50f, root_child0_child0.LayoutHeight);

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

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

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

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

            Assert.AreEqual(50f, root_child0.LayoutX);
            Assert.AreEqual(75f, root_child0.LayoutY);
            Assert.AreEqual(100f, root_child0.LayoutWidth);
            Assert.AreEqual(50f, 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(50f, root_child0_child0.LayoutHeight);

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

            Assert.AreEqual(0f, root_child0_child0_child1.LayoutX);
            Assert.AreEqual(0f, root_child0_child0_child1.LayoutY);
            Assert.AreEqual(50f, root_child0_child0_child1.LayoutWidth);
            Assert.AreEqual(50f, root_child0_child0_child1.LayoutHeight);
        }
Esempio n. 21
0
        public void Test_align_self_baseline()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

            root.FlexDirection = YogaFlexDirection.Row;
            root.Width         = 100;
            root.Height        = 100;

            YogaNode root_child0 = new YogaNode(config);

            root_child0.AlignSelf = YogaAlign.Baseline;
            root_child0.Width     = 50;
            root_child0.Height    = 50;
            root.Insert(0, root_child0);

            YogaNode root_child1 = new YogaNode(config);

            root_child1.AlignSelf = YogaAlign.Baseline;
            root_child1.Width     = 50;
            root_child1.Height    = 20;
            root.Insert(1, root_child1);

            YogaNode root_child1_child0 = new YogaNode(config);

            root_child1_child0.Width  = 50;
            root_child1_child0.Height = 10;
            root_child1.Insert(0, root_child1_child0);
            root.StyleDirection = YogaDirection.LeftToRight;
            root.CalculateLayout();

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

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

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

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

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

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

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

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

            Assert.AreEqual(0f, root_child1_child0.LayoutX);
            Assert.AreEqual(0f, root_child1_child0.LayoutY);
            Assert.AreEqual(50f, root_child1_child0.LayoutWidth);
            Assert.AreEqual(10f, root_child1_child0.LayoutHeight);
        }
        public void Test_percent_absolute_position()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = new YogaNode(config);

            root.Width  = 60;
            root.Height = 50;

            YogaNode root_child0 = new YogaNode(config);

            root_child0.FlexDirection = YogaFlexDirection.Row;
            root_child0.PositionType  = YogaPositionType.Absolute;
            root_child0.Left          = 50.Percent();
            root_child0.Width         = 100.Percent();
            root_child0.Height        = 50;
            root.Insert(0, root_child0);

            YogaNode root_child0_child0 = new YogaNode(config);

            root_child0_child0.Width = 100.Percent();
            root_child0.Insert(0, root_child0_child0);

            YogaNode root_child0_child1 = new YogaNode(config);

            root_child0_child1.Width = 100.Percent();
            root_child0.Insert(1, root_child0_child1);
            root.StyleDirection = YogaDirection.LeftToRight;
            root.CalculateLayout();

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

            Assert.AreEqual(30f, root_child0.LayoutX);
            Assert.AreEqual(0f, root_child0.LayoutY);
            Assert.AreEqual(60f, root_child0.LayoutWidth);
            Assert.AreEqual(50f, root_child0.LayoutHeight);

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

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

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

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

            Assert.AreEqual(30f, root_child0.LayoutX);
            Assert.AreEqual(0f, root_child0.LayoutY);
            Assert.AreEqual(60f, root_child0.LayoutWidth);
            Assert.AreEqual(50f, root_child0.LayoutHeight);

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

            Assert.AreEqual(-60f, root_child0_child1.LayoutX);
            Assert.AreEqual(0f, root_child0_child1.LayoutY);
            Assert.AreEqual(60f, root_child0_child1.LayoutWidth);
            Assert.AreEqual(50f, root_child0_child1.LayoutHeight);
        }