Esempio n. 1
0
        public void TestArrangeOverride()
        {
            ResetState();

            DepthAlignment = DepthAlignment.Stretch;

            // Test that returned value is the one provided when no content
            var providedSize = 1000 * rand.NextVector3();
            var arrangedSize = ArrangeOverride(providedSize);

            Assert.AreEqual(providedSize, arrangedSize);

            ResetState();

            // Test arrange with some content
            providedSize = 1000 * rand.NextVector3();
            var content = new ArrangeValidator {
                DepthAlignment = DepthAlignment.Stretch
            };

            Content = content;
            Padding = rand.NextThickness(10, 20, 30, 40, 50, 60);
            var providedSizeWithoutPadding = CalculateSizeWithoutThickness(ref providedSize, ref padding);

            content.ExpectedArrangeValue = providedSizeWithoutPadding;
            arrangedSize = ArrangeOverride(providedSize);
            Assert.AreEqual(providedSize, arrangedSize);
            var childOffsets = new Vector3(Padding.Left, Padding.Top, Padding.Front) - arrangedSize / 2;

            Assert.AreEqual(Matrix.Translation(childOffsets), VisualContent.DependencyProperties.Get(ContentArrangeMatrixPropertyKey));
        }
Esempio n. 2
0
        public void TestArrangeOverrideRelative()
        {
            ResetState();

            DepthAlignment = DepthAlignment.Stretch;

            // test that arrange set render size to provided size when there is no children
            var providedSize = 1000 * rand.NextVector3();
            var providedSizeWithoutMargins = CalculateSizeWithoutThickness(ref providedSize, ref MarginInternal);

            Measure(providedSize);
            Arrange(providedSize, false);
            Assert.AreEqual(providedSizeWithoutMargins, RenderSize);

            ResetState();

            DepthAlignment = DepthAlignment.Stretch;

            var child = new ArrangeValidator();

            child.DependencyProperties.Set(RelativeSizePropertyKey, new Vector3(0.2f, 0.3f, 0.4f));
            child.DependencyProperties.Set(PinOriginPropertyKey, new Vector3(0f, 0.5f, 1f));
            child.DependencyProperties.Set(RelativePositionPropertyKey, new Vector3(0.2f, 0.4f, 0.6f));
            Children.Add(child);

            child.ReturnedMeasuredValue = 2 * new Vector3(2, 6, 12);
            child.ExpectedArrangeValue  = new Vector3(4, 12, 18);
            providedSize = new Vector3(10, 20, 30);
            Measure(providedSize);
            Arrange(providedSize, false);
            Assert.AreEqual(Matrix.Translation(2f - 5f, 8f - 6f - 10f, 18f - 18f - 15f), child.DependencyProperties.Get(PanelArrangeMatrixPropertyKey));
        }
Esempio n. 3
0
        public void TestArrangeOverrideAbsolute()
        {
            // test that arrange set render size to provided size when there is no children
            var nullCanvas = new Canvas {
                DepthAlignment = DepthAlignment.Stretch
            };
            var providedSize = 1000 * rand.NextVector3();
            var providedSizeWithoutMargins = CalculateSizeWithoutThickness(ref providedSize, ref MarginInternal);

            nullCanvas.Measure(providedSize);
            nullCanvas.Arrange(providedSize, false);
            Assert.AreEqual(providedSizeWithoutMargins, nullCanvas.RenderSize);

            // test that arrange works properly with valid children.
            var availablesizeWithMargins = new Vector3(200, 300, 500);
            var canvas = new Canvas {
                DepthAlignment = DepthAlignment.Stretch
            };

            for (int i = 0; i < 10; i++)
            {
                var child = new ArrangeValidator {
                    Name = i.ToString()
                };

                child.SetCanvasPinOrigin(new Vector3(0, 0.5f, 1));
                child.SetCanvasAbsolutePosition(((i >> 1) - 1) * 0.5f * availablesizeWithMargins);
                child.Margin = new Thickness(10, 11, 12, 13, 14, 15);

                child.ReturnedMeasuredValue = (i % 2) == 0? new Vector3(1000) : availablesizeWithMargins / 3f;
                child.ExpectedArrangeValue  = new Vector3(
                    Math.Min(child.ReturnedMeasuredValue.X, Math.Max(0, i > 1 ? availablesizeWithMargins.X * (1 - ((i >> 1) - 1) * 0.5f) - 23 : 0)),
                    Math.Min(child.ReturnedMeasuredValue.Y, (i >> 1) == 2? availablesizeWithMargins.Y - 25 : 0),
                    Math.Min(child.ReturnedMeasuredValue.Z, Math.Max(0, i < 8 ? availablesizeWithMargins.Z * (((i >> 1) - 1) * 0.5f) - 27 : 0)));

                canvas.Children.Add(child);
            }

            // Measure the stack
            canvas.Measure(availablesizeWithMargins);
            canvas.Arrange(availablesizeWithMargins, false);

            // checks the stack arranged size
            Assert.AreEqual(availablesizeWithMargins, canvas.RenderSize);

            // Checks the children arrange matrix
            for (int i = 0; i < canvas.Children.Count; i++)
            {
                var pinPosition  = canvas.Children[i].DependencyProperties.Get(AbsolutePositionPropertyKey);
                var pinOrigin    = canvas.Children[i].DependencyProperties.Get(PinOriginPropertyKey);
                var childOffsets = (pinPosition - Vector3.Modulate(pinOrigin, canvas.Children[i].RenderSize)) - canvas.RenderSize / 2;
                Assert.AreEqual(Matrix.Translation(childOffsets), canvas.Children[i].DependencyProperties.Get(PanelArrangeMatrixPropertyKey));
            }
        }
