Ejemplo n.º 1
0
        public void TestMeasuring()
        {
            var label = new Label {
                IsPlatformEnabled = true,
            };
            var Layout = new FlexLayout {
                IsPlatformEnabled = true,
                Direction         = FlexDirection.Row,
                Wrap     = FlexWrap.Wrap,
                Children =
                {
                    label,
                }
            };

            //measure sith +inf as main-axis
            var measure = Layout.Measure(double.PositiveInfinity, 40);

            Assert.That(measure.Request, Is.EqualTo(new Size(100, 40)));

            //measure sith +inf as cross-axis
            measure = Layout.Measure(200, double.PositiveInfinity);
            Assert.That(measure.Request, Is.EqualTo(new Size(200, 20)));

            //measure with +inf as both axis
            measure = Layout.Measure(double.PositiveInfinity, double.PositiveInfinity);
            Assert.That(measure.Request, Is.EqualTo(new Size(100, 20)));
        }
Ejemplo n.º 2
0
        public void TestFlexDirectionRowNoWidth()
        {
            var platform = new UnitPlatform();
            var view0    = new View {
                Platform = platform, IsPlatformEnabled = true, WidthRequest = 10,
            };
            var view1 = new View {
                Platform = platform, IsPlatformEnabled = true, WidthRequest = 10,
            };
            var view2 = new View {
                Platform = platform, IsPlatformEnabled = true, WidthRequest = 10,
            };
            var layout = new FlexLayout {
                Platform          = platform,
                IsPlatformEnabled = true,
                Children          =
                {
                    view0,
                    view1,
                    view2,
                },

                Direction = FlexDirection.Row,
            };


            var measure = layout.Measure(double.PositiveInfinity, 100);

            layout.Layout(new Rectangle(0, 0, measure.Request.Width, measure.Request.Height));
            Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 30, 100)));
            Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 10, 100)));
            Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(10, 0, 10, 100)));
            Assert.That(view2.Bounds, Is.EqualTo(new Rectangle(20, 0, 10, 100)));
        }
Ejemplo n.º 3
0
        public void TestFlexDirectionColumnWithoutHeight()
        {
            var platform = new UnitPlatform();
            var view0    = new View {
                Platform = platform, IsPlatformEnabled = true, HeightRequest = 10
            };
            var view1 = new View {
                Platform = platform, IsPlatformEnabled = true, HeightRequest = 10
            };
            var view2 = new View {
                Platform = platform, IsPlatformEnabled = true, HeightRequest = 10
            };
            var layout = new FlexLayout {
                Platform          = platform,
                IsPlatformEnabled = true,
                Children          =
                {
                    view0,
                    view1,
                    view2,
                },

                Direction = FlexDirection.Column,
            };

            var sizeRequest = layout.Measure(100, double.PositiveInfinity);

            layout.Layout(new Rectangle(0, 0, sizeRequest.Request.Width, sizeRequest.Request.Height));
            Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 30)));
            Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 10)));
            Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(0, 10, 100, 10)));
            Assert.That(view2.Bounds, Is.EqualTo(new Rectangle(0, 20, 100, 10)));
        }
Ejemplo n.º 4
0
        public void TestAlignContentFlexEnd()
        {
            MockPlatformSizeService.Current.GetPlatformSizeFunc = (visual, width, height) => new SizeRequest(new Size(50, 10));

            var layout = new FlexLayout
            {
                IsPlatformEnabled = true,
                WidthRequest      = 100,
                HeightRequest     = 100,

                Direction    = FlexDirection.Column,
                AlignContent = FlexAlignContent.End,
                AlignItems   = FlexAlignItems.Start,
                Wrap         = FlexWrap.Wrap,
            };

            Func <View> createView = () => new View
            {
                IsPlatformEnabled = true,
                WidthRequest      = 50,
                HeightRequest     = 10,
            };
            var view0 = createView();

            layout.Children.Add(view0);

            var view1 = createView();

            layout.Children.Add(view1);

            var view2 = createView();

            layout.Children.Add(view2);

            var view3 = createView();

            layout.Children.Add(view3);

            var view4 = createView();

            layout.Children.Add(view4);

            var measure = layout.Measure(100, 100);

            layout.Layout(new Rect(0, 0, 100, 100));

            Assert.That(layout.Bounds, Is.EqualTo(new Rect(0, 0, 100, 100)));
            Assert.That(view0.Bounds, Is.EqualTo(new Rect(50, 0, 50, 10)));
            Assert.That(view1.Bounds, Is.EqualTo(new Rect(50, 10, 50, 10)));
            Assert.That(view2.Bounds, Is.EqualTo(new Rect(50, 20, 50, 10)));
            Assert.That(view3.Bounds, Is.EqualTo(new Rect(50, 30, 50, 10)));
            Assert.That(view4.Bounds, Is.EqualTo(new Rect(50, 40, 50, 10)));
        }
Ejemplo n.º 5
0
        public void TestMarginsWithWrap()
        {
            var platform = new UnitPlatform();
            var label0   = new Label {
                Platform          = platform,
                IsPlatformEnabled = true,
                Margin            = 6,
            };
            var label1 = new Label {
                Platform          = platform,
                IsPlatformEnabled = true,
                Margin            = 6,
            };
            var label2 = new Label {
                Platform          = platform,
                IsPlatformEnabled = true,
            };

            FlexLayout.SetGrow(label0, 0);
            FlexLayout.SetBasis(label0, new FlexBasis(.5f, true));
            FlexLayout.SetGrow(label1, 0);
            FlexLayout.SetBasis(label1, new FlexBasis(.5f, true));
            FlexLayout.SetGrow(label2, 0);
            FlexLayout.SetBasis(label2, new FlexBasis(1f, true));
            var layout = new FlexLayout {
                Platform          = platform,
                IsPlatformEnabled = true,
                Direction         = FlexDirection.Row,
                Wrap         = FlexWrap.Wrap,
                AlignItems   = FlexAlignItems.Start,
                AlignContent = FlexAlignContent.Start,
                Children     =
                {
                    label0,
                    label1,
                    label2,
                }
            };

            var measure = layout.Measure(300, double.PositiveInfinity);

            Assert.That(measure.Request, Is.EqualTo(new Size(300, 52)));
            layout.Layout(new Rectangle(0, 0, 300, 300));
            Assert.That(label0.Bounds, Is.EqualTo(new Rectangle(6, 6, 138, 20)));
            Assert.That(label1.Bounds, Is.EqualTo(new Rectangle(156, 6, 138, 20)));
            Assert.That(label2.Bounds, Is.EqualTo(new Rectangle(0, 32, 300, 20)));
        }