Пример #1
0
        public void TestBaselineFunc()
        {
            YogaNode node = new YogaNode();

            node.Height        = 200;
            node.FlexDirection = YogaFlexDirection.Row;
            node.AlignItems    = YogaAlign.Baseline;

            YogaNode child0 = new YogaNode();

            child0.Width  = 100;
            child0.Height = 110;
            child0.SetBaselineFunction((_, width, height) => {
                Assert.AreEqual(100, width);
                Assert.AreEqual(110, height);
                return(65);
            });
            node.Insert(0, child0);

            YogaNode child1 = new YogaNode();

            child1.Width  = 100;
            child1.Height = 110;
            child1.SetBaselineFunction((_, width, height) => {
                Assert.AreEqual(100, width);
                Assert.AreEqual(110, height);
                return(80);
            });
            node.Insert(1, child1);

            YogaNode child2 = new YogaNode();

            child2.Width  = 100;
            child2.Height = 110;
            child2.SetBaselineFunction((_, width, height) => {
                Assert.AreEqual(100, width);
                Assert.AreEqual(110, height);
                return(88);
            });
            node.Insert(2, child2);

            node.CalculateLayout();

            Assert.AreEqual(0, child0.LayoutX);
            Assert.AreEqual(23, child0.LayoutY);
            Assert.AreEqual(100, child1.LayoutX);
            Assert.AreEqual(8, child1.LayoutY);
            Assert.AreEqual(200, child2.LayoutX);
            Assert.AreEqual(0, child2.LayoutY);
        }
Пример #2
0
        public void Test_align_baseline_parent_using_child_in_row_as_reference()
        {
            YogaConfig config = new YogaConfig();

            YogaNode root = createYGNode(config, YogaFlexDirection.Row, 1000, 1000, true);

            YogaNode root_child0 = createYGNode(config, YogaFlexDirection.Column, 500, 600, false);

            root.Insert(0, root_child0);

            YogaNode root_child1 = createYGNode(config, YogaFlexDirection.Row, 500, 800, true);

            root.Insert(1, root_child1);

            YogaNode root_child1_child0 = createYGNode(config, YogaFlexDirection.Row, 500, 500, false);

            root_child1.Insert(0, root_child1_child0);

            YogaNode root_child1_child1 = createYGNode(config, YogaFlexDirection.Row, 500, 400, false);

            root_child1_child1.SetBaselineFunction((_, width, height) => {
                return(height / 2);
            });
            root_child1_child1.IsReferenceBaseline = true;
            root_child1.Insert(1, root_child1_child1);

            root.StyleDirection = YogaDirection.LTR;

            root.CalculateLayout();

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

            Assert.AreEqual(500f, root_child1.LayoutX);
            Assert.AreEqual(100f, root_child1.LayoutY);

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

            Assert.AreEqual(500f, root_child1_child1.LayoutX);
            Assert.AreEqual(300f, root_child1_child1.LayoutY);
        }