Esempio n. 4
0
        public void TestArrangeOverrideAbsolute()
        {
            // test that arrange set render size to provided size when there is no children
            var nullCanvas = new Canvas { DepthAlignment = DepthAlignment.Stretch};
            var providedSize = 1000 * rand.NextVector3();
            var providedSizeWithoutMargins = CalculateSizeWithoutThickness(ref providedSize, ref MarginInternal);
            nullCanvas.Measure(providedSize);
            nullCanvas.Arrange(providedSize, false);
            Assert.AreEqual(providedSizeWithoutMargins, nullCanvas.RenderSize);

            // test that arrange works properly with valid children.
            var availablesizeWithMargins = new Vector3(200, 300, 500);
            var canvas = new Canvas { DepthAlignment = DepthAlignment.Stretch };
            for (int i = 0; i < 10; i++)
            {
                var child = new ArrangeValidator { Name = i.ToString() };

                child.SetCanvasPinOrigin(new Vector3(0, 0.5f, 1));
                child.SetCanvasAbsolutePosition(((i>>1)-1) * 0.5f * availablesizeWithMargins);
                child.Margin = new Thickness(10, 11, 12, 13, 14, 15);

                child.ReturnedMeasuredValue = (i%2)==0? new Vector3(1000) : availablesizeWithMargins/3f;
                child.ExpectedArrangeValue = new Vector3(
                    Math.Min(child.ReturnedMeasuredValue.X, Math.Max(0, i > 1 ? availablesizeWithMargins.X * (1 - ((i >> 1) - 1) * 0.5f) - 23 : 0)),
                    Math.Min(child.ReturnedMeasuredValue.Y, (i>> 1) == 2? availablesizeWithMargins.Y - 25 : 0),
                    Math.Min(child.ReturnedMeasuredValue.Z, Math.Max(0, i < 8 ? availablesizeWithMargins.Z * (((i >> 1) - 1) * 0.5f) - 27 : 0)));

                canvas.Children.Add(child);
            }

            // Measure the stack
            canvas.Measure(availablesizeWithMargins);
            canvas.Arrange(availablesizeWithMargins, false);

            // checks the stack arranged size
            Assert.AreEqual(availablesizeWithMargins, canvas.RenderSize);

            // Checks the children arrange matrix
            for (int i = 0; i < canvas.Children.Count; i++)
            {
                var pinPosition = canvas.Children[i].DependencyProperties.Get(AbsolutePositionPropertyKey);
                var pinOrigin = canvas.Children[i].DependencyProperties.Get(PinOriginPropertyKey);
                var childOffsets = (pinPosition - Vector3.Modulate(pinOrigin, canvas.Children[i].RenderSize)) - canvas.RenderSize / 2;
                Assert.AreEqual(Matrix.Translation(childOffsets), canvas.Children[i].DependencyProperties.Get(PanelArrangeMatrixPropertyKey));
            }
        }
