Пример #1
0
        public void TestMeasureOverrideRelative()
        {
            ResetState();

            // check that desired size is null if no children
            Measure(1000 * rand.NextVector3());
            Assert.AreEqual(Vector3.Zero, DesiredSize);

            var child = new MeasureValidator();

            child.DependencyProperties.Set(RelativeSizePropertyKey, new Vector3(0.2f, 0.3f, 0.4f));
            Children.Add(child);

            child.ExpectedMeasureValue  = new Vector3(2, 3, 4);
            child.ReturnedMeasuredValue = new Vector3(4, 3, 2);
            Measure(10 * Vector3.One);
            // canvas size does not depend on its children
            Assert.AreEqual(Vector3.Zero, DesiredSize);
        }
Пример #2
0
        public void TestMeasureOverrideAbsolute()
        {
            ResetState();

            // check that desired size is null if no children
            Measure(1000 * rand.NextVector3());
            Assert.AreEqual(Vector3.Zero, DesiredSize);

            var child = new MeasureValidator();

            Children.Add(child);
            child.Margin = Thickness.UniformCuboid(10);

            // check canvas desired size and child provided size with one child out of the available zone
            var availableSize    = new Vector3(100, 200, 300);
            var childDesiredSize = new Vector3(30, 80, 130);

            var pinOrigin = Vector3.Zero;

            TestOutOfBounds(child, childDesiredSize, new Vector3(float.PositiveInfinity), new Vector3(-1, 100, 150), pinOrigin, availableSize, Vector3.Zero);
        }
Пример #3
0
        public void TestMeasureOverride()
        {
            ResetState();

            // test that desired size is null if no children
            Measure(1000 * rand.NextVector3());
            Assert.AreEqual(Vector3.Zero, DesiredSize);

            // Create and add children
            var child1 = new MeasureValidator();
            var child2 = new MeasureValidator();
            var child3 = new MeasureValidator();

            Children.Add(child1);
            Children.Add(child2);
            Children.Add(child3);

            // tests desired size depending on the orientation
            TestMeasureOverrideCore(Orientation.Horizontal);
            TestMeasureOverrideCore(Orientation.Vertical);
            TestMeasureOverrideCore(Orientation.InDepth);
        }
