コード例 #1
0
        public void TestAlignContentStretchRowWithFlex()
        {
            var platform = new UnitPlatform();
            var layout   = new FlexLayout {
                Platform          = platform,
                IsPlatformEnabled = true,

                AlignContent = FlexAlignContent.Stretch,
                Direction    = FlexDirection.Row,
                Wrap         = FlexWrap.Wrap,
            };
            var view0 = new View {
                IsPlatformEnabled = true, WidthRequest = 50
            };

            layout.Children.Add(view0);

            var view1 = new View {
                IsPlatformEnabled = true, WidthRequest = 50
            };

            FlexLayout.SetGrow(view1, 1);
            FlexLayout.SetShrink(view1, 1);
            FlexLayout.SetBasis(view1, 0);
            layout.Children.Add(view1);

            var view2 = new View {
                IsPlatformEnabled = true, WidthRequest = 50
            };

            layout.Children.Add(view2);

            var view3 = new View {
                IsPlatformEnabled = true, WidthRequest = 50
            };

            FlexLayout.SetGrow(view3, 1);
            FlexLayout.SetShrink(view3, 1);
            FlexLayout.SetBasis(view3, 0);
            layout.Children.Add(view3);

            var view4 = new View {
                IsPlatformEnabled = true, WidthRequest = 50
            };

            layout.Children.Add(view4);

            layout.Layout(new Rectangle(0, 0, 150, 100));

            Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 150, 100)));
            Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 50, 100)));
            Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(50, 0, 0, 100)));
            Assert.That(view2.Bounds, Is.EqualTo(new Rectangle(50, 0, 50, 100)));
            Assert.That(view3.Bounds, Is.EqualTo(new Rectangle(100, 0, 0, 100)));
            Assert.That(view4.Bounds, Is.EqualTo(new Rectangle(100, 0, 50, 100)));
        }
コード例 #2
0
        public void TestSizeThatFits()
        {
            var platform = new UnitPlatform(useRealisticLabelMeasure: true);

            var layout = new FlexLayout {
                Direction         = FlexDirection.Row,
                AlignItems        = FlexAlignItems.Start,
                Platform          = platform,
                IsPlatformEnabled = true
            };

            var label1 = new Label {
                Platform          = platform,
                IsPlatformEnabled = true,
                LineBreakMode     = LineBreakMode.TailTruncation,
                Text = @"This is a very very very very very very very very long piece of text."
            };

            FlexLayout.SetShrink(label1, 1);
            layout.Children.Add(label1);

            var label2 = new Label {
                Text              = "",
                Platform          = platform,
                IsPlatformEnabled = true,
                WidthRequest      = 10,
                HeightRequest     = 10
            };

            layout.Children.Add(label2);
            layout.Layout(new Rectangle(0, 0, 320, 50));

            var label2Size = label2.Measure(double.PositiveInfinity, double.PositiveInfinity);

            Assert.AreEqual(10, label2Size.Request.Height);
            Assert.AreEqual(10, label2Size.Request.Width);

            var label1Size = label1.Measure(double.PositiveInfinity, double.PositiveInfinity);
            //	var layoutSize = layout.Measure(-1, -1);
        }
コード例 #3
0
 public static TView Shrink <TView>(this TView view, float value) where TView : View
 {
     FlexLayout.SetShrink(view, value);
     return(view);
 }