Esempio n. 5
0
        public void TestArrangeOverrideRelative()
        {
            ResetState();

            DepthAlignment = DepthAlignment.Stretch;

            // test that arrange set render size to provided size when there is no children
            var providedSize = 1000 * rand.NextVector3();
            var providedSizeWithoutMargins = CalculateSizeWithoutThickness(ref providedSize, ref MarginInternal);
            Measure(providedSize);
            Arrange(providedSize, false);
            Assert.AreEqual(providedSizeWithoutMargins, RenderSize);

            ResetState();

            DepthAlignment = DepthAlignment.Stretch;
            
            var child = new ArrangeValidator();
            child.DependencyProperties.Set(RelativeSizePropertyKey, new Vector3(0.2f, 0.3f, 0.4f));
            child.DependencyProperties.Set(PinOriginPropertyKey, new Vector3(0f, 0.5f, 1f));
            child.DependencyProperties.Set(RelativePositionPropertyKey, new Vector3(0.2f, 0.4f, 0.6f));
            Children.Add(child);

            child.ReturnedMeasuredValue = 2 * new Vector3(2, 6, 12);
            child.ExpectedArrangeValue = new Vector3(4, 12, 18);
            providedSize = new Vector3(10, 20, 30);
            Measure(providedSize);
            Arrange(providedSize, false);
            Assert.AreEqual(Matrix.Translation(2f-5f,8f-6f-10f,18f-18f-15f), child.DependencyProperties.Get(PanelArrangeMatrixPropertyKey));
        }
Esempio n. 6
0
        private void TestArrangeOverrideCore(Orientation orientation)
        {
            ResetState();

            DepthAlignment = DepthAlignment.Stretch;

            // Create and add children
            var child1 = new ArrangeValidator { DepthAlignment = DepthAlignment.Stretch };
            var child2 = new ArrangeValidator { DepthAlignment = DepthAlignment.Stretch };
            var child3 = new ArrangeValidator { DepthAlignment = DepthAlignment.Stretch };
            Children.Add(child1);
            Children.Add(child2);
            Children.Add(child3);

            // set the stack orientation
            Orientation = orientation;

            // set children margins
            Children[0].Margin = rand.NextThickness(10, 11, 12, 13, 14, 15);
            Children[1].Margin = rand.NextThickness(10, 11, 12, 13, 14, 15);
            Children[2].Margin = rand.NextThickness(10, 11, 12, 13, 14, 15);

            // set an available size
            var availablesizeWithMargins = 1000 * rand.NextVector3();
            var availableSizeWithoutMargins = CalculateSizeWithoutThickness(ref availablesizeWithMargins, ref MarginInternal);

            // set the arrange validator values
            foreach (ArrangeValidator child in Children)
            {
                child.ReturnedMeasuredValue = 1000 * rand.NextVector3();
                child.ExpectedArrangeValue = CalculateSizeWithoutThickness(ref availableSizeWithoutMargins, ref child.MarginInternal);
                child.ExpectedArrangeValue[(int)Orientation] = child.ReturnedMeasuredValue[(int)Orientation];
            }

            // Measure the stack
            Measure(availableSizeWithoutMargins);
            Arrange(availablesizeWithMargins, false);
            
            // compute the children accumulated sizes
            var acculumatedDesiredSizeWithMarginsList = new List<Vector3>();
            for (int i = 0; i < Children.Count; i++)
            {
                var accumulatedVector = Vector3.Zero;
                for (int j = 0; j < i; j++)
                {
                    for(int dim = 0; dim<3; ++dim)
                        accumulatedVector[dim] += Children[j].RenderSize[dim] + Children[j].Margin[dim] + Children[j].Margin[dim + 3];
                }

                acculumatedDesiredSizeWithMarginsList.Add(accumulatedVector);
            }

            // checks the stack arranged size
            Assert.AreEqual(availableSizeWithoutMargins, RenderSize);
            
            // Checks the children arrange matrix
            for (int i = 0; i < Children.Count; i++)
            {
                var childOffsets = -RenderSize / 2;

                switch (orientation)
                {
                    case Orientation.Horizontal:
                        childOffsets.X += acculumatedDesiredSizeWithMarginsList[i].X;
                        break;
                    case Orientation.Vertical:
                        childOffsets.Y += acculumatedDesiredSizeWithMarginsList[i].Y;
                        break;
                    case Orientation.InDepth:
                        childOffsets.Z += acculumatedDesiredSizeWithMarginsList[i].Z;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException("orientation");
                }

                Utilities.AssertAreNearlyEqual(Matrix.Translation(childOffsets), Children[i].DependencyProperties.Get(PanelArrangeMatrixPropertyKey));
            }
        }