Пример #4
0
        public void TestMeasureOverrideInfinite()
        {
            var child1 = new MeasureValidator();
            var canvas = new Canvas {
                Children = { child1 }
            };

            // check that relative 0 x inf available = 0
            child1.SetCanvasRelativeSize(Vector3.Zero);
            child1.ExpectedMeasureValue = Vector3.Zero;
            canvas.Measure(new Vector3(float.PositiveInfinity));
            child1.SetCanvasRelativeSize(new Vector3(float.NaN));

            // check sizes with infinite measure values and absolute position
            child1.SetCanvasAbsolutePosition(new Vector3(1, -1, -3));
            child1.ExpectedMeasureValue  = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
            child1.ReturnedMeasuredValue = new Vector3(2);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            // canvas size does not depend on its children
            Assert.AreEqual(Vector3.Zero, canvas.DesiredSizeWithMargins);

            // check sizes with infinite measure values and relative position
            child1.SetCanvasPinOrigin(new Vector3(0, .5f, 1));
            child1.SetCanvasRelativePosition(new Vector3(-1));
            child1.ExpectedMeasureValue  = new Vector3(0);
            child1.ReturnedMeasuredValue = new Vector3(1);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            // canvas size does not depend on its children
            Assert.AreEqual(Vector3.Zero, canvas.DesiredSizeWithMargins);
            child1.SetCanvasRelativePosition(new Vector3(0));
            child1.ExpectedMeasureValue  = new Vector3(float.PositiveInfinity, 0, 0);
            child1.ReturnedMeasuredValue = new Vector3(1);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            // canvas size does not depend on its children
            Assert.AreEqual(Vector3.Zero, canvas.DesiredSizeWithMargins);
            child1.SetCanvasRelativePosition(new Vector3(0.5f));
            child1.ExpectedMeasureValue  = new Vector3(float.PositiveInfinity);
            child1.ReturnedMeasuredValue = new Vector3(1);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            // canvas size does not depend on its children
            Assert.AreEqual(Vector3.Zero, canvas.DesiredSizeWithMargins);
            child1.SetCanvasRelativePosition(new Vector3(1f));
            child1.ExpectedMeasureValue  = new Vector3(float.PositiveInfinity);
            child1.ReturnedMeasuredValue = new Vector3(1);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            // canvas size does not depend on its children
            Assert.AreEqual(Vector3.Zero, canvas.DesiredSizeWithMargins);
            child1.SetCanvasRelativePosition(new Vector3(2f));
            child1.ExpectedMeasureValue  = new Vector3(float.PositiveInfinity);
            child1.ReturnedMeasuredValue = new Vector3(1);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            // canvas size does not depend on its children
            Assert.AreEqual(Vector3.Zero, canvas.DesiredSizeWithMargins);

            // check that the maximum is correctly taken
            var child2 = new MeasureValidator();
            var child3 = new MeasureValidator();

            canvas.Children.Add(child2);
            canvas.Children.Add(child3);
            child1.InvalidateMeasure();
            child1.SetCanvasPinOrigin(new Vector3(0.5f));
            child1.SetCanvasRelativePosition(new Vector3(0.5f));
            child1.ExpectedMeasureValue  = new Vector3(float.PositiveInfinity);
            child1.ReturnedMeasuredValue = new Vector3(10);
            child2.SetCanvasPinOrigin(new Vector3(0.5f));
            child2.SetCanvasRelativePosition(new Vector3(-.1f, .5f, 1.2f));
            child2.ExpectedMeasureValue  = new Vector3(float.PositiveInfinity);
            child2.ReturnedMeasuredValue = new Vector3(30.8f, 5, 48);
            child3.SetCanvasRelativeSize(new Vector3(0f, 1f, 2f));
            child3.ExpectedMeasureValue  = new Vector3(0, float.PositiveInfinity, float.PositiveInfinity);
            child3.ReturnedMeasuredValue = new Vector3(0, 5, 50);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            // canvas size does not depend on its children
            Assert.AreEqual(Vector3.Zero, canvas.DesiredSizeWithMargins);
        }
