Beispiel #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));
        }
        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(UseAbsolutePositionPropertyKey, false);
            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  = child.ReturnedMeasuredValue;
            providedSize = new Vector3(10, 20, 30);
            Measure(providedSize);
            Arrange(providedSize, false);
            Assert.AreEqual(Matrix.Translation(2f - 5f, 8f - 6f - 10f, 18f - 24f - 15f), child.DependencyProperties.Get(PanelArrangeMatrixPropertyKey));
        }
Beispiel #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));
            }
        }
Beispiel #4
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));
            }
        }
Beispiel #5
0
        public void TestAutoOnlyMinMaxLayering()
        {
            //  min = 20                                                      min = 20
            //                                 max = 20             max = 20  max = 20
            // 0         20        40         60        80        100        120      140
            // +---------+---------+----------+---------+---------+----------+--------+
            // |<-c00->  |<--c01-->|                    |<-c04->  |<----c05--|-->     |
            // +---------+---------+----------+---------+---------+----------+--------+
            // |<-------c10------->|                    |         |          |<-c16-> |
            // +---------+---------+----------+---------+---------+----------+--------+
            // |         |<----------c21-------->       |         |          |<---c26-|-->
            // +---------+---------+----------+---------+---------+----------+--------|
            // |         |         |<-------c32-------->|         |          |        |
            // +---------+---------+----------+---------+---------+----------+--------+
            // |         |         |          |         |<------------c44------------>|
            // +---------+---------+----------+---------+---------+----------+--------+

            var grid = new Grid();

            // set the grid definition
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto) { MinimumSize = 20 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto) { MaximumSize = 20 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto) { MaximumSize = 20 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto) { MaximumSize = 20, MinimumSize = 20 });
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));

            // create the children
            var c00 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(10, 0, 0), ExpectedArrangeValue = new Vector3(20, 0, 0), Name = "c00" };
            var c01 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(20, 0, 0), ExpectedArrangeValue = new Vector3(20, 0, 0), Name = "c01" };
            var c04 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(10, 0, 0), ExpectedArrangeValue = new Vector3(20, 0, 0), Name = "c03" };
            var c05 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(30, 0, 0), ExpectedArrangeValue = new Vector3(20, 0, 0), Name = "c04" };
            var c10 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(40, 0, 0), ExpectedArrangeValue = new Vector3(40, 0, 0), Name = "c10" };
            var c16 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(10, 0, 0), ExpectedArrangeValue = new Vector3(20, 0, 0), Name = "c15" };
            var c21 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(50, 0, 0), ExpectedArrangeValue = new Vector3(60, 0, 0), Name = "c21" };
            var c26 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(30, 0, 0), ExpectedArrangeValue = new Vector3(20, 0, 0), Name = "c25" };
            var c32 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(40, 0, 0), ExpectedArrangeValue = new Vector3(40, 0, 0), Name = "c32" };
            var c44 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(60, 0, 0), ExpectedArrangeValue = new Vector3(60, 0, 0), Name = "c44" };

            // set the spans 
            c10.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);
            c21.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 3);
            c32.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);
            c44.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 3);

            // set the positions
            c01.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            c04.DependencyProperties.Set(GridBase.ColumnPropertyKey, 4);
            c05.DependencyProperties.Set(GridBase.ColumnPropertyKey, 5);
            c10.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            c16.DependencyProperties.Set(GridBase.ColumnPropertyKey, 6);
            c16.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            c21.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            c21.DependencyProperties.Set(GridBase.RowPropertyKey, 2);
            c26.DependencyProperties.Set(GridBase.ColumnPropertyKey, 6);
            c26.DependencyProperties.Set(GridBase.RowPropertyKey, 2);
            c32.DependencyProperties.Set(GridBase.ColumnPropertyKey, 2);
            c32.DependencyProperties.Set(GridBase.RowPropertyKey, 3);
            c44.DependencyProperties.Set(GridBase.ColumnPropertyKey, 4);
            c44.DependencyProperties.Set(GridBase.RowPropertyKey, 4);

            // add the children
            grid.Children.Add(c00);
            grid.Children.Add(c01);
            grid.Children.Add(c04);
            grid.Children.Add(c05);
            grid.Children.Add(c10);
            grid.Children.Add(c16);
            grid.Children.Add(c21);
            grid.Children.Add(c26);
            grid.Children.Add(c32);
            grid.Children.Add(c44);

            grid.Measure(30 * rand.NextVector3());
            Assert.AreEqual(new Vector3(140, 0, 0), grid.DesiredSizeWithMargins);

            grid.Arrange(100 * rand.NextVector3(), false);

            Assert.AreEqual(20, grid.ColumnDefinitions[0].ActualSize);
            Assert.AreEqual(20, grid.ColumnDefinitions[1].ActualSize);
            Assert.AreEqual(20, grid.ColumnDefinitions[2].ActualSize);
            Assert.AreEqual(20, grid.ColumnDefinitions[3].ActualSize);
            Assert.AreEqual(20, grid.ColumnDefinitions[4].ActualSize);
            Assert.AreEqual(20, grid.ColumnDefinitions[5].ActualSize);
            Assert.AreEqual(20, grid.ColumnDefinitions[6].ActualSize);
        }
