Dim.AutoTests.PosTypes.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. namespace Terminal.Gui.LayoutTests;
  2. public partial class DimAutoTests
  3. {
  4. // Tests all the Pos Types in Subview scenarios to ensure DimAutoStyle.Content is calculated correctly
  5. #region PosAbsolute
  6. [Theory]
  7. [InlineData (0, 0, 0, 0, 0, 0)]
  8. [InlineData (0, 19, 0, 9, 19, 9)]
  9. [InlineData (0, 20, 0, 10, 20, 10)]
  10. [InlineData (0, 21, 0, 11, 21, 11)]
  11. [InlineData (1, 21, 1, 11, 21, 11)]
  12. [InlineData (21, 21, 11, 11, 21, 11)]
  13. public void With_Subview_Using_PosAbsolute (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
  14. {
  15. var view = new View
  16. {
  17. Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
  18. Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
  19. };
  20. var subview = new View
  21. {
  22. X = Pos.Absolute (10),
  23. Y = Pos.Absolute (5),
  24. Width = 20,
  25. Height = 10
  26. };
  27. view.Add (subview);
  28. // Assuming the calculation is done after layout
  29. int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
  30. int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
  31. int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
  32. int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
  33. Assert.Equal (expectedWidth, calculatedWidth);
  34. Assert.Equal (expectedHeight, calculatedHeight);
  35. Assert.Equal (0, calculatedX);
  36. Assert.Equal (0, calculatedY);
  37. }
  38. #endregion PosAbsolute
  39. #region PosPercent
  40. [Theory]
  41. [InlineData (0, 0, 0, 0, 0, 0)]
  42. [InlineData (0, 19, 0, 9, 19, 9)]
  43. [InlineData (0, 20, 0, 10, 20, 10)]
  44. [InlineData (0, 21, 0, 11, 20, 10)]
  45. [InlineData (1, 21, 1, 11, 20, 10)]
  46. [InlineData (21, 21, 11, 11, 21, 11)]
  47. public void With_Subview_Using_PosPercent (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
  48. {
  49. var view = new View
  50. {
  51. Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
  52. Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
  53. };
  54. var subview = new View
  55. {
  56. X = Pos.Percent (50),
  57. Y = Pos.Percent (50),
  58. Width = 20,
  59. Height = 10
  60. };
  61. view.Add (subview);
  62. // Assuming the calculation is done after layout
  63. int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
  64. int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
  65. int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
  66. int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
  67. Assert.Equal (expectedWidth, calculatedWidth);
  68. Assert.Equal (expectedHeight, calculatedHeight);
  69. Assert.Equal (0, calculatedX);
  70. Assert.Equal (0, calculatedY);
  71. view.BeginInit ();
  72. view.EndInit ();
  73. // subview should be at 50% in the parent view
  74. Assert.Equal ((int)(view.Viewport.Width * .50), subview.Frame.X);
  75. Assert.Equal ((int)(view.Viewport.Height * .50), subview.Frame.Y);
  76. }
  77. [Theory]
  78. [InlineData (0, 0, 0, 0, 0, 0)]
  79. [InlineData (0, 19, 0, 9, 19, 9)]
  80. [InlineData (0, 20, 0, 10, 20, 10)]
  81. [InlineData (0, 21, 0, 11, 21, 11)]
  82. [InlineData (1, 21, 1, 11, 21, 11)]
  83. [InlineData (21, 21, 11, 11, 21, 11)]
  84. public void With_Subview_Using_PosPercent_Combine (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
  85. {
  86. var view = new View
  87. {
  88. Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
  89. Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
  90. };
  91. var subview = new View
  92. {
  93. X = Pos.Percent (50) + 1,
  94. Y = 1 + Pos.Percent (50),
  95. Width = 20,
  96. Height = 10
  97. };
  98. view.Add (subview);
  99. // Assuming the calculation is done after layout
  100. int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
  101. int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
  102. int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
  103. int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
  104. Assert.Equal (expectedWidth, calculatedWidth);
  105. Assert.Equal (expectedHeight, calculatedHeight);
  106. Assert.Equal (0, calculatedX);
  107. Assert.Equal (0, calculatedY);
  108. view.BeginInit ();
  109. view.EndInit ();
  110. // subview should be at 50% in the parent view
  111. Assert.Equal ((int)(view.Viewport.Width * .50) + 1, subview.Frame.X);
  112. Assert.Equal ((int)(view.Viewport.Height * .50) + 1, subview.Frame.Y);
  113. }
  114. #endregion PosPercent
  115. #region PosCenter
  116. [Theory]
  117. [InlineData (0, 0, 0, 0, 0, 0)]
  118. [InlineData (0, 19, 0, 9, 19, 9)]
  119. [InlineData (0, 20, 0, 10, 20, 10)]
  120. [InlineData (0, 21, 0, 11, 20, 10)]
  121. [InlineData (1, 21, 1, 11, 20, 10)]
  122. [InlineData (21, 21, 11, 11, 21, 11)]
  123. public void With_Subview_Using_PosCenter (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
  124. {
  125. var view = new View
  126. {
  127. Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
  128. Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
  129. };
  130. var subview = new View
  131. {
  132. X = Pos.Center (),
  133. Y = Pos.Center (),
  134. Width = 20,
  135. Height = 10
  136. };
  137. view.Add (subview);
  138. // Assuming the calculation is done after layout
  139. int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
  140. int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
  141. int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
  142. int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
  143. Assert.Equal (expectedWidth, calculatedWidth);
  144. Assert.Equal (expectedHeight, calculatedHeight);
  145. Assert.Equal (0, calculatedX);
  146. Assert.Equal (0, calculatedY);
  147. view.BeginInit ();
  148. view.EndInit ();
  149. // subview should be centered in the parent view + 1
  150. Assert.Equal ((view.Viewport.Width - subview.Frame.Width) / 2, subview.Frame.X);
  151. Assert.Equal ((view.Viewport.Height - subview.Frame.Height) / 2, subview.Frame.Y);
  152. }
  153. [Theory]
  154. [InlineData (0, 0, 0, 0, 0, 0)]
  155. [InlineData (0, 19, 0, 9, 19, 9)]
  156. [InlineData (0, 18, 0, 8, 18, 8)]
  157. [InlineData (0, 20, 0, 10, 20, 10)]
  158. [InlineData (0, 21, 0, 11, 21, 11)]
  159. [InlineData (1, 21, 1, 11, 21, 11)]
  160. [InlineData (21, 21, 11, 11, 21, 11)]
  161. public void With_Subview_Using_PosCenter_Combine (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
  162. {
  163. var view = new View
  164. {
  165. Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
  166. Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
  167. };
  168. var subview = new View
  169. {
  170. X = Pos.Center () + 1,
  171. Y = 1 + Pos.Center (),
  172. Width = 20,
  173. Height = 10
  174. };
  175. view.Add (subview);
  176. // Assuming the calculation is done after layout
  177. int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
  178. int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
  179. int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
  180. int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
  181. Assert.Equal (expectedWidth, calculatedWidth);
  182. Assert.Equal (expectedHeight, calculatedHeight);
  183. Assert.Equal (0, calculatedX);
  184. Assert.Equal (0, calculatedY);
  185. view.BeginInit ();
  186. view.EndInit ();
  187. // subview should be centered in the parent view + 1
  188. Assert.Equal ((view.Viewport.Width - subview.Frame.Width) / 2 + 1, subview.Frame.X);
  189. Assert.Equal ((view.Viewport.Height - subview.Frame.Height) / 2 + 1, subview.Frame.Y);
  190. }
  191. #endregion PosCenter
  192. #region PosView
  193. // TODO: Need PosView tests
  194. [Fact]
  195. public void With_Subview_Using_PosView ()
  196. {
  197. var view = new View ()
  198. {
  199. Width = Dim.Auto (),
  200. Height = Dim.Auto (),
  201. };
  202. var subview1 = new View { X = 1, Y = 2, Width = 1, Height = 2 };
  203. var subview2 = new View { X = Pos.Top (subview1), Y = Pos.Bottom (subview1), Width = 1, Height = 2 };
  204. view.Add (subview1, subview2);
  205. view.SetRelativeLayout (new (100, 100));
  206. // subview1.X + subview1.Width + subview2.Width
  207. Assert.Equal (1 + 1 + 1, view.Frame.Width);
  208. // subview1.Y + subview1.Height + subview2.Height
  209. Assert.Equal (2 + 2 + 2, view.Frame.Height);
  210. }
  211. #endregion PosView
  212. #region PosAnchorEnd
  213. [Theory]
  214. [InlineData (0, 0, 0, 0, 0, 0)]
  215. [InlineData (0, 19, 0, 9, 19, 9)]
  216. [InlineData (0, 18, 0, 8, 18, 8)]
  217. [InlineData (0, 20, 0, 10, 20, 10)]
  218. [InlineData (0, 21, 0, 11, 20, 10)]
  219. [InlineData (1, 21, 1, 11, 20, 10)]
  220. [InlineData (21, 21, 11, 11, 21, 11)]
  221. public void With_Subview_Using_PosAnchorEnd (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
  222. {
  223. var view = new View
  224. {
  225. Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
  226. Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
  227. };
  228. var subview = new View
  229. {
  230. X = Pos.AnchorEnd (),
  231. Y = Pos.AnchorEnd (),
  232. Width = 20,
  233. Height = 10
  234. };
  235. view.Add (subview);
  236. // Assuming the calculation is done after layout
  237. int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
  238. int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
  239. int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
  240. int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
  241. Assert.Equal (expectedWidth, calculatedWidth);
  242. Assert.Equal (expectedHeight, calculatedHeight);
  243. Assert.Equal (0, calculatedX);
  244. Assert.Equal (0, calculatedY);
  245. view.BeginInit ();
  246. view.EndInit ();
  247. // subview should be at the end of the view
  248. Assert.Equal (view.Viewport.Width - subview.Frame.Width, subview.Frame.X);
  249. Assert.Equal (view.Viewport.Height - subview.Frame.Height, subview.Frame.Y);
  250. }
  251. [Theory]
  252. [InlineData (0, 0, 0, 0, 0, 0)]
  253. [InlineData (0, 19, 0, 9, 19, 9)]
  254. [InlineData (0, 18, 0, 8, 18, 8)]
  255. [InlineData (0, 20, 0, 10, 20, 10)]
  256. [InlineData (0, 21, 0, 11, 21, 11)]
  257. [InlineData (1, 21, 1, 11, 21, 11)]
  258. [InlineData (21, 21, 11, 11, 21, 11)]
  259. [InlineData (0, 30, 0, 20, 25, 15)]
  260. public void With_Subview_And_Subview_Using_PosAnchorEnd (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
  261. {
  262. var view = new View
  263. {
  264. Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
  265. Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
  266. };
  267. var otherView = new View
  268. {
  269. Width = 5,
  270. Height = 5
  271. };
  272. view.Add (otherView);
  273. var subview = new View
  274. {
  275. X = Pos.AnchorEnd (),
  276. Y = Pos.AnchorEnd (),
  277. Width = 20,
  278. Height = 10
  279. };
  280. view.Add (subview);
  281. // Assuming the calculation is done after layout
  282. int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
  283. int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
  284. int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
  285. int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
  286. Assert.Equal (expectedWidth, calculatedWidth);
  287. Assert.Equal (expectedHeight, calculatedHeight);
  288. Assert.Equal (0, calculatedX);
  289. Assert.Equal (0, calculatedY);
  290. view.BeginInit ();
  291. view.EndInit ();
  292. // subview should be at the end of the view
  293. Assert.Equal (view.Viewport.Width - subview.Frame.Width, subview.Frame.X);
  294. Assert.Equal (view.Viewport.Height - subview.Frame.Height, subview.Frame.Y);
  295. }
  296. [Theory]
  297. [InlineData (0, 0, 0, 0, 0, 0)]
  298. [InlineData (0, 19, 0, 9, 19, 9)]
  299. [InlineData (0, 18, 0, 8, 18, 8)]
  300. [InlineData (0, 20, 0, 10, 20, 10)]
  301. [InlineData (0, 21, 0, 11, 21, 11)]
  302. [InlineData (1, 21, 1, 11, 21, 11)]
  303. [InlineData (21, 21, 11, 11, 21, 11)]
  304. [InlineData (0, 30, 0, 20, 25, 15)]
  305. public void With_DimAutoSubview_And_Subview_Using_PosAnchorEnd (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
  306. {
  307. var view = new View
  308. {
  309. Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
  310. Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
  311. };
  312. var otherView = new View
  313. {
  314. Text = "01234\n01234\n01234\n01234\n01234",
  315. Width = Dim.Auto(),
  316. Height = Dim.Auto ()
  317. };
  318. view.Add (otherView);
  319. var subview = new View
  320. {
  321. X = Pos.AnchorEnd (),
  322. Y = Pos.AnchorEnd (),
  323. Width = 20,
  324. Height = 10
  325. };
  326. view.Add (subview);
  327. // Assuming the calculation is done after layout
  328. int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
  329. int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
  330. int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
  331. int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
  332. Assert.Equal (expectedWidth, calculatedWidth);
  333. Assert.Equal (expectedHeight, calculatedHeight);
  334. Assert.Equal (0, calculatedX);
  335. Assert.Equal (0, calculatedY);
  336. view.BeginInit ();
  337. view.EndInit ();
  338. // subview should be at the end of the view
  339. Assert.Equal (view.Viewport.Width - subview.Frame.Width, subview.Frame.X);
  340. Assert.Equal (view.Viewport.Height - subview.Frame.Height, subview.Frame.Y);
  341. }
  342. [Theory]
  343. [InlineData (0, 0, 0, 0, 0, 0)]
  344. [InlineData (0, 19, 0, 9, 19, 9)]
  345. [InlineData (0, 18, 0, 8, 18, 8)]
  346. [InlineData (0, 20, 0, 10, 20, 10)]
  347. [InlineData (0, 21, 0, 11, 21, 11)]
  348. [InlineData (1, 21, 1, 11, 21, 11)]
  349. [InlineData (21, 21, 11, 11, 21, 11)]
  350. [InlineData (0, 30, 0, 20, 26, 16)]
  351. public void With_PosViewSubview_And_Subview_Using_PosAnchorEnd (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
  352. {
  353. var view = new View
  354. {
  355. Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
  356. Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
  357. };
  358. var otherView = new View
  359. {
  360. Width = 1,
  361. Height = 1,
  362. };
  363. view.Add (otherView);
  364. var posViewView = new View
  365. {
  366. X = Pos.Bottom(otherView),
  367. Y = Pos.Right(otherView),
  368. Width = 5,
  369. Height = 5,
  370. };
  371. view.Add (posViewView);
  372. var subview = new View
  373. {
  374. X = Pos.AnchorEnd (),
  375. Y = Pos.AnchorEnd (),
  376. Width = 20,
  377. Height = 10
  378. };
  379. view.Add (subview);
  380. // Assuming the calculation is done after layout
  381. int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
  382. int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
  383. int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
  384. int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
  385. Assert.Equal (expectedWidth, calculatedWidth);
  386. Assert.Equal (expectedHeight, calculatedHeight);
  387. Assert.Equal (0, calculatedX);
  388. Assert.Equal (0, calculatedY);
  389. view.BeginInit ();
  390. view.EndInit ();
  391. // subview should be at the end of the view
  392. Assert.Equal (view.Viewport.Width - subview.Frame.Width, subview.Frame.X);
  393. Assert.Equal (view.Viewport.Height - subview.Frame.Height, subview.Frame.Y);
  394. }
  395. [Theory]
  396. [InlineData (0, 0, 0, 0, 0, 0)]
  397. [InlineData (0, 19, 0, 9, 19, 9)]
  398. [InlineData (0, 18, 0, 8, 18, 8)]
  399. [InlineData (0, 20, 0, 10, 20, 10)]
  400. [InlineData (0, 21, 0, 11, 21, 11)]
  401. [InlineData (1, 21, 1, 11, 21, 11)]
  402. [InlineData (21, 21, 11, 11, 21, 11)]
  403. [InlineData (0, 30, 0, 20, 22, 12)]
  404. public void With_DimViewSubview_And_Subview_Using_PosAnchorEnd (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
  405. {
  406. var view = new View
  407. {
  408. Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth),
  409. Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight)
  410. };
  411. var otherView = new View
  412. {
  413. Width = 1,
  414. Height = 1,
  415. };
  416. view.Add (otherView);
  417. var dimViewView = new View
  418. {
  419. Id = "dimViewView",
  420. X = 1,
  421. Y = 1,
  422. Width = Dim.Width (otherView),
  423. Height = Dim.Height (otherView),
  424. };
  425. view.Add (dimViewView);
  426. var subview = new View
  427. {
  428. X = Pos.AnchorEnd (),
  429. Y = Pos.AnchorEnd (),
  430. Width = 20,
  431. Height = 10
  432. };
  433. view.Add (subview);
  434. // Assuming the calculation is done after layout
  435. int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
  436. int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
  437. int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
  438. int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
  439. Assert.Equal (expectedWidth, calculatedWidth);
  440. Assert.Equal (expectedHeight, calculatedHeight);
  441. Assert.Equal (0, calculatedX);
  442. Assert.Equal (0, calculatedY);
  443. view.BeginInit ();
  444. view.EndInit ();
  445. // subview should be at the end of the view
  446. Assert.Equal (view.Viewport.Width - subview.Frame.Width, subview.Frame.X);
  447. Assert.Equal (view.Viewport.Height - subview.Frame.Height, subview.Frame.Y);
  448. }
  449. [Theory]
  450. [InlineData (0, 10, 0, 10, 10, 2)]
  451. [InlineData (0, 5, 0, 5, 5, 3)] // max width of 5 should cause wordwrap at 5 giving a height of 2 + 1
  452. [InlineData (0, 19, 0, 9, 11, 2)]
  453. //[InlineData (0, 20, 0, 10, 20, 10)]
  454. //[InlineData (0, 21, 0, 11, 21, 11)]
  455. //[InlineData (1, 21, 1, 11, 21, 11)]
  456. //[InlineData (21, 21, 11, 11, 21, 11)]
  457. public void With_Text_And_Subview_Using_PosAnchorEnd (int minWidth, int maxWidth, int minHeight, int maxHeight, int expectedWidth, int expectedHeight)
  458. {
  459. var view = new View
  460. {
  461. Text = "01234ABCDE",
  462. Width = Dim.Auto (),
  463. Height = Dim.Auto ()
  464. };
  465. // Without a subview, width should be 10
  466. // Without a subview, height should be 1
  467. view.SetRelativeLayout (Application.Screen.Size);
  468. Assert.Equal (10, view.Frame.Width);
  469. Assert.Equal (1, view.Frame.Height);
  470. view.Width = Dim.Auto (minimumContentDim: minWidth, maximumContentDim: maxWidth);
  471. view.Height = Dim.Auto (minimumContentDim: minHeight, maximumContentDim: maxHeight);
  472. var subview = new View
  473. {
  474. X = Pos.AnchorEnd (),
  475. Y = Pos.AnchorEnd (),
  476. Width = 1,
  477. Height = 1
  478. };
  479. view.Add (subview);
  480. // Assuming the calculation is done after layout
  481. int calculatedX = view.X.Calculate (100, view.Width, view, Dimension.Width);
  482. int calculatedY = view.Y.Calculate (100, view.Height, view, Dimension.Height);
  483. int calculatedWidth = view.Width.Calculate (0, 100, view, Dimension.Width);
  484. int calculatedHeight = view.Height.Calculate (0, 100, view, Dimension.Height);
  485. Assert.Equal (expectedWidth, calculatedWidth);
  486. Assert.Equal (expectedHeight, calculatedHeight);
  487. Assert.Equal (0, calculatedX);
  488. Assert.Equal (0, calculatedY);
  489. }
  490. #endregion PosAnchorEnd
  491. #region PosFunc
  492. [Fact]
  493. public void With_Subview_Using_PosFunc ()
  494. {
  495. var view = new View ()
  496. {
  497. Width = Dim.Auto (),
  498. Height = Dim.Auto (),
  499. };
  500. var subview = new View { X = Pos.Func (() => 20), Y = Pos.Func (() => 25) };
  501. view.Add (subview);
  502. view.SetRelativeLayout (new (100, 100));
  503. Assert.Equal (20, view.Frame.Width);
  504. Assert.Equal (25, view.Frame.Height);
  505. }
  506. #endregion PosFunc
  507. #region PosCombine
  508. // TODO: Need more PosCombine tests
  509. #endregion PosCombine
  510. }