Пример #5
0
        public void TestMeasureOverrideAbsolute()
        {
            ResetState();

            // check that desired size is null if no children
            Measure(1000 * rand.NextVector3());
            Assert.AreEqual(Vector3.Zero, DesiredSize);

            var child = new MeasureValidator();

            Children.Add(child);
            child.Margin = Thickness.UniformCuboid(10);

            // check canvas desired size and child provided size with one child out of the available zone
            var availableSize    = new Vector3(100, 200, 300);
            var childDesiredSize = new Vector3(30, 80, 130);

            var pinOrigin = Vector3.Zero;

            TestOutOfBounds(child, childDesiredSize, new Vector3(0, 80, 130), new Vector3(-1, 100, 150), pinOrigin, availableSize, new Vector3(49, 200, 300));
            TestOutOfBounds(child, childDesiredSize, new Vector3(0, 80, 130), new Vector3(101, 100, 150), pinOrigin, availableSize, new Vector3(151, 200, 300));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 0, 130), new Vector3(50, -1, 150), pinOrigin, availableSize, new Vector3(100, 99, 300));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 0, 130), new Vector3(50, 201, 150), pinOrigin, availableSize, new Vector3(100, 301, 300));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 80, 0), new Vector3(50, 100, -1), pinOrigin, availableSize, new Vector3(100, 200, 149));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 80, 0), new Vector3(50, 100, 301), pinOrigin, availableSize, new Vector3(100, 200, 451));

            pinOrigin = Vector3.One;
            TestOutOfBounds(child, childDesiredSize, new Vector3(0, 80, 130), new Vector3(-1, 100, 150), pinOrigin, availableSize, new Vector3(0, 100, 150));
            TestOutOfBounds(child, childDesiredSize, new Vector3(0, 80, 130), new Vector3(101, 100, 150), pinOrigin, availableSize, new Vector3(101, 100, 150));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 0, 130), new Vector3(50, -1, 150), pinOrigin, availableSize, new Vector3(50, 0, 150));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 0, 130), new Vector3(50, 201, 150), pinOrigin, availableSize, new Vector3(50, 201, 150));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 80, 0), new Vector3(50, 100, -1), pinOrigin, availableSize, new Vector3(50, 100, 0));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 80, 0), new Vector3(50, 100, 301), pinOrigin, availableSize, new Vector3(50, 100, 301));

            pinOrigin = 0.5f * Vector3.One;
            TestOutOfBounds(child, childDesiredSize, new Vector3(0, 180, 280), new Vector3(-1, 100, 150), pinOrigin, availableSize, new Vector3(24, 150, 225));
            TestOutOfBounds(child, childDesiredSize, new Vector3(0, 180, 280), new Vector3(101, 100, 150), pinOrigin, availableSize, new Vector3(126, 150, 225));
            TestOutOfBounds(child, childDesiredSize, new Vector3(80, 0, 280), new Vector3(50, -1, 150), pinOrigin, availableSize, new Vector3(75, 49, 225));
            TestOutOfBounds(child, childDesiredSize, new Vector3(80, 0, 280), new Vector3(50, 201, 150), pinOrigin, availableSize, new Vector3(75, 251, 225));
            TestOutOfBounds(child, childDesiredSize, new Vector3(80, 180, 0), new Vector3(50, 100, -1), pinOrigin, availableSize, new Vector3(75, 150, 74));
            TestOutOfBounds(child, childDesiredSize, new Vector3(80, 180, 0), new Vector3(50, 100, 301), pinOrigin, availableSize, new Vector3(75, 150, 376));

            // check canvas desired size and child provided size with one child in the available zone
            var position = availableSize / 2;

            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 80, 130), position, Vector3.Zero, availableSize, new Vector3(100, 200, 300));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 80, 130), position, Vector3.One, availableSize, new Vector3(50, 100, 150));
            TestOutOfBounds(child, childDesiredSize, new Vector3(80, 180, 280), position, 0.5f * Vector3.One, availableSize, new Vector3(75, 150, 225));

            // check that canvas desired size with several children
            ResetState();
            var child1 = new CanvasTests();
            var child2 = new CanvasTests();
            var child3 = new CanvasTests();

            Children.Add(child1);
            Children.Add(child2);
            Children.Add(child3);
            child1.Margin = new Thickness(10, 20, 30, 40, 50, 60);
            child2.Margin = new Thickness(60, 50, 40, 30, 20, 10);
            child3.Margin = new Thickness(1, 2, 3, 4, 5, 6);
            child1.Width  = 100;
            child1.Height = 200;
            child1.Depth  = 300;
            child2.Width  = 10;
            child2.Height = 20;
            child2.Depth  = 30;
            child3.Width  = 300;
            child3.Height = 200;
            child3.Depth  = 100;
            child1.DependencyProperties.Set(AbsolutePositionPropertyKey, new Vector3(1000, 1100, 1200));
            child1.DependencyProperties.Set(PinOriginPropertyKey, new Vector3(0, 0, 1));
            child2.DependencyProperties.Set(AbsolutePositionPropertyKey, new Vector3(1050, 1150, 1200));
            child2.DependencyProperties.Set(PinOriginPropertyKey, new Vector3(1, 1, 0));
            child3.DependencyProperties.Set(AbsolutePositionPropertyKey, new Vector3(500, 600, 700));
            child3.DependencyProperties.Set(PinOriginPropertyKey, new Vector3(0.5f, 0.5f, 0.5f));
            Measure(Vector3.Zero);
            Assert.AreEqual(new Vector3(1150, 1370, 1280), DesiredSize);
        }
Пример #6
0
        public void TestMeasureOverride()
        {
            ResetState();

            // test that desired size is null if no children
            Measure(1000 * rand.NextVector3());
            Assert.AreEqual(Vector3.Zero, DesiredSize);

            // Create and add children
            var child1 = new MeasureValidator();
            var child2 = new MeasureValidator();
            var child3 = new MeasureValidator();
            Children.Add(child1);
            Children.Add(child2);
            Children.Add(child3);
            
            // tests desired size depending on the orientation
            TestMeasureOverrideCore(Orientation.Horizontal);
            TestMeasureOverrideCore(Orientation.Vertical);
            TestMeasureOverrideCore(Orientation.InDepth);
        }
