예제 #1
0
파일: CanvasTests.cs 프로젝트: cg123/xenko
        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);
        }
예제 #2
0
파일: CanvasTests.cs 프로젝트: cg123/xenko
        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));
            }
        }