public void TestSurroudingAnchor() { var stackSize = new Vector3(100, 200, 300); var stackPanel = new PanelTests { Size = stackSize }; stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(new Vector2(0, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, -1f)); Assert.AreEqual(new Vector2(0, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 0)); Assert.AreEqual(new Vector2(-20, 80), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 20)); Assert.AreEqual(new Vector2(-100, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 100)); Assert.AreEqual(new Vector2(-100, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 150)); Assert.AreEqual(new Vector2(0, 200), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, -1f)); Assert.AreEqual(new Vector2(0, 200), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 0)); Assert.AreEqual(new Vector2(-100, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 100)); Assert.AreEqual(new Vector2(-200, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 200)); Assert.AreEqual(new Vector2(-200, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 220)); Assert.AreEqual(new Vector2(0, 300), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, -1f)); Assert.AreEqual(new Vector2(0, 300), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 0)); Assert.AreEqual(new Vector2(-200, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 200)); Assert.AreEqual(new Vector2(-300, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 300)); Assert.AreEqual(new Vector2(-300, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 330)); }
public static void Main() { var uiElementTest = new UIElementLayeringTests(); uiElementTest.TestAll(); var panelTest = new PanelTests(); panelTest.TestAll(); var controlTest = new ControlTests(); controlTest.TestAll(); var stackPanelTest = new StackPanelTests(); stackPanelTest.TestAll(); var canvasTest = new CanvasTests(); canvasTest.TestAll(); var contentControlTest = new ContentControlTest(); contentControlTest.TestAll(); var eventManagerTest = new EventManagerTests(); eventManagerTest.TestAll(); var routedEventArgTest = new RoutedEventArgsTest(); routedEventArgTest.TestAll(); var uiElementEventTest = new UIElementEventTests(); uiElementEventTest.TestAll(); var gridTest = new GridTests(); gridTest.TestAll(); }
public void TestChildrenManagement() { ResetState(); // Check that parent is added to child var newChild = new PanelTests { Name = "child 1" }; Assert.AreEqual(null, newChild.Parent); Children.Add(newChild); Assert.AreEqual(this, newChild.Parent); // check that parent is removed from child Children.Remove(newChild); Assert.AreEqual(null, newChild.Parent); // check that adding or removing a child invalidate the measure Measure(Vector3.Zero); Children.Add(newChild); Assert.AreEqual(false, IsMeasureValid); Measure(Vector3.Zero); Children.Remove(newChild); Assert.AreEqual(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.AreEqual(VisualChildrenCollection.Count, 2); Assert.AreEqual(newChild, VisualChildrenCollection[0]); Assert.AreEqual(newChild2, VisualChildrenCollection[1]); newChild.DependencyProperties.Set(ZIndexPropertyKey, 3); Assert.AreEqual(VisualChildrenCollection.Count, 2); Assert.AreEqual(newChild2, VisualChildrenCollection[0]); Assert.AreEqual(newChild, VisualChildrenCollection[1]); Children.Remove(newChild); Assert.AreEqual(VisualChildrenCollection.Count, 1); Assert.AreEqual(newChild2, VisualChildrenCollection[0]); Children.Remove(newChild2); Assert.AreEqual(VisualChildrenCollection.Count, 0); }
public void TestChildrenManagement() { ResetState(); // Check that parent is added to child var newChild = new PanelTests { Name = "child 1"}; Assert.AreEqual(null, newChild.Parent); Children.Add(newChild); Assert.AreEqual(this, newChild.Parent); // check that parent is removed from child Children.Remove(newChild); Assert.AreEqual(null, newChild.Parent); // check that adding or removing a child invalidate the measure Measure(Vector3.Zero); Children.Add(newChild); Assert.AreEqual(false, IsMeasureValid); Measure(Vector3.Zero); Children.Remove(newChild); Assert.AreEqual(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.AreEqual(VisualChildrenCollection.Count, 2); Assert.AreEqual(newChild, VisualChildrenCollection[0]); Assert.AreEqual(newChild2, VisualChildrenCollection[1]); newChild.DependencyProperties.Set(ZIndexPropertyKey, 3); Assert.AreEqual(VisualChildrenCollection.Count, 2); Assert.AreEqual(newChild2, VisualChildrenCollection[0]); Assert.AreEqual(newChild, VisualChildrenCollection[1]); Children.Remove(newChild); Assert.AreEqual(VisualChildrenCollection.Count, 1); Assert.AreEqual(newChild2, VisualChildrenCollection[0]); Children.Remove(newChild2); Assert.AreEqual(VisualChildrenCollection.Count, 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.AreEqual(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.AreEqual(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); }
public void TestShouldAnchor() { var panel = new PanelTests(); // default state Assert.IsTrue(panel.ShouldAnchor(Orientation.Horizontal)); Assert.IsTrue(panel.ShouldAnchor(Orientation.Vertical)); Assert.IsTrue(panel.ShouldAnchor(Orientation.InDepth)); // horizontally panel.ActivateAnchoring(Orientation.Horizontal, false); Assert.IsFalse(panel.ShouldAnchor(Orientation.Horizontal)); Assert.IsTrue(panel.ShouldAnchor(Orientation.Vertical)); Assert.IsTrue(panel.ShouldAnchor(Orientation.InDepth)); panel.ActivateAnchoring(Orientation.Horizontal, true); Assert.IsTrue(panel.ShouldAnchor(Orientation.Horizontal)); Assert.IsTrue(panel.ShouldAnchor(Orientation.Vertical)); Assert.IsTrue(panel.ShouldAnchor(Orientation.InDepth)); // vertically panel.ActivateAnchoring(Orientation.Vertical, false); Assert.IsTrue(panel.ShouldAnchor(Orientation.Horizontal)); Assert.IsFalse(panel.ShouldAnchor(Orientation.Vertical)); Assert.IsTrue(panel.ShouldAnchor(Orientation.InDepth)); panel.ActivateAnchoring(Orientation.Vertical, true); Assert.IsTrue(panel.ShouldAnchor(Orientation.Horizontal)); Assert.IsTrue(panel.ShouldAnchor(Orientation.Vertical)); Assert.IsTrue(panel.ShouldAnchor(Orientation.InDepth)); // in depth panel.ActivateAnchoring(Orientation.InDepth, false); Assert.IsTrue(panel.ShouldAnchor(Orientation.Horizontal)); Assert.IsTrue(panel.ShouldAnchor(Orientation.Vertical)); Assert.IsFalse(panel.ShouldAnchor(Orientation.InDepth)); panel.ActivateAnchoring(Orientation.InDepth, true); Assert.IsTrue(panel.ShouldAnchor(Orientation.Horizontal)); Assert.IsTrue(panel.ShouldAnchor(Orientation.Vertical)); Assert.IsTrue(panel.ShouldAnchor(Orientation.InDepth)); // combination panel.ActivateAnchoring(Orientation.Horizontal, false); panel.ActivateAnchoring(Orientation.Vertical, false); panel.ActivateAnchoring(Orientation.InDepth, false); Assert.IsFalse(panel.ShouldAnchor(Orientation.Horizontal)); Assert.IsFalse(panel.ShouldAnchor(Orientation.Vertical)); Assert.IsFalse(panel.ShouldAnchor(Orientation.InDepth)); panel.ActivateAnchoring(Orientation.Horizontal, true); panel.ActivateAnchoring(Orientation.Vertical, true); panel.ActivateAnchoring(Orientation.InDepth, true); Assert.IsTrue(panel.ShouldAnchor(Orientation.Horizontal)); Assert.IsTrue(panel.ShouldAnchor(Orientation.Vertical)); Assert.IsTrue(panel.ShouldAnchor(Orientation.InDepth)); }
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.AreEqual(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.AreEqual(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); }
public void TestSurroudingAnchor() { var stackSize = new Vector3(100, 200, 300); var stackPanel = new PanelTests { Size = stackSize }; stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(new Vector2( 0, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, -1f)); Assert.AreEqual(new Vector2( 0, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 0)); Assert.AreEqual(new Vector2(-20, 80), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 20)); Assert.AreEqual(new Vector2(-100, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 100)); Assert.AreEqual(new Vector2(-100, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 150)); Assert.AreEqual(new Vector2( 0, 200), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, -1f)); Assert.AreEqual(new Vector2( 0, 200), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 0)); Assert.AreEqual(new Vector2(-100, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 100)); Assert.AreEqual(new Vector2(-200, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 200)); Assert.AreEqual(new Vector2(-200, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 220)); Assert.AreEqual(new Vector2( 0, 300), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, -1f)); Assert.AreEqual(new Vector2( 0, 300), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 0)); Assert.AreEqual(new Vector2(-200, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 200)); Assert.AreEqual(new Vector2(-300, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 300)); Assert.AreEqual(new Vector2(-300, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 330)); }