コード例 #1
0
ファイル: CanvasTests.cs プロジェクト: vvvv/stride
        public void TestMeasureOverrideRelative()
        {
            ResetState();

            // check that desired size is null if no children
            Measure(1000 * rand.NextVector3());
            Assert.Equal(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.Equal(Vector3.Zero, DesiredSize);
        }
コード例 #2
0
        public void TestMeasureOverrideAbsolute()
        {
            ResetState();

            // check that desired size is null if no children
            Measure(1000 * rand.NextVector3());
            Assert.Equal(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.Equal(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.Equal(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.Equal(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.Equal(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.Equal(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.Equal(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.Equal(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.Equal(Vector3.Zero, canvas.DesiredSizeWithMargins);
        }