Пример #7
0
        public void TestMeasureProvidedSizeAuto0()
        {
            var grid = new Grid();

            var providedSize = 100 * Vector3.One;

            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto) { MaximumSize = 10 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));

            var child0 = new MeasureValidator { Name = "0", ReturnedMeasuredValue = providedSize, ExpectedMeasureValue = providedSize };
            var child1 = new MeasureValidator { Name = "1", ReturnedMeasuredValue = providedSize, ExpectedMeasureValue = new Vector3(10, providedSize.Y, providedSize.Z) };
            var child2 = new MeasureValidator { Name = "2", ReturnedMeasuredValue = providedSize, ExpectedMeasureValue = providedSize };

            child0.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);
            child1.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            child2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 2);

            grid.Children.Add(child0);
            grid.Children.Add(child1);
            grid.Children.Add(child2);

            grid.Measure(providedSize);
        }
Пример #8
0
        public void TestMeasureProvidedSizeAutoMix()
        {
            var grid = new Grid();

            var providedSize = 100 * Vector3.One;

            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto) { MaximumSize = 10 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 20));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 30) { MaximumSize = 25 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto) { MinimumSize = 10 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star) { MinimumSize = 15 });

            var child2 = new MeasureValidator { Name = "2", ExpectedMeasureValue = new Vector3(030, providedSize.Y, providedSize.Z), ReturnedMeasuredValue = new Vector3(030, 100, 100) };
            var child3 = new MeasureValidator { Name = "3", ExpectedMeasureValue = new Vector3(050, providedSize.Y, providedSize.Z), ReturnedMeasuredValue = new Vector3(050, 100, 100) };
            var child4 = new MeasureValidator { Name = "4", ExpectedMeasureValue = new Vector3(075, providedSize.Y, providedSize.Z), ReturnedMeasuredValue = new Vector3(075, 100, 100) };
            var child5 = new MeasureValidator { Name = "5", ExpectedMeasureValue = new Vector3(085, providedSize.Y, providedSize.Z), ReturnedMeasuredValue = new Vector3(085, 100, 100) };
            var child6 = new MeasureValidator { Name = "6", ExpectedMeasureValue = new Vector3(100, providedSize.Y, providedSize.Z), ReturnedMeasuredValue = new Vector3(100, 100, 100) };

            child2.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);
            child3.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 3);
            child4.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 4);
            child5.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 5);
            child6.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 6);

            grid.Children.Add(child2);
            grid.Children.Add(child3);
            grid.Children.Add(child4);
            grid.Children.Add(child5);
            grid.Children.Add(child6);

            grid.Measure(providedSize);
        }
        public void TestMeasureOverride()
        {
            ResetState();

            // test that desired size without content correspond to padding
            Padding = rand.NextThickness(10, 20, 30, 40, 50, 60);
            Measure(1000*rand.NextVector3());
            var v0 = Vector3.Zero;
            var expectedSize = CalculateSizeWithThickness(ref v0, ref padding);
            Assert.AreEqual(expectedSize, DesiredSize);

            // test desired size with a child
            var content = new MeasureValidator();
            Content = content;
            var availableSize = 1000 * rand.NextVector3();
            content.Margin = rand.NextThickness(60, 50, 40, 30, 20, 10);
            var availableSizeWithoutPadding = CalculateSizeWithoutThickness(ref availableSize, ref padding);
            var availableSizeWithoutPaddingChildMargin = CalculateSizeWithoutThickness(ref availableSizeWithoutPadding, ref content.MarginInternal);
            content.ExpectedMeasureValue = availableSizeWithoutPaddingChildMargin;
            content.ReturnedMeasuredValue = 100 * rand.NextVector3();
            var returnedValueWithMargin = CalculateSizeWithThickness(ref content.ReturnedMeasuredValue, ref content.MarginInternal);
            expectedSize = CalculateSizeWithThickness(ref returnedValueWithMargin, ref padding);
            Measure(availableSize);
            Assert.AreEqual(expectedSize, DesiredSize);
        }