Beispiel #6
0
        public void TestAutoOnlyMultiSpanLayering()
        {
            // 0       10          40                70
            // +-------+-----------+-----------------+
            // |<-c00->|<--c01-->  |                 |
            // +-------+-----------+-----------------+
            // |<-------c10------->|<---c12--->      |
            // +-------+-----------+-----------------+
            // |       |<-----------c21---------->   |
            // +-------+-----------+-----------------+
            // |<-----------------c30--------------->|
            // +-------+-----------+-----------------+

            var grid = new Grid();

            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));

            var c00 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(10, 0, 0), ExpectedArrangeValue = new Vector3(10, 0, 0) };
            var c01 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(20, 0, 0), ExpectedArrangeValue = new Vector3(30, 0, 0) };
            var c10 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(40, 0, 0), ExpectedArrangeValue = new Vector3(40, 0, 0) };
            var c12 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(10, 0, 0), ExpectedArrangeValue = new Vector3(30, 0, 0) };
            var c21 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(30, 0, 0), ExpectedArrangeValue = new Vector3(60, 0, 0) };
            var c30 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(70, 0, 0), ExpectedArrangeValue = new Vector3(70, 0, 0) };

            // set the spans 
            c10.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);
            c21.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);
            c30.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 3);

            // set the positions
            c01.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            c10.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            c12.DependencyProperties.Set(GridBase.ColumnPropertyKey, 2);
            c12.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            c21.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            c21.DependencyProperties.Set(GridBase.RowPropertyKey, 2);
            c30.DependencyProperties.Set(GridBase.RowPropertyKey, 3);

            // add the children
            grid.Children.Add(c00);
            grid.Children.Add(c01);
            grid.Children.Add(c10);
            grid.Children.Add(c12);
            grid.Children.Add(c21);
            grid.Children.Add(c30);

            grid.Measure(30 * rand.NextVector3());
            Assert.AreEqual(new Vector3(70, 0, 0), grid.DesiredSizeWithMargins);

            grid.Arrange(50 * rand.NextVector3(), false);

            Assert.AreEqual(10, grid.ColumnDefinitions[0].ActualSize);
            Assert.AreEqual(30, grid.ColumnDefinitions[1].ActualSize);
            Assert.AreEqual(30, grid.ColumnDefinitions[2].ActualSize);
        }
Beispiel #7
0
        public void TestAutoOnlyBasicLayering()
        {
            // 0       10          40            80
            // +-------+-----------+-------------+
            // |<-c00->|<--c01-->  |             |
            // +-------+-----------+-------------+
            // |       |<---c11--->|<----c12---->|
            // +-------+-----------+-------------+

            var grid = new Grid();

            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));

            var c00 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(10, 0, 0), ExpectedArrangeValue = new Vector3(10, 0, 0) };
            var c01 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(20, 0, 0), ExpectedArrangeValue = new Vector3(30, 0, 0) };
            var c11 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(30, 0, 0), ExpectedArrangeValue = new Vector3(30, 0, 0) };
            var c12 = new ArrangeValidator { ReturnedMeasuredValue = new Vector3(40, 0, 0), ExpectedArrangeValue = new Vector3(40, 0, 0) };

            c00.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);
            c00.DependencyProperties.Set(GridBase.RowPropertyKey, 0);

            c01.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            c01.DependencyProperties.Set(GridBase.RowPropertyKey, 0);

            c11.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            c11.DependencyProperties.Set(GridBase.RowPropertyKey, 1);

            c12.DependencyProperties.Set(GridBase.ColumnPropertyKey, 2);
            c12.DependencyProperties.Set(GridBase.RowPropertyKey, 1);

            grid.Children.Add(c00);
            grid.Children.Add(c01);
            grid.Children.Add(c11);
            grid.Children.Add(c12);

            grid.Measure(30 * rand.NextVector3());
            Assert.AreEqual(new Vector3(80,0,0), grid.DesiredSizeWithMargins);

            grid.Arrange(30 * rand.NextVector3(), false);

            Assert.AreEqual(10, grid.ColumnDefinitions[0].ActualSize);
            Assert.AreEqual(30, grid.ColumnDefinitions[1].ActualSize);
            Assert.AreEqual(40, grid.ColumnDefinitions[2].ActualSize);
        }