Esempio n. 7
0
        private void TestArrangeOverrideCore(Orientation orientation)
        {
            ResetState();

            DepthAlignment = DepthAlignment.Stretch;

            // Create and add children
            var child1 = new ArrangeValidator {
                DepthAlignment = DepthAlignment.Stretch
            };
            var child2 = new ArrangeValidator {
                DepthAlignment = DepthAlignment.Stretch
            };
            var child3 = new ArrangeValidator {
                DepthAlignment = DepthAlignment.Stretch
            };

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

            // set the stack orientation
            Orientation = orientation;

            // set children margins
            Children[0].Margin = rand.NextThickness(10, 11, 12, 13, 14, 15);
            Children[1].Margin = rand.NextThickness(10, 11, 12, 13, 14, 15);
            Children[2].Margin = rand.NextThickness(10, 11, 12, 13, 14, 15);

            // set an available size
            var availablesizeWithMargins    = 1000 * rand.NextVector3();
            var availableSizeWithoutMargins = CalculateSizeWithoutThickness(ref availablesizeWithMargins, ref MarginInternal);

            // set the arrange validator values
            foreach (ArrangeValidator child in Children)
            {
                child.ReturnedMeasuredValue = 1000 * rand.NextVector3();
                child.ExpectedArrangeValue  = CalculateSizeWithoutThickness(ref availableSizeWithoutMargins, ref child.MarginInternal);
                child.ExpectedArrangeValue[(int)Orientation] = child.ReturnedMeasuredValue[(int)Orientation];
            }

            // Measure the stack
            Measure(availableSizeWithoutMargins);
            Arrange(availablesizeWithMargins, false);

            // compute the children accumulated sizes
            var acculumatedDesiredSizeWithMarginsList = new List <Vector3>();

            for (int i = 0; i < Children.Count; i++)
            {
                var accumulatedVector = Vector3.Zero;
                for (int j = 0; j < i; j++)
                {
                    for (int dim = 0; dim < 3; ++dim)
                    {
                        accumulatedVector[dim] += Children[j].RenderSize[dim] + Children[j].Margin[dim] + Children[j].Margin[dim + 3];
                    }
                }

                acculumatedDesiredSizeWithMarginsList.Add(accumulatedVector);
            }

            // checks the stack arranged size
            Assert.AreEqual(availableSizeWithoutMargins, RenderSize);

            // Checks the children arrange matrix
            for (int i = 0; i < Children.Count; i++)
            {
                var childOffsets = -RenderSize / 2;

                switch (orientation)
                {
                case Orientation.Horizontal:
                    childOffsets.X += acculumatedDesiredSizeWithMarginsList[i].X;
                    break;

                case Orientation.Vertical:
                    childOffsets.Y += acculumatedDesiredSizeWithMarginsList[i].Y;
                    break;

                case Orientation.InDepth:
                    childOffsets.Z += acculumatedDesiredSizeWithMarginsList[i].Z;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("orientation");
                }

                Assert.AreEqual(Matrix.Translation(childOffsets), Children[i].DependencyProperties.Get(PanelArrangeMatrixPropertyKey));
            }
        }
Esempio n. 8
0
        public void TestArrangeOverride()
        {
            ResetState();

            DepthAlignment = DepthAlignment.Stretch;

            // Test that returned value is the one provided when no content
            var providedSize = 1000 * rand.NextVector3();
            var arrangedSize = ArrangeOverride(providedSize);
            Assert.AreEqual(providedSize, arrangedSize);

            ResetState();

            // Test arrange with some content
            providedSize = 1000 * rand.NextVector3();
            var content = new ArrangeValidator { DepthAlignment = DepthAlignment.Stretch };
            Content = content;
            Padding = rand.NextThickness(10, 20, 30, 40, 50, 60);
            var providedSizeWithoutPadding = CalculateSizeWithoutThickness(ref providedSize, ref padding);
            content.ExpectedArrangeValue = providedSizeWithoutPadding;
            arrangedSize = ArrangeOverride(providedSize);
            Assert.AreEqual(providedSize, arrangedSize);
            var childOffsets = new Vector3(Padding.Left, Padding.Top, Padding.Front) - arrangedSize / 2;
            Assert.AreEqual(Matrix.Translation(childOffsets), VisualContent.DependencyProperties.Get(ContentArrangeMatrixPropertyKey));
        }