Пример #10
0
        public void TestMeasureProvidedSizeFixedMulti()
        {
            var grid = new Grid();

            var providedSize = 1000 * rand.NextVector3();

            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed) { MinimumSize = 5 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed) { MaximumSize = 0.5f });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 2));

            var child2 = new MeasureValidator { Name = "2", ExpectedMeasureValue = new Vector3(3f, providedSize.Y, providedSize.Z), ReturnedMeasuredValue = providedSize };
            var child4 = new MeasureValidator { Name = "4", ExpectedMeasureValue = new Vector3(8.5f, providedSize.Y, providedSize.Z), ReturnedMeasuredValue = providedSize };

            child2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 2);
            child4.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);

            child2.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);
            child4.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 4);

            grid.Children.Add(child2);
            grid.Children.Add(child4);

            grid.Measure(providedSize);
        }
Пример #11
0
        public void TestMeasureOverrideInfinite()
        {
            var child1 = new MeasureValidator();
            var canvas = new Canvas { Children = { child1 } };

            // check that relative 0 x inf available = 0 
            child1.SetCanvasRelativeSize(Vector3.Zero);
            child1.ExpectedMeasureValue = Vector3.Zero;
            canvas.Measure(new Vector3(float.PositiveInfinity));
            child1.SetCanvasRelativeSize(new Vector3(float.NaN));

            // check sizes with infinite measure values and absolute position
            child1.SetCanvasAbsolutePosition(new Vector3(1, -1, -3));
            child1.ExpectedMeasureValue = new Vector3(float.PositiveInfinity, 0, 0);
            child1.ReturnedMeasuredValue = new Vector3(2);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(new Vector3(3, 1, 0), canvas.DesiredSizeWithMargins);

            // check sizes with infinite measure values and relative position
            child1.SetCanvasPinOrigin(new Vector3(0, .5f, 1));
            child1.SetCanvasRelativePosition(new Vector3(-1));
            child1.ExpectedMeasureValue = new Vector3(0);
            child1.ReturnedMeasuredValue = new Vector3(1);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(new Vector3(0.5f, 0.25f, 0), canvas.DesiredSizeWithMargins);
            child1.SetCanvasRelativePosition(new Vector3(0));
            child1.ExpectedMeasureValue = new Vector3(float.PositiveInfinity, 0, 0);
            child1.ReturnedMeasuredValue = new Vector3(1);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(new Vector3(1, 0.5f, 0), canvas.DesiredSizeWithMargins);
            child1.SetCanvasRelativePosition(new Vector3(0.5f));
            child1.ExpectedMeasureValue = new Vector3(float.PositiveInfinity);
            child1.ReturnedMeasuredValue = new Vector3(1);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(new Vector3(2, 1, 2), canvas.DesiredSizeWithMargins);
            child1.SetCanvasRelativePosition(new Vector3(1f));
            child1.ExpectedMeasureValue = new Vector3(float.PositiveInfinity);
            child1.ReturnedMeasuredValue = new Vector3(1);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(new Vector3(0, 0.5f, 1), canvas.DesiredSizeWithMargins);
            child1.SetCanvasRelativePosition(new Vector3(2f));
            child1.ExpectedMeasureValue = new Vector3(float.PositiveInfinity);
            child1.ReturnedMeasuredValue = new Vector3(1);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(new Vector3(0, 0.25f, 0.5f), canvas.DesiredSizeWithMargins);

            // check that the maximum is correctly taken
            var child2 = new MeasureValidator();
            var child3 = new MeasureValidator();
            canvas.Children.Add(child2);
            canvas.Children.Add(child3);
            child1.InvalidateMeasure();
            child1.SetCanvasPinOrigin(new Vector3(0.5f));
            child1.SetCanvasRelativePosition(new Vector3(0.5f));
            child1.ExpectedMeasureValue = new Vector3(float.PositiveInfinity);
            child1.ReturnedMeasuredValue = new Vector3(10);
            child2.SetCanvasPinOrigin(new Vector3(0.5f));
            child2.SetCanvasRelativePosition(new Vector3(-.1f, .5f, 1.2f));
            child2.ExpectedMeasureValue = new Vector3(0, float.PositiveInfinity, float.PositiveInfinity);
            child2.ReturnedMeasuredValue = new Vector3(30.8f, 5, 48);
            child3.SetCanvasRelativeSize(new Vector3(0f, 1f, 2f));
            child3.ExpectedMeasureValue = new Vector3(0, float.PositiveInfinity, float.PositiveInfinity);
            child3.ReturnedMeasuredValue = new Vector3(0, 5, 50);
            canvas.Measure(new Vector3(float.PositiveInfinity));
            Assert.AreEqual(new Vector3(14f, 10f, 25f), canvas.DesiredSizeWithMargins);
        }
