public void TestArrangeOverrideRelative() { ResetState(); DepthAlignment = DepthAlignment.Stretch; // test that arrange set render size to provided size when there is no children var providedSize = 1000 * rand.NextVector3(); var providedSizeWithoutMargins = CalculateSizeWithoutThickness(ref providedSize, ref MarginInternal); Measure(providedSize); Arrange(providedSize, false); Assert.Equal(providedSizeWithoutMargins, RenderSize); ResetState(); DepthAlignment = DepthAlignment.Stretch; var child = new ArrangeValidator(); child.DependencyProperties.Set(UseAbsolutePositionPropertyKey, false); child.DependencyProperties.Set(RelativeSizePropertyKey, new Vector3(0.2f, 0.3f, 0.4f)); child.DependencyProperties.Set(PinOriginPropertyKey, new Vector3(0f, 0.5f, 1f)); child.DependencyProperties.Set(RelativePositionPropertyKey, new Vector3(0.2f, 0.4f, 0.6f)); Children.Add(child); child.ReturnedMeasuredValue = 2 * new Vector3(2, 6, 12); child.ExpectedArrangeValue = child.ReturnedMeasuredValue; providedSize = new Vector3(10, 20, 30); Measure(providedSize); Arrange(providedSize, false); Assert.Equal(Matrix.Translation(2f - 5f, 8f - 6f - 10f, 18f - 24f - 15f), child.DependencyProperties.Get(PanelArrangeMatrixPropertyKey)); }
public void TestArrangeOverride() { ResetState(); DepthAlignment = DepthAlignment.Stretch; // Test that returned value is the one provided when no content var providedSize = 1000 * rand.NextVector3(); var arrangedSize = ArrangeOverride(providedSize); Assert.Equal(providedSize, arrangedSize); ResetState(); // Test arrange with some content providedSize = 1000 * rand.NextVector3(); var content = new ArrangeValidator { DepthAlignment = DepthAlignment.Stretch }; Content = content; Padding = rand.NextThickness(10, 20, 30, 40, 50, 60); var providedSizeWithoutPadding = CalculateSizeWithoutThickness(ref providedSize, ref padding); content.ExpectedArrangeValue = providedSizeWithoutPadding; arrangedSize = ArrangeOverride(providedSize); Assert.Equal(providedSize, arrangedSize); var childOffsets = new Vector3(Padding.Left, Padding.Top, Padding.Front) - arrangedSize / 2; Assert.Equal(Matrix.Translation(childOffsets), VisualContent.DependencyProperties.Get(ContentArrangeMatrixPropertyKey)); }
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.Equal(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 = child.ReturnedMeasuredValue; canvas.Children.Add(child); } // Measure the stack canvas.Measure(availablesizeWithMargins); canvas.Arrange(availablesizeWithMargins, false); // checks the stack arranged size Assert.Equal(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.Equal(Matrix.Translation(childOffsets), canvas.Children[i].DependencyProperties.Get(PanelArrangeMatrixPropertyKey)); } }
private void TestArrangeOverrideCore(Orientation orientation) { ResetState(); DepthAlignment = DepthAlignment.Stretch; // Create and add children var child1 = new ArrangeValidator { DepthAlignment = DepthAlignment.Stretch }; var child2 = new ArrangeValidator { DepthAlignment = DepthAlignment.Stretch }; var child3 = new ArrangeValidator { DepthAlignment = DepthAlignment.Stretch }; Children.Add(child1); Children.Add(child2); Children.Add(child3); // set the stack orientation Orientation = orientation; // set children margins Children[0].Margin = rand.NextThickness(10, 11, 12, 13, 14, 15); Children[1].Margin = rand.NextThickness(10, 11, 12, 13, 14, 15); Children[2].Margin = rand.NextThickness(10, 11, 12, 13, 14, 15); // set an available size var availablesizeWithMargins = 1000 * rand.NextVector3(); var availableSizeWithoutMargins = CalculateSizeWithoutThickness(ref availablesizeWithMargins, ref MarginInternal); // set the arrange validator values foreach (ArrangeValidator child in Children) { child.ReturnedMeasuredValue = 1000 * rand.NextVector3(); child.ExpectedArrangeValue = CalculateSizeWithoutThickness(ref availableSizeWithoutMargins, ref child.MarginInternal); child.ExpectedArrangeValue[(int)Orientation] = child.ReturnedMeasuredValue[(int)Orientation]; } // Measure the stack Measure(availableSizeWithoutMargins); Arrange(availablesizeWithMargins, false); // compute the children accumulated sizes var acculumatedDesiredSizeWithMarginsList = new List <Vector3>(); for (int i = 0; i < Children.Count; i++) { var accumulatedVector = Vector3.Zero; for (int j = 0; j < i; j++) { for (int dim = 0; dim < 3; ++dim) { accumulatedVector[dim] += Children[j].RenderSize[dim] + Children[j].Margin[dim] + Children[j].Margin[dim + 3]; } } acculumatedDesiredSizeWithMarginsList.Add(accumulatedVector); } // checks the stack arranged size Assert.Equal(availableSizeWithoutMargins, RenderSize); // Checks the children arrange matrix for (int i = 0; i < Children.Count; i++) { var childOffsets = -RenderSize / 2; switch (orientation) { case Orientation.Horizontal: childOffsets.X += acculumatedDesiredSizeWithMarginsList[i].X; break; case Orientation.Vertical: childOffsets.Y += acculumatedDesiredSizeWithMarginsList[i].Y; break; case Orientation.InDepth: childOffsets.Z += acculumatedDesiredSizeWithMarginsList[i].Z; break; default: throw new ArgumentOutOfRangeException(nameof(orientation)); } Utilities.AssertAreNearlyEqual(Matrix.Translation(childOffsets), Children[i].DependencyProperties.Get(PanelArrangeMatrixPropertyKey)); } }