Beispiel #8
0
        public void TestBasicMultiTypeLayering()
        {
            var grid = new Grid();
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 30));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));

            // 0     30     30     auto     60     1*     100
            // +-------------+--------------+-------------+
            // |<---c00--->  |<----c01----->|             |
            // +-------------+--------------+-------------+
            // |             |<-------------c11---------->|
            // +-------------+--------------+-------------+

            var c00 = new ArrangeValidator { Name = "c00", ReturnedMeasuredValue = new Vector3(20, 0, 0), ExpectedArrangeValue = new Vector3(30, 0, 0) };
            var c01 = new ArrangeValidator { Name = "c01", ReturnedMeasuredValue = new Vector3(30, 0, 0), ExpectedArrangeValue = new Vector3(30, 0, 0) };
            var c11 = new ArrangeValidator { Name = "c11", ReturnedMeasuredValue = new Vector3(70, 0, 0), ExpectedArrangeValue = new Vector3(80, 0, 0) };

            c01.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            c11.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            c11.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            c11.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);

            grid.Children.Add(c00);
            grid.Children.Add(c01);
            grid.Children.Add(c11);

            grid.Measure(50 * rand.NextVector3());
            Assert.AreEqual(new Vector3(100, 0, 0), grid.DesiredSizeWithMargins);

            grid.Arrange(110 * Vector3.One, false);
            Assert.AreEqual(30, grid.ColumnDefinitions[0].ActualSize);
            Assert.AreEqual(30, grid.ColumnDefinitions[1].ActualSize);
            Assert.AreEqual(50, grid.ColumnDefinitions[2].ActualSize);
        }
Beispiel #9
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));
            }
        }
Beispiel #10
0
        public void TestStarOnlyMultiMinLayering1()
        {
            var grid = new Grid();
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 10) { MinimumSize = 20 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 20) { MinimumSize = 30 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 30) { MinimumSize = 40 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 40) { MinimumSize = 50 });
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));

            //    min = 20    min = 30  min = 40  min = 50
            // 0    10*    20   20*   50        90       140
            // +-----------+----------+---------+--------+
            // |<---------------c00--------------->      |
            // +---- ------+----------+---------+--------+

            var c00 = new ArrangeValidator { Name = "c00", ReturnedMeasuredValue = new Vector3(25, 0, 0), ExpectedArrangeValue = new Vector3(140, 0, 0) };
            c00.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 4);
            grid.Children.Add(c00);

            grid.Measure(50 * rand.NextVector3());
            Assert.AreEqual(new Vector3(140, 0, 0), grid.DesiredSizeWithMargins);

            grid.Arrange(50 * Vector3.One, false);
            Assert.AreEqual(20, grid.ColumnDefinitions[0].ActualSize);
            Assert.AreEqual(30, grid.ColumnDefinitions[1].ActualSize);
            Assert.AreEqual(40, grid.ColumnDefinitions[2].ActualSize);
            Assert.AreEqual(50, grid.ColumnDefinitions[3].ActualSize);
        }
Beispiel #11
0
        public void TestStarOnlyMax2EltsLayering3()
        {
            var grid = new Grid();
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 10) { MaximumSize = 40 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 20) { MaximumSize = 50 });
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));

            //    max = 40   max = 50
            // 0    10*    20   20*   50
            // +-----------+----------+
            // |<---c00--->|<--c01--> |           
            // +-----------+----------+

            var c00 = new ArrangeValidator { Name = "c00", ReturnedMeasuredValue = new Vector3(15, 0, 0), ExpectedArrangeValue = new Vector3(20, 0, 0) };
            var c01 = new ArrangeValidator { Name = "c01", ReturnedMeasuredValue = new Vector3(25, 0, 0), ExpectedArrangeValue = new Vector3(40, 0, 0) };

            c01.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);

            grid.Children.Add(c00);
            grid.Children.Add(c01);

            grid.Measure(50 * rand.NextVector3());
            Assert.AreEqual(new Vector3(45, 0, 0), grid.DesiredSizeWithMargins);

            grid.Arrange(60 * Vector3.One, false);
            Assert.AreEqual(20, grid.ColumnDefinitions[0].ActualSize);
            Assert.AreEqual(40, grid.ColumnDefinitions[1].ActualSize);
        }
