예제 #1
0
        public void cloning_two_levels()
        {
            var root = new YogaNode {
                Width = 100, Height = 100
            };

            var root_child0 = new YogaNode {
                FlexGrow = 1, FlexBasis = 15
            };

            root.Children.Add(root_child0);

            var root_child1 = new YogaNode {
                FlexGrow = 1
            };

            root.Children.Insert(1, root_child1);

            var root_child1_0 = new YogaNode {
                FlexBasis = 10, FlexGrow = 1
            };

            root_child1.Children.Add(root_child1_0);

            var root_child1_1 = new YogaNode {
                FlexBasis = 25
            };

            root_child1.Children.Insert(1, root_child1_1);

            root.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.LTR);

            Assert.AreEqual(40, root_child0.Layout.Height);
            Assert.AreEqual(60, root_child1.Layout.Height);
            Assert.AreEqual(35, root_child1_0.Layout.Height);
            Assert.AreEqual(25, root_child1_1.Layout.Height);

            var root2_child0 = new YogaNode(root_child0)
            {
                FlexGrow = 0, FlexBasis = 40
            };

            var root2_child1 = new YogaNode(root_child1);
            var root2        = new YogaNode(root);

            root2.ClearChildren();
            root2.Children.Add(root2_child0);
            root2.Children.Insert(1, root2_child1);
            Assert.AreEqual(2, root2.Children.Count);

            root2.Calc.CalculateLayout(float.NaN, float.NaN, DirectionType.LTR);

            // Original root is unchanged
            Assert.AreEqual(40, root_child0.Layout.Height);
            Assert.AreEqual(60, root_child1.Layout.Height);
            Assert.AreEqual(35, root_child1_0.Layout.Height);
            Assert.AreEqual(25, root_child1_1.Layout.Height);

            // New root has new layout at the top
            Assert.AreEqual(40, root2_child0.Layout.Height);
            Assert.AreEqual(60, root2_child1.Layout.Height);

            // The deeper children are untouched.
            Assert.AreEqual(root2_child1.Children[0], root_child1_0);
            Assert.AreEqual(root2_child1.Children[1], root_child1_1);
        }