Пример #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_with_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 = 50;
            root.Insert(0, root_child0);

            var root_child1 = new YogaNode(config);

            root_child1.Width  = 50;
            root_child1.Height = 40;
            root_child1.SetBaselineFunction(_baselineFunc);
            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(70, root.LayoutHeight);

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

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