Beispiel #12
0
        public void TestStarOnlyMax1EltLayering()
        {
            var grid = new Grid();
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 10) { MaximumSize = 20 });
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));

            //    max = 20
            // 0    10*   20   
            // +----------+
            // |<----c00--|-->
            // +----------+

            var c00 = new ArrangeValidator { Name = "c00", ReturnedMeasuredValue = new Vector3(30, 0, 0), ExpectedArrangeValue = new Vector3(20, 0, 0) };
            grid.Children.Add(c00);

            grid.Measure(50 * rand.NextVector3());
            Assert.AreEqual(new Vector3(20, 0, 0), grid.DesiredSizeWithMargins);

            grid.Arrange(40 * Vector3.One, false);
            Assert.AreEqual(20, grid.ColumnDefinitions[0].ActualSize);
        }
Beispiel #13
0
        public void TestStarOnlyMultiSpanLayering()
        {
            // 0      30*     30     20*    50    10*    60
            // +--------------+--------------+-----------+
            // |<-c00->       |<--c01-->     |<--c02-->  |
            // +--------------+--------------+-----------+
            // |              |<----------c11----------->|
            // +--------------+--------------+-----------+
            // |<---------------c20---------------->     |
            // +--------------+--------------+-----------+

            var grid = new Grid();
            var ratios = new List<float> { 30, 20, 10 };

            grid.ColumnDefinitions.Clear();
            foreach (var ratio in ratios)
                grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, ratio));

            var c00 = new ArrangeValidator { Name = "c00", ReturnedMeasuredValue = new Vector3(20, 0, 0), ExpectedArrangeValue = new Vector3(60, 0, 0) };
            var c01 = new ArrangeValidator { Name = "c01", ReturnedMeasuredValue = new Vector3(15, 0, 0), ExpectedArrangeValue = new Vector3(40, 0, 0) };
            var c02 = new ArrangeValidator { Name = "c02", ReturnedMeasuredValue = new Vector3( 8, 0, 0), ExpectedArrangeValue = new Vector3(20, 0, 0) };
            var c11 = new ArrangeValidator { Name = "c11", ReturnedMeasuredValue = new Vector3(30, 0, 0), ExpectedArrangeValue = new Vector3(60, 0, 0) };
            var c20 = new ArrangeValidator { Name = "c20", ReturnedMeasuredValue = new Vector3(55, 0, 0), ExpectedArrangeValue = new Vector3(120, 0, 0) };
            
            c11.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 2);
            c20.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 3);

            c01.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            c02.DependencyProperties.Set(GridBase.ColumnPropertyKey, 2);
            c11.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            c11.DependencyProperties.Set(GridBase.RowPropertyKey, 1);
            c20.DependencyProperties.Set(GridBase.RowPropertyKey, 2);

            grid.Children.Add(c00);
            grid.Children.Add(c01);
            grid.Children.Add(c02);
            grid.Children.Add(c11);
            grid.Children.Add(c20);

            grid.Measure(50 * rand.NextVector3());
            Assert.AreEqual(new Vector3(60, 0, 0), grid.DesiredSizeWithMargins);

            grid.Arrange(2 * grid.DesiredSizeWithMargins, false);

            for (int i = 0; i < ratios.Count; i++)
                Assert.AreEqual(2 * ratios[i], grid.ColumnDefinitions[i].ActualSize);
        }
