GridTests.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using Avalonia.Controls;
  4. using Xunit;
  5. namespace Avalonia.Controls.UnitTests
  6. {
  7. public class GridTests
  8. {
  9. [Fact]
  10. public void Calculates_Colspan_Correctly()
  11. {
  12. var target = new Grid
  13. {
  14. ColumnDefinitions = new ColumnDefinitions
  15. {
  16. new ColumnDefinition(GridLength.Auto),
  17. new ColumnDefinition(new GridLength(4, GridUnitType.Pixel)),
  18. new ColumnDefinition(GridLength.Auto),
  19. },
  20. RowDefinitions = new RowDefinitions
  21. {
  22. new RowDefinition(GridLength.Auto),
  23. new RowDefinition(GridLength.Auto),
  24. },
  25. Children =
  26. {
  27. new Border
  28. {
  29. Width = 100,
  30. Height = 25,
  31. [Grid.ColumnSpanProperty] = 3,
  32. },
  33. new Border
  34. {
  35. Width = 150,
  36. Height = 25,
  37. [Grid.RowProperty] = 1,
  38. },
  39. new Border
  40. {
  41. Width = 50,
  42. Height = 25,
  43. [Grid.RowProperty] = 1,
  44. [Grid.ColumnProperty] = 2,
  45. }
  46. },
  47. };
  48. target.Measure(Size.Infinity);
  49. // Issue #25 only appears after a second measure
  50. target.InvalidateMeasure();
  51. target.Measure(Size.Infinity);
  52. target.Arrange(new Rect(target.DesiredSize));
  53. Assert.Equal(new Size(204, 50), target.Bounds.Size);
  54. Assert.Equal(150d, target.ColumnDefinitions[0].ActualWidth);
  55. Assert.Equal(4d, target.ColumnDefinitions[1].ActualWidth);
  56. Assert.Equal(50d, target.ColumnDefinitions[2].ActualWidth);
  57. Assert.Equal(new Rect(52, 0, 100, 25), target.Children[0].Bounds);
  58. Assert.Equal(new Rect(0, 25, 150, 25), target.Children[1].Bounds);
  59. Assert.Equal(new Rect(154, 25, 50, 25), target.Children[2].Bounds);
  60. }
  61. }
  62. }