public void TestScrollOf(bool virtualizeItems) { var stackSize = new Vector3(100, 200, 300); var childSize1 = new Vector3(50, 150, 250); var childSize2 = new Vector3(150, 250, 350); var childSize3 = new Vector3(250, 250, 350); var stackPanel = new StackPanel { Size = stackSize, ItemVirtualizationEnabled = virtualizeItems, Orientation = Orientation.Horizontal, LayoutingContext = new LayoutingContext() }; var child1 = new StackPanel { Size = childSize1 }; var child2 = new StackPanel { Size = childSize2 }; var child3 = new StackPanel { Size = childSize3 }; stackPanel.Children.Add(child1); stackPanel.Children.Add(child2); stackPanel.Children.Add(child3); stackPanel.Arrange(Vector3.Zero, false); // pre-arranged stackPanel.ScrollOf(childSize1); Utilities.AssertAreNearlyEqual(1, stackPanel.ScrollPosition); stackPanel.ScrollOf(childSize1); Utilities.AssertAreNearlyEqual(1 + 1 / 3f, stackPanel.ScrollPosition); // post arranged stackPanel.InvalidateArrange(); stackPanel.ScrollOf(childSize1); Utilities.AssertAreNearlyEqual(1 + 1 / 3f, stackPanel.ScrollPosition); stackPanel.Arrange(Vector3.Zero, false); Utilities.AssertAreNearlyEqual(1 + 2 / 3f, stackPanel.ScrollPosition); stackPanel.InvalidateArrange(); stackPanel.ScrollOf(- 2 *childSize1); Utilities.AssertAreNearlyEqual(1 + 2 / 3f, stackPanel.ScrollPosition); stackPanel.Arrange(Vector3.Zero, false); Utilities.AssertAreNearlyEqual(1, stackPanel.ScrollPosition); }
public void TestSurroudingAnchor(bool virtualizeItems) { var stackSize = new Vector3(100, 200, 300); var childSize1 = new Vector3(50, 150, 250); var childSize2 = new Vector3(150, 250, 350); var childSize3 = new Vector3(250, 250, 350); var stackPanel = new StackPanel { Size = stackSize, ItemVirtualizationEnabled = virtualizeItems, Orientation = Orientation.Horizontal }; var child1 = new StackPanel { Size = childSize1 }; var child2 = new StackPanel { Size = childSize2 }; var child3 = new StackPanel { Size = childSize3 }; stackPanel.Children.Add(child1); stackPanel.Children.Add(child2); stackPanel.Children.Add(child3); stackPanel.Arrange(Vector3.Zero, false); // checks in the scrolling direction stackPanel.ScrollToBeginning(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(new Vector2(0, 50), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 0)); stackPanel.ScrolllToElement(0.5f); Utilities.AssertAreNearlyEqual(new Vector2(-25, 25), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 0)); stackPanel.ScrolllToElement(1f); Utilities.AssertAreNearlyEqual(new Vector2(0, 150), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 0)); stackPanel.ScrolllToElement(2 + 3/5f); Utilities.AssertAreNearlyEqual(new Vector2(-150, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 0)); stackPanel.ScrollToEnd(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(new Vector2(-150, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.Horizontal, 0)); // checks in other directions Assert.AreEqual(new Vector2(0, 200), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, -1)); Assert.AreEqual(new Vector2(-100, 100), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 100)); Assert.AreEqual(new Vector2(-200, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.Vertical, 500)); Assert.AreEqual(new Vector2(0, 300), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, -1)); Assert.AreEqual(new Vector2(-150, 150), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 150)); Assert.AreEqual(new Vector2(-300, 0), stackPanel.GetSurroudingAnchorDistances(Orientation.InDepth, 500)); }
public void TestScrollToNeighborScreen(bool virtualizeItems) { var stackSize = new Vector3(100, 200, 300); var childSize1 = new Vector3(50, 150, 250); var childSize2 = new Vector3(150, 250, 350); var childSize3 = new Vector3(250, 250, 350); var stackPanel = new StackPanel { Size = stackSize, ItemVirtualizationEnabled = virtualizeItems, Orientation = Orientation.Horizontal }; var child1 = new StackPanel { Size = childSize1 }; var child2 = new StackPanel { Size = childSize2 }; var child3 = new StackPanel { Size = childSize3 }; stackPanel.Children.Add(child1); stackPanel.Children.Add(child2); stackPanel.Children.Add(child3); stackPanel.Arrange(Vector3.Zero, false); // pre-arranged stackPanel.ScrollToNextPage(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(1 + 1 / 3f, stackPanel.ScrollPosition); stackPanel.ScrollToPreviousPage(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(0, stackPanel.ScrollPosition); stackPanel.ScrolllToElement(1 + 2 / 3f); stackPanel.ScrollToPreviousPage(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(1f, stackPanel.ScrollPosition); stackPanel.ScrolllToElement(1 + 2 / 3f); stackPanel.ScrollToNextPage(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(2.2f, stackPanel.ScrollPosition); // reset scrolling stackPanel.ScrollToBeginning(Orientation.Horizontal); stackPanel.Arrange(Vector3.Zero, false); // post arranged stackPanel.InvalidateArrange(); stackPanel.ScrollToNextPage(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(0, stackPanel.ScrollPosition); stackPanel.Arrange(Vector3.Zero, false); Utilities.AssertAreNearlyEqual(1 + 1 / 3f, stackPanel.ScrollPosition); stackPanel.InvalidateArrange(); stackPanel.ScrollToPreviousPage(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(1 + 1 / 3f, stackPanel.ScrollPosition); stackPanel.Arrange(Vector3.Zero, false); Utilities.AssertAreNearlyEqual(0, stackPanel.ScrollPosition); stackPanel.ScrolllToElement(1 + 2 / 3f); stackPanel.Arrange(Vector3.Zero, false); stackPanel.InvalidateArrange(); stackPanel.ScrollToPreviousPage(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(1 + 2 / 3f, stackPanel.ScrollPosition); stackPanel.Arrange(Vector3.Zero, false); Utilities.AssertAreNearlyEqual(1, stackPanel.ScrollPosition); stackPanel.ScrolllToElement(1 + 2 / 3f); stackPanel.Arrange(Vector3.Zero, false); stackPanel.InvalidateArrange(); stackPanel.ScrollToNextPage(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(1 + 2 / 3f, stackPanel.ScrollPosition); stackPanel.Arrange(Vector3.Zero, false); Utilities.AssertAreNearlyEqual(2.2f, stackPanel.ScrollPosition); }
public void TestScrollToExtrema(bool virtualizeItems) { var stackSize = new Vector3(100, 200, 300); var childSize1 = new Vector3(50, 150, 250); var childSize2 = new Vector3(150, 250, 350); var childSize3 = new Vector3(250, 250, 350); var stackPanel = new StackPanel { Size = stackSize, ItemVirtualizationEnabled = virtualizeItems, Orientation = Orientation.Horizontal }; var child1 = new StackPanel { Size = childSize1 }; var child2 = new StackPanel { Size = childSize2 }; var child3 = new StackPanel { Size = childSize3 }; stackPanel.Children.Add(child1); stackPanel.Children.Add(child2); stackPanel.Children.Add(child3); stackPanel.Arrange(Vector3.Zero, false); // pre-arranged stackPanel.ScrollToEnd(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(2 + 3 / 5f, stackPanel.ScrollPosition); stackPanel.ScrollToBeginning(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(0, stackPanel.ScrollPosition); // post arranged stackPanel.InvalidateArrange(); stackPanel.ScrollToEnd(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(0, stackPanel.ScrollPosition); stackPanel.Arrange(Vector3.Zero, false); Utilities.AssertAreNearlyEqual(2 + 3 / 5f, stackPanel.ScrollPosition); stackPanel.InvalidateArrange(); stackPanel.ScrollToBeginning(Orientation.Horizontal); Utilities.AssertAreNearlyEqual(2 + 3 / 5f, stackPanel.ScrollPosition); stackPanel.Arrange(Vector3.Zero, false); Utilities.AssertAreNearlyEqual(0, stackPanel.ScrollPosition); }
private static void TestScrollBarPosition(bool virtualizeChildren) { var stackSize = new Vector3(100, 200, 300); var childSize1 = new Vector3(50, 150, 250); var childSize2 = new Vector3(150, 250, 350); var childSize3 = new Vector3(250, 250, 350); var stackPanel = new StackPanel { Size = stackSize, ItemVirtualizationEnabled = virtualizeChildren, Orientation = Orientation.Horizontal }; Assert.AreEqual(Vector3.Zero, stackPanel.ScrollBarPositions); var child1 = new StackPanel { Size = childSize1 }; var child2 = new StackPanel { Size = childSize2 }; var child3 = new StackPanel { Size = childSize3 }; stackPanel.Children.Add(child1); stackPanel.Children.Add(child2); stackPanel.Children.Add(child3); var reference = Vector3.Zero; stackPanel.ScrollToBeginning(Orientation.Horizontal); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(reference, stackPanel.ScrollBarPositions); reference[0] = 1; stackPanel.ScrollToEnd(Orientation.Horizontal); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(reference, stackPanel.ScrollBarPositions); stackPanel.ScrolllToElement(1); stackPanel.Arrange(Vector3.Zero, false); if (virtualizeChildren) { reference[0] = 1 / (2 + (childSize3.X - stackPanel.Size.X) / childSize3.X); } else { reference[0] = childSize1.X / (childSize1.X + childSize2.X + childSize3.X - stackPanel.Size.X); } Assert.AreEqual(reference, stackPanel.ScrollBarPositions); }
public void TestViewport(bool virtualizeChildren) { var random = new Random(); var childSize1 = new Vector3(50, 150, 250); var childSize2 = new Vector3(150, 250, 350); var childSize3 = new Vector3(250, 250, 350); var childSize4 = new Vector3(350, 250, 350); var stackPanel = new StackPanel { DepthAlignment = DepthAlignment.Stretch, ItemVirtualizationEnabled = virtualizeChildren }; Assert.AreEqual(Vector3.Zero, stackPanel.Viewport); var child1 = new StackPanel { Size = childSize1 }; var child2 = new StackPanel { Size = childSize2 }; var child3 = new StackPanel { Size = childSize3 }; var child4 = new StackPanel { Size = childSize4 }; stackPanel.Children.Add(child1); stackPanel.Children.Add(child2); stackPanel.Children.Add(child3); stackPanel.Children.Add(child4); var referencePosition = Vector3.Zero; stackPanel.Arrange(referencePosition, false); Assert.AreEqual(referencePosition, stackPanel.Viewport); referencePosition = random.NextVector3(); stackPanel.Arrange(referencePosition, false); Assert.AreEqual(referencePosition, stackPanel.Viewport); referencePosition = random.NextVector3(); stackPanel.ScrollToEnd(Orientation.Horizontal); stackPanel.ScrollToEnd(Orientation.Vertical); stackPanel.Children.Remove(child4); stackPanel.Arrange(referencePosition, false); Assert.AreEqual(referencePosition, stackPanel.Viewport); var stackSize = new Vector3(100, 200, 300); stackPanel.Size = stackSize; stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(stackSize, stackPanel.Viewport); }
private static void TestScrollPosition(bool virtualizeChildren) { var stackSize = new Vector3(100, 200, 300); var childSize1 = new Vector3(50, 150, 250); var childSize2 = new Vector3(150, 250, 350); var childSize3 = new Vector3(250, 250, 350); var childSize4 = new Vector3(350, 250, 350); var stackPanel = new StackPanel { Size = stackSize, Orientation = Orientation.Horizontal, ItemVirtualizationEnabled = virtualizeChildren}; Assert.AreEqual(0f, stackPanel.ScrollPosition); var child1 = new StackPanel { Size = childSize1 }; var child2 = new StackPanel { Size = childSize2 }; var child3 = new StackPanel { Size = childSize3 }; var child4 = new StackPanel { Size = childSize4 }; stackPanel.Children.Add(child1); stackPanel.Children.Add(child2); stackPanel.Children.Add(child3); stackPanel.Children.Add(child4); float referencePosition = 0; stackPanel.ScrolllToElement(referencePosition); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(referencePosition, stackPanel.ScrollPosition); referencePosition = 1; stackPanel.ScrolllToElement(referencePosition); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(referencePosition, stackPanel.ScrollPosition); referencePosition = 2; stackPanel.ScrolllToElement(referencePosition); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(referencePosition, stackPanel.ScrollPosition); referencePosition = 2.3f; stackPanel.ScrolllToElement(referencePosition); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(referencePosition, stackPanel.ScrollPosition); stackPanel.ScrollToEnd(Orientation.Horizontal); referencePosition = 3 + (childSize4.X - stackSize.X) / childSize4.X; stackPanel.Arrange(Vector3.Zero, false); Assert.IsTrue(Math.Abs(referencePosition - stackPanel.ScrollPosition) < MathUtil.ZeroTolerance); }
public void TestOffset() { var stackSize = new Vector3(100, 200, 300); var childSize1 = new Vector3(50, 150, 250); var childSize2 = new Vector3(150, 250, 350); var childSize3 = new Vector3(250, 250, 350); var childSize4 = new Vector3(350, 250, 350); var stackPanel = new StackPanel { Size = stackSize, Orientation = Orientation.Horizontal }; Assert.AreEqual(Vector3.Zero, stackPanel.Offset); var child1 = new StackPanel { Size = childSize1 }; var child2 = new StackPanel { Size = childSize2 }; var child3 = new StackPanel { Size = childSize3 }; var child4 = new StackPanel { Size = childSize4 }; stackPanel.Children.Add(child1); stackPanel.Children.Add(child2); stackPanel.Children.Add(child3); stackPanel.Children.Add(child4); var refenceOffset = Vector3.Zero; // non virtualized children stackPanel.ScrolllToElement(1); stackPanel.Arrange(Vector3.Zero, false); refenceOffset[0] -= childSize1.X; Assert.AreEqual(refenceOffset, stackPanel.Offset); stackPanel.ScrolllToElement(2.5f); stackPanel.Arrange(Vector3.Zero, false); refenceOffset[0] -= childSize2.X + childSize3.X / 2; Assert.AreEqual(refenceOffset, stackPanel.Offset); stackPanel.ScrollToEnd(Orientation.Horizontal); stackPanel.Arrange(Vector3.Zero, false); refenceOffset[0] = -childSize1.X - childSize2.X - childSize3.X - childSize4.X + stackPanel.Size.X; Assert.IsTrue((refenceOffset-stackPanel.Offset).Length() < 0.001); // virtualized children refenceOffset[0] = 0; stackPanel.ScrolllToElement(0); stackPanel.ItemVirtualizationEnabled = true; stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(refenceOffset, stackPanel.Offset); refenceOffset[0] = 0; stackPanel.ScrolllToElement(1); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(refenceOffset, stackPanel.Offset); refenceOffset[0] = -childSize3.X / 2; stackPanel.ScrolllToElement(2.5f); stackPanel.Arrange(Vector3.Zero, false); Assert.AreEqual(refenceOffset, stackPanel.Offset); stackPanel.ScrollToEnd(Orientation.Horizontal); stackPanel.Arrange(Vector3.Zero, false); refenceOffset[0] = -childSize4.X + stackPanel.Size.X; Assert.IsTrue((refenceOffset-stackPanel.Offset).Length() < 0.001); }
private void TestExtent(Orientation direction) { var stackSize = new Vector3(100, 200, 300); var childSize1 = new Vector3(50, 150, 250); var childSize2 = new Vector3(150, 250, 350); var stackPanel = new StackPanel { Size = stackSize, Orientation = direction }; Assert.AreEqual(Vector3.Zero, stackPanel.Extent); var child1 = new StackPanel { Size = childSize1 }; var child2 = new StackPanel { Size = childSize2 }; var child3 = new StackPanel { Size = childSize1 }; stackPanel.Children.Add(child1); stackPanel.Children.Add(child2); stackPanel.Children.Add(child3); stackPanel.Arrange(Vector3.Zero, false); var exactReferenceExtent = stackSize; exactReferenceExtent[(int)direction] = 0; foreach (var child in stackPanel.Children) exactReferenceExtent[(int)direction] += child.Size[(int)direction]; Assert.AreEqual(exactReferenceExtent, stackPanel.Extent); // with virtualized items. stackPanel.ItemVirtualizationEnabled = true; stackPanel.Arrange(Vector3.Zero, false); var childCount = 0; var approximatedSize = 0f; var approximatedReferenceExtent = stackSize; while (childCount < stackPanel.Children.Count-1 && approximatedSize < stackPanel.Size[(int)direction]) { ++childCount; approximatedSize += stackPanel.Children[stackPanel.Children.Count - childCount].Size[(int)direction]; } approximatedReferenceExtent[(int)direction] = stackPanel.Children.Count / (float)childCount * approximatedSize; Assert.AreEqual(approximatedReferenceExtent, stackPanel.Extent); }