Beispiel #14
0
        public void TestMeasureProvidedSizeMix()
        {
            var grid = new Grid();

            var providedSize = 100 * Vector3.One;

            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 4));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star, 6));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 10));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Fixed, 15));
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Auto));

            var child0 = new MeasureReflector { Name = "0", };
            var child1 = new MeasureReflector { Name = "1", };
            var child2 = new MeasureReflector { Name = "2", };
            var child3 = new ArrangeValidator { Name = "3", ReturnedMeasuredValue = new Vector3(5, providedSize.Y, providedSize.Z) };
            var child4 = new MeasureReflector { Name = "4", };
            var child5 = new ArrangeValidator { Name = "5", ReturnedMeasuredValue = new Vector3(20, providedSize.Y, providedSize.Z)};

            child0.DependencyProperties.Set(GridBase.ColumnPropertyKey, 0);
            child1.DependencyProperties.Set(GridBase.ColumnPropertyKey, 1);
            child2.DependencyProperties.Set(GridBase.ColumnPropertyKey, 2);
            child3.DependencyProperties.Set(GridBase.ColumnPropertyKey, 3);
            child4.DependencyProperties.Set(GridBase.ColumnPropertyKey, 4);
            child5.DependencyProperties.Set(GridBase.ColumnPropertyKey, 5);

            grid.Children.Add(child0);
            grid.Children.Add(child1);
            grid.Children.Add(child2);
            grid.Children.Add(child3);
            grid.Children.Add(child4);
            grid.Children.Add(child5);

            grid.Measure(providedSize);

            Utilities.AssertAreNearlyEqual(20, child0.DesiredSize.X);
            Utilities.AssertAreNearlyEqual(30, child1.DesiredSize.X);
            Utilities.AssertAreNearlyEqual(10, child2.DesiredSize.X);
            Utilities.AssertAreNearlyEqual(5, child3.DesiredSize.X);
            Utilities.AssertAreNearlyEqual(15, child4.DesiredSize.X);
            Utilities.AssertAreNearlyEqual(20, child5.DesiredSize.X);
        }
        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));
        }
Beispiel #16
0
        public void TestStarOnlyMultiMaxLayering2()
        {
            var grid = new Grid();
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star) { MaximumSize = 20 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star) { MaximumSize = 50 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star) { MaximumSize = 40 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star) { MaximumSize = 30 });
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));

            // |<---max 20-->|<---max 50----|<->---max 40-|<->-max 30-->|
            // 0      1*     20     1*      75     1*     115    1*     140
            // +-------------+--------------+-------------+-------------+
            // |<-------------------------c00-------------------------->|
            // +-------------+--------------+-------------+-------------+

            var c00 = new ArrangeValidator { Name = "c00", ReturnedMeasuredValue = new Vector3(110, 0, 0), ExpectedArrangeValue = new Vector3(110, 0, 0) };
            c00.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 4);
            grid.Children.Add(c00);

            grid.Measure(50 * rand.NextVector3());
            Assert.AreEqual(new Vector3(110, 0, 0), grid.DesiredSizeWithMargins);

            grid.Arrange(110 * Vector3.One, false);
            Assert.AreEqual(20, grid.ColumnDefinitions[0].ActualSize);
            Assert.AreEqual(30, grid.ColumnDefinitions[1].ActualSize);
            Assert.AreEqual(30, grid.ColumnDefinitions[2].ActualSize);
            Assert.AreEqual(30, grid.ColumnDefinitions[3].ActualSize);
        }
Beispiel #17
0
        public void TestStarOnlyMinMaxLayering2()
        {
            var grid = new Grid();
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star) { MinimumSize = 10, MaximumSize = 70 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star) { MinimumSize = 20, MaximumSize = 35 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star) { MinimumSize = 30, MaximumSize = 55 });
            grid.ColumnDefinitions.Add(new StripDefinition(StripType.Star) { MinimumSize = 40, MaximumSize = 45 });
            grid.RowDefinitions.Add(new StripDefinition(StripType.Auto));

            // |<--min 10->  |<---min 20->  |<---min 30-> |<--min 40->|
            // |<---max 70---|<-->-max 35-->|<---max 55-->|<---max 45-->|
            // 0      1*     20     1*      55     1*     95     1*     145
            // +-------------+--------------+-------------+-------------+
            // |<-------------------------c00-------------------------->|
            // +-------------+--------------+-------------+-------------+

            var c00 = new ArrangeValidator { Name = "c00", ReturnedMeasuredValue = new Vector3(195, 0, 0), ExpectedArrangeValue = new Vector3(195, 0, 0) };
            c00.DependencyProperties.Set(GridBase.ColumnSpanPropertyKey, 4);
            grid.Children.Add(c00);

            grid.Measure(50 * rand.NextVector3());
            Assert.AreEqual(new Vector3(195, 0, 0), grid.DesiredSizeWithMargins);

            grid.Arrange(195 * Vector3.One, false);
            Assert.AreEqual(60, grid.ColumnDefinitions[0].ActualSize);
            Assert.AreEqual(35, grid.ColumnDefinitions[1].ActualSize);
            Assert.AreEqual(55, grid.ColumnDefinitions[2].ActualSize);
            Assert.AreEqual(45, grid.ColumnDefinitions[3].ActualSize);
        }
Beispiel #18
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(nameof(orientation));
                }

                Utilities.AssertAreNearlyEqual(Matrix.Translation(childOffsets), Children[i].DependencyProperties.Get(PanelArrangeMatrixPropertyKey));
            }
        }
Beispiel #19
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));
        }