Пример #12
0
 private void TestOutOfBounds(MeasureValidator child, Vector3 childDesiredSize, Vector3 childExpectedValue, Vector3 pinPosition, Vector3 pinOrigin, Vector3 availableSize, Vector3 expectedSize)
 {
     child.ExpectedMeasureValue = childExpectedValue;
     child.ReturnedMeasuredValue = childDesiredSize;
     child.DependencyProperties.Set(AbsolutePositionPropertyKey, pinPosition);
     child.DependencyProperties.Set(PinOriginPropertyKey, pinOrigin);
     Measure(availableSize);
     Assert.AreEqual(expectedSize, DesiredSize);
 }
Пример #13
0
        public void TestMeasureOverrideAbsolute()
        {
            ResetState();

            // check that desired size is null if no children
            Measure(1000 * rand.NextVector3());
            Assert.AreEqual(Vector3.Zero, DesiredSize);

            var child = new MeasureValidator();
            Children.Add(child);
            child.Margin = Thickness.UniformCuboid(10);

            // check canvas desired size and child provided size with one child out of the available zone
            var availableSize = new Vector3(100, 200, 300);
            var childDesiredSize = new Vector3(30, 80, 130);

            var pinOrigin = Vector3.Zero;
            TestOutOfBounds(child, childDesiredSize, new Vector3(0, 80, 130), new Vector3(-1, 100, 150), pinOrigin, availableSize, new Vector3(49, 200, 300));
            TestOutOfBounds(child, childDesiredSize, new Vector3(0, 80, 130), new Vector3(101, 100, 150), pinOrigin, availableSize, new Vector3(151, 200, 300));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 0, 130), new Vector3(50, -1, 150), pinOrigin, availableSize, new Vector3(100, 99, 300));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 0, 130), new Vector3(50, 201, 150), pinOrigin, availableSize, new Vector3(100, 301, 300));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 80,  0), new Vector3(50, 100, -1), pinOrigin, availableSize, new Vector3(100, 200, 149));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 80,  0), new Vector3(50, 100, 301), pinOrigin, availableSize, new Vector3(100, 200, 451));

            pinOrigin = Vector3.One;
            TestOutOfBounds(child, childDesiredSize, new Vector3(0, 80, 130), new Vector3(-1, 100, 150), pinOrigin, availableSize, new Vector3(0, 100, 150));
            TestOutOfBounds(child, childDesiredSize, new Vector3(0, 80, 130), new Vector3(101, 100, 150), pinOrigin, availableSize, new Vector3(101, 100, 150));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 0, 130), new Vector3(50, -1, 150), pinOrigin, availableSize, new Vector3(50, 0, 150));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 0, 130), new Vector3(50, 201, 150), pinOrigin, availableSize, new Vector3(50, 201, 150));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 80,  0), new Vector3(50, 100, -1), pinOrigin, availableSize, new Vector3(50, 100, 0));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 80,  0), new Vector3(50, 100, 301), pinOrigin, availableSize, new Vector3(50, 100, 301));

            pinOrigin = 0.5f * Vector3.One;
            TestOutOfBounds(child, childDesiredSize, new Vector3(0, 180, 280), new Vector3(-1, 100, 150), pinOrigin, availableSize, new Vector3(24, 150, 225));
            TestOutOfBounds(child, childDesiredSize, new Vector3(0, 180, 280), new Vector3(101, 100, 150), pinOrigin, availableSize, new Vector3(126, 150, 225));
            TestOutOfBounds(child, childDesiredSize, new Vector3(80, 0, 280), new Vector3(50, -1, 150), pinOrigin, availableSize, new Vector3(75, 49, 225));
            TestOutOfBounds(child, childDesiredSize, new Vector3(80, 0, 280), new Vector3(50, 201, 150), pinOrigin, availableSize, new Vector3(75, 251, 225));
            TestOutOfBounds(child, childDesiredSize, new Vector3(80, 180,  0), new Vector3(50, 100, -1), pinOrigin, availableSize, new Vector3(75, 150, 74));
            TestOutOfBounds(child, childDesiredSize, new Vector3(80, 180,  0), new Vector3(50, 100, 301), pinOrigin, availableSize, new Vector3(75, 150, 376));

            // check canvas desired size and child provided size with one child in the available zone
            var position = availableSize / 2;
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 80, 130), position, Vector3.Zero, availableSize, new Vector3(100, 200, 300));
            TestOutOfBounds(child, childDesiredSize, new Vector3(30, 80, 130), position, Vector3.One, availableSize, new Vector3(50, 100, 150));
            TestOutOfBounds(child, childDesiredSize, new Vector3(80, 180, 280), position, 0.5f * Vector3.One, availableSize, new Vector3(75, 150, 225));

            // check that canvas desired size with several children
            ResetState();
            var child1 = new CanvasTests();
            var child2 = new CanvasTests();
            var child3 = new CanvasTests();
            Children.Add(child1);
            Children.Add(child2);
            Children.Add(child3);
            child1.Margin = new Thickness(10, 20, 30, 40, 50, 60);
            child2.Margin = new Thickness(60, 50, 40, 30, 20, 10);
            child3.Margin = new Thickness(1, 2, 3, 4, 5, 6);
            child1.Width = 100;
            child1.Height = 200;
            child1.Depth = 300;
            child2.Width = 10;
            child2.Height = 20;
            child2.Depth = 30;
            child3.Width = 300;
            child3.Height = 200;
            child3.Depth = 100;
            child1.DependencyProperties.Set(AbsolutePositionPropertyKey, new Vector3(1000, 1100, 1200));
            child1.DependencyProperties.Set(PinOriginPropertyKey, new Vector3(0, 0, 1));
            child2.DependencyProperties.Set(AbsolutePositionPropertyKey, new Vector3(1050, 1150, 1200));
            child2.DependencyProperties.Set(PinOriginPropertyKey, new Vector3(1, 1, 0));
            child3.DependencyProperties.Set(AbsolutePositionPropertyKey, new Vector3(500, 600, 700));
            child3.DependencyProperties.Set(PinOriginPropertyKey, new Vector3(0.5f, 0.5f, 0.5f));
            Measure(Vector3.Zero);
            Assert.AreEqual(new Vector3(1150, 1370, 1280), DesiredSize);
        }
