StackPanelTests.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Copyright (c) The Perspex Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using Perspex.Controls;
  4. using Xunit;
  5. namespace Perspex.Controls.UnitTests
  6. {
  7. public class StackPanelTests
  8. {
  9. [Fact]
  10. public void Lays_Out_Children_Vertically()
  11. {
  12. var target = new StackPanel
  13. {
  14. Children = new Controls
  15. {
  16. new Border { Height = 20, Width = 120 },
  17. new Border { Height = 30 },
  18. new Border { Height = 50 },
  19. }
  20. };
  21. target.Measure(Size.Infinity);
  22. target.Arrange(new Rect(target.DesiredSize));
  23. Assert.Equal(new Size(120, 100), target.Bounds.Size);
  24. Assert.Equal(new Rect(0, 0, 120, 20), target.Children[0].Bounds);
  25. Assert.Equal(new Rect(0, 20, 120, 30), target.Children[1].Bounds);
  26. Assert.Equal(new Rect(0, 50, 120, 50), target.Children[2].Bounds);
  27. }
  28. [Fact]
  29. public void Lays_Out_Children_Horizontally()
  30. {
  31. var target = new StackPanel
  32. {
  33. Orientation = Orientation.Horizontal,
  34. Children = new Controls
  35. {
  36. new Border { Width = 20, Height = 120 },
  37. new Border { Width = 30 },
  38. new Border { Width = 50 },
  39. }
  40. };
  41. target.Measure(Size.Infinity);
  42. target.Arrange(new Rect(target.DesiredSize));
  43. Assert.Equal(new Size(100, 120), target.Bounds.Size);
  44. Assert.Equal(new Rect(0, 0, 20, 120), target.Children[0].Bounds);
  45. Assert.Equal(new Rect(20, 0, 30, 120), target.Children[1].Bounds);
  46. Assert.Equal(new Rect(50, 0, 50, 120), target.Children[2].Bounds);
  47. }
  48. [Fact]
  49. public void Lays_Out_Children_Vertically_With_Gap()
  50. {
  51. var target = new StackPanel
  52. {
  53. Gap = 10,
  54. Children = new Controls
  55. {
  56. new Border { Height = 20, Width = 120 },
  57. new Border { Height = 30 },
  58. new Border { Height = 50 },
  59. }
  60. };
  61. target.Measure(Size.Infinity);
  62. target.Arrange(new Rect(target.DesiredSize));
  63. Assert.Equal(new Size(120, 130), target.Bounds.Size);
  64. Assert.Equal(new Rect(0, 0, 120, 20), target.Children[0].Bounds);
  65. Assert.Equal(new Rect(0, 30, 120, 30), target.Children[1].Bounds);
  66. Assert.Equal(new Rect(0, 70, 120, 50), target.Children[2].Bounds);
  67. }
  68. [Fact]
  69. public void Lays_Out_Children_Horizontally_With_Gap()
  70. {
  71. var target = new StackPanel
  72. {
  73. Gap = 10,
  74. Orientation = Orientation.Horizontal,
  75. Children = new Controls
  76. {
  77. new Border { Width = 20, Height = 120 },
  78. new Border { Width = 30 },
  79. new Border { Width = 50 },
  80. }
  81. };
  82. target.Measure(Size.Infinity);
  83. target.Arrange(new Rect(target.DesiredSize));
  84. Assert.Equal(new Size(130, 120), target.Bounds.Size);
  85. Assert.Equal(new Rect(0, 0, 20, 120), target.Children[0].Bounds);
  86. Assert.Equal(new Rect(30, 0, 30, 120), target.Children[1].Bounds);
  87. Assert.Equal(new Rect(70, 0, 50, 120), target.Children[2].Bounds);
  88. }
  89. [Fact]
  90. public void Lays_Out_Children_Vertically_Even_If_Larger_Than_Panel()
  91. {
  92. var target = new StackPanel
  93. {
  94. Height = 60,
  95. Children = new Controls
  96. {
  97. new Border { Height = 20, Width = 120 },
  98. new Border { Height = 30 },
  99. new Border { Height = 50 },
  100. }
  101. };
  102. target.Measure(Size.Infinity);
  103. target.Arrange(new Rect(target.DesiredSize));
  104. Assert.Equal(new Size(120, 60), target.Bounds.Size);
  105. Assert.Equal(new Rect(0, 0, 120, 20), target.Children[0].Bounds);
  106. Assert.Equal(new Rect(0, 20, 120, 30), target.Children[1].Bounds);
  107. Assert.Equal(new Rect(0, 50, 120, 50), target.Children[2].Bounds);
  108. }
  109. [Fact]
  110. public void Lays_Out_Children_Horizontally_Even_If_Larger_Than_Panel()
  111. {
  112. var target = new StackPanel
  113. {
  114. Width = 60,
  115. Orientation = Orientation.Horizontal,
  116. Children = new Controls
  117. {
  118. new Border { Width = 20, Height = 120 },
  119. new Border { Width = 30 },
  120. new Border { Width = 50 },
  121. }
  122. };
  123. target.Measure(Size.Infinity);
  124. target.Arrange(new Rect(target.DesiredSize));
  125. Assert.Equal(new Size(60, 120), target.Bounds.Size);
  126. Assert.Equal(new Rect(0, 0, 20, 120), target.Children[0].Bounds);
  127. Assert.Equal(new Rect(20, 0, 30, 120), target.Children[1].Bounds);
  128. Assert.Equal(new Rect(50, 0, 50, 120), target.Children[2].Bounds);
  129. }
  130. }
  131. }