Пример #1
0
        public void TestSurroudingAnchor()
        {
            var stackSize = new Vector3(100, 200, 300);

            var stackPanel = new PanelTests {
                Size = stackSize
            };

            stackPanel.Arrange(Vector3.Zero, false);

            Assert.Equal(new Vector2(0, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, -1f));
            Assert.Equal(new Vector2(0, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 0));
            Assert.Equal(new Vector2(-20, 80), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 20));
            Assert.Equal(new Vector2(-100, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 100));
            Assert.Equal(new Vector2(-100, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 150));

            Assert.Equal(new Vector2(0, 200), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, -1f));
            Assert.Equal(new Vector2(0, 200), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 0));
            Assert.Equal(new Vector2(-100, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 100));
            Assert.Equal(new Vector2(-200, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 200));
            Assert.Equal(new Vector2(-200, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 220));

            Assert.Equal(new Vector2(0, 300), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, -1f));
            Assert.Equal(new Vector2(0, 300), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 0));
            Assert.Equal(new Vector2(-200, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 200));
            Assert.Equal(new Vector2(-300, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 300));
            Assert.Equal(new Vector2(-300, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 330));
        }
Пример #2
0
        public void TestChildrenManagement()
        {
            ResetState();

            // Check that parent is added to child
            var newChild = new PanelTests {
                Name = "child 1"
            };

            Assert.Null(newChild.Parent);
            Children.Add(newChild);
            Assert.Equal(this, newChild.Parent);

            // check that parent is removed from child
            Children.Remove(newChild);
            Assert.Null(newChild.Parent);

            // check that adding or removing a child invalidate the measure
            Measure(Vector3.Zero);
            Children.Add(newChild);
            Assert.False(IsMeasureValid);
            Measure(Vector3.Zero);
            Children.Remove(newChild);
            Assert.False(IsMeasureValid);

            // test that children are correctly ordered by Z
            var newChild2 = new PanelTests {
                Name = "child 2"
            };

            newChild2.DependencyProperties.Set(ZIndexPropertyKey, 2);
            Children.Add(newChild2);
            Children.Add(newChild);
            Assert.Equal(2, VisualChildrenCollection.Count);
            Assert.Equal(newChild, VisualChildrenCollection[0]);
            Assert.Equal(newChild2, VisualChildrenCollection[1]);
            newChild.DependencyProperties.Set(ZIndexPropertyKey, 3);
            Assert.Equal(2, VisualChildrenCollection.Count);
            Assert.Equal(newChild2, VisualChildrenCollection[0]);
            Assert.Equal(newChild, VisualChildrenCollection[1]);
            Children.Remove(newChild);
            Assert.Single(VisualChildrenCollection);
            Assert.Equal(newChild2, VisualChildrenCollection[0]);
            Children.Remove(newChild2);
            Assert.Empty(VisualChildrenCollection);
        }
Пример #3
0
        public void TestUpdateWorldMatrix()
        {
            ResetState();

            DepthAlignment = DepthAlignment.Stretch;

            // set the panel size to 1
            Arrange(Vector3.One, false);

            // test that the world matrix of the panel is correctly updated.
            var localMatrix = Matrix.Scaling(0.1f, 0.5f, 1f);
            var worldMatrix = Matrix.Scaling(1f, 0.8f, 0.4f);

            LocalMatrix = localMatrix;
            UpdateWorldMatrix(ref worldMatrix, true);
            Assert.Equal(new Matrix(0.1f, 0, 0, 0, 0, 0.4f, 0, 0, 0, 0, 0.4f, 0, 0.5f, 0.4f, 0.2f, 1), WorldMatrix);

            // add a child and set its local matrix
            var child = new PanelTests {
                DepthAlignment = DepthAlignment.Stretch
            };
            var childArrangementMatrix = Matrix.Translation(10, 20, 30);
            var childLocalMatrix       = new Matrix(0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);

            child.LocalMatrix = childLocalMatrix;
            Children.Add(child);

            // set the child's panel arrangement matrix
            child.DependencyProperties.Set(PanelArrangeMatrixPropertyKey, childArrangementMatrix);

            // arrange the child (set its size to 1)
            child.Arrange(Vector3.One, false);

            // check that the value of the world matrix of the child is correctly updated too
            UpdateWorldMatrix(ref worldMatrix, true);
            Assert.Equal(new Matrix(0, -0.4f, 0, 0, 0.1f, 0, 0, 0, 0, 0, 0.4f, 0, 1.55f, 8.6f, 12.4f, 1), child.WorldMatrix);
        }
Пример #4
0
        public void TestShouldAnchor()
        {
            var panel = new PanelTests();

            // default state
            Assert.True(panel.ShouldAnchor(Orientation.Horizontal));
            Assert.True(panel.ShouldAnchor(Orientation.Vertical));
            Assert.True(panel.ShouldAnchor(Orientation.InDepth));

            // horizontally
            panel.ActivateAnchoring(Orientation.Horizontal, false);

            Assert.False(panel.ShouldAnchor(Orientation.Horizontal));
            Assert.True(panel.ShouldAnchor(Orientation.Vertical));
            Assert.True(panel.ShouldAnchor(Orientation.InDepth));

            panel.ActivateAnchoring(Orientation.Horizontal, true);

            Assert.True(panel.ShouldAnchor(Orientation.Horizontal));
            Assert.True(panel.ShouldAnchor(Orientation.Vertical));
            Assert.True(panel.ShouldAnchor(Orientation.InDepth));

            // vertically
            panel.ActivateAnchoring(Orientation.Vertical, false);

            Assert.True(panel.ShouldAnchor(Orientation.Horizontal));
            Assert.False(panel.ShouldAnchor(Orientation.Vertical));
            Assert.True(panel.ShouldAnchor(Orientation.InDepth));

            panel.ActivateAnchoring(Orientation.Vertical, true);

            Assert.True(panel.ShouldAnchor(Orientation.Horizontal));
            Assert.True(panel.ShouldAnchor(Orientation.Vertical));
            Assert.True(panel.ShouldAnchor(Orientation.InDepth));

            // in depth
            panel.ActivateAnchoring(Orientation.InDepth, false);

            Assert.True(panel.ShouldAnchor(Orientation.Horizontal));
            Assert.True(panel.ShouldAnchor(Orientation.Vertical));
            Assert.False(panel.ShouldAnchor(Orientation.InDepth));

            panel.ActivateAnchoring(Orientation.InDepth, true);

            Assert.True(panel.ShouldAnchor(Orientation.Horizontal));
            Assert.True(panel.ShouldAnchor(Orientation.Vertical));
            Assert.True(panel.ShouldAnchor(Orientation.InDepth));

            // combination
            panel.ActivateAnchoring(Orientation.Horizontal, false);
            panel.ActivateAnchoring(Orientation.Vertical, false);
            panel.ActivateAnchoring(Orientation.InDepth, false);

            Assert.False(panel.ShouldAnchor(Orientation.Horizontal));
            Assert.False(panel.ShouldAnchor(Orientation.Vertical));
            Assert.False(panel.ShouldAnchor(Orientation.InDepth));

            panel.ActivateAnchoring(Orientation.Horizontal, true);
            panel.ActivateAnchoring(Orientation.Vertical, true);
            panel.ActivateAnchoring(Orientation.InDepth, true);

            Assert.True(panel.ShouldAnchor(Orientation.Horizontal));
            Assert.True(panel.ShouldAnchor(Orientation.Vertical));
            Assert.True(panel.ShouldAnchor(Orientation.InDepth));
        }