Пример #14
0
        public void TestMeasureOverrideRelative()
        {
            ResetState();

            // check that desired size is null if no children
            Measure(1000 * rand.NextVector3());
            Assert.AreEqual(Vector3.Zero, DesiredSize);

            var child = new MeasureValidator();
            child.DependencyProperties.Set(RelativeSizePropertyKey, new Vector3(0.2f,0.3f,0.4f));
            Children.Add(child);
            
            child.ExpectedMeasureValue = new Vector3(2,3,4);
            child.ReturnedMeasuredValue = new Vector3(4,3,2);
            Measure(10 * Vector3.One);
            Assert.AreEqual(new Vector3(20f, 10f, 5f), DesiredSize);
        }
Пример #15
0
        public void TestMeasureOverrideAbsolute()
        {
            ResetState();

            // check that desired size is null if no children
            Measure(1000 * rand.NextVector3());
            Assert.AreEqual(Vector3.Zero, DesiredSize);

            var child = new MeasureValidator();
            Children.Add(child);
            child.Margin = Thickness.UniformCuboid(10);

            // check canvas desired size and child provided size with one child out of the available zone
            var availableSize = new Vector3(100, 200, 300);
            var childDesiredSize = new Vector3(30, 80, 130);

            var pinOrigin = Vector3.Zero;
            TestOutOfBounds(child, childDesiredSize, new Vector3(float.PositiveInfinity), new Vector3(-1, 100, 150), pinOrigin, availableSize, Vector3.Zero);
        }