コード例 #4
0
        public void TestAlignContentStretchRowWithFlexNoShrink()
        {
            var platform = new UnitPlatform();
            var layout   = new FlexLayout {
                Platform          = platform,
                IsPlatformEnabled = true,
                Direction         = FlexDirection.Row,
                AlignContent      = FlexAlignContent.Stretch,
                Wrap          = FlexWrap.Wrap,
                WidthRequest  = 150,
                HeightRequest = 100
            };
            var view0 = new View {
                IsPlatformEnabled = true, WidthRequest = 50
            };

            layout.Children.Add(view0);

            var view1 = new View {
                IsPlatformEnabled = true, WidthRequest = 50
            };

            FlexLayout.SetGrow(view1, 1);
            FlexLayout.SetShrink(view1, 1);
            FlexLayout.SetBasis(view1, 0);
            layout.Children.Add(view1);

            var view2 = new View {
                IsPlatformEnabled = true, WidthRequest = 50
            };

            layout.Children.Add(view2);

            var view3 = new View {
                IsPlatformEnabled = true, WidthRequest = 50
            };

            FlexLayout.SetGrow(view3, 1);
            FlexLayout.SetBasis(view3, 0);
            layout.Children.Add(view3);

            var view4 = new View {
                IsPlatformEnabled = true, WidthRequest = 50
            };

            layout.Children.Add(view4);

            layout.Layout(new Rectangle(0, 0, 150, 100));

            Assert.AreEqual(0f, layout.X);
            Assert.AreEqual(0f, layout.Y);
            Assert.AreEqual(150f, layout.Width);
            Assert.AreEqual(100f, layout.Height);

            Assert.AreEqual(0f, view0.X);
            Assert.AreEqual(0f, view0.Y);
            Assert.AreEqual(50f, view0.Width);
            Assert.AreEqual(100f, view0.Height);

            Assert.AreEqual(50f, view1.X);
            Assert.AreEqual(0f, view1.Y);
            Assert.AreEqual(0f, view1.Width);
            Assert.AreEqual(100f, view1.Height);

            Assert.AreEqual(50f, view2.X);
            Assert.AreEqual(0f, view2.Y);
            Assert.AreEqual(50f, view2.Width);
            Assert.AreEqual(100f, view2.Height);

            Assert.AreEqual(100f, view3.X);
            Assert.AreEqual(0f, view3.Y);
            Assert.AreEqual(0f, view3.Width);
            Assert.AreEqual(100f, view3.Height);

            Assert.AreEqual(100f, view4.X);
            Assert.AreEqual(0f, view4.Y);
            Assert.AreEqual(50f, view4.Width);
            Assert.AreEqual(100f, view4.Height);
        }
コード例 #5
0
        public void TestAlignContentFlexStartWithFlex()
        {
            var platform = new UnitPlatform((visual, width, height) => new SizeRequest(new Size(0, 0)));

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

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

            var view0 = new View {
                IsPlatformEnabled = true
            };

            FlexLayout.SetGrow(view0, 1);
            FlexLayout.SetBasis(view0, 0);
            view0.WidthRequest = 50;
            layout.Children.Add(view0);

            var view1 = new View {
                IsPlatformEnabled = true
            };

            FlexLayout.SetGrow(view1, 1);
            FlexLayout.SetBasis(view1, 0);
            view1.WidthRequest  = 50;
            view1.HeightRequest = 10;
            layout.Children.Add(view1);

            var view2 = new View {
                IsPlatformEnabled = true
            };

            view2.WidthRequest = 50;
            layout.Children.Add(view2);

            var view3 = new View {
                IsPlatformEnabled = true
            };

            FlexLayout.SetGrow(view3, 1);
            FlexLayout.SetShrink(view3, 1);
            FlexLayout.SetBasis(view3, 0);
            view3.WidthRequest = 50;
            layout.Children.Add(view3);

            var view4 = new View {
                IsPlatformEnabled = true
            };

            view4.WidthRequest = 50;
            layout.Children.Add(view4);

            layout.Layout(new Rectangle(0, 0, 100, 120));

            Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 120)));
            Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 50, 40)));
            Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(0, 40, 50, 40)));
            Assert.That(view2.Bounds, Is.EqualTo(new Rectangle(0, 80, 50, 0)));
            Assert.That(view3.Bounds, Is.EqualTo(new Rectangle(0, 80, 50, 40)));
            Assert.That(view4.Bounds, Is.EqualTo(new Rectangle(0, 120, 50, 0)));
        }
コード例 #6
0
 public static TView Shrink <TView>(this TView view, float value) where TView : View
 {
     VerifyExperimental();
     FlexLayout.SetShrink(view, value);
     return(view);
 }
コード例 #7
0
 public void Shrink() => AssertExperimental(() =>
 {
     FlexLayout.SetShrink(Bindable, 1f);
     Bindable.Shrink(0f);
     Assert.That(FlexLayout.GetShrink(Bindable), Is.EqualTo(0f));
 });
コード例 #8
0
 public void Shrink()
 {
     FlexLayout.SetShrink(Bindable, 1f);
     Bindable.Shrink(0f);
     Assert.That(FlexLayout.GetShrink(Bindable), Is.EqualTo(0f));
 }