TileViewTests.cs 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404
  1. using UnitTests;
  2. using Xunit.Abstractions;
  3. namespace Terminal.Gui.ViewsTests;
  4. public class TileViewTests (ITestOutputHelper output)
  5. {
  6. [Fact]
  7. [AutoInitShutdown]
  8. public void Test_SplitTop_WholeBottom ()
  9. {
  10. var tileView = new TileView (2)
  11. {
  12. Width = 20, Height = 10, Orientation = Orientation.Horizontal, LineStyle = LineStyle.Single
  13. };
  14. Assert.True (tileView.TrySplitTile (0, 2, out TileView top));
  15. top.Tiles.ElementAt (0).ContentView!.Add (new Label { Text = "bleh" });
  16. top.Tiles.ElementAt (1).ContentView!.Add (new Label { Text = "blah" });
  17. top.Layout ();
  18. tileView.Tiles.ElementAt (1).ContentView!.Add (new Label { Text = "Hello" });
  19. tileView.SetScheme (new ());
  20. top.SetScheme (new ());
  21. top.Layout ();
  22. tileView.Layout ();
  23. tileView.Draw ();
  24. var looksLike =
  25. @"
  26. ┌─────────┬────────┐
  27. │bleh │blah │
  28. │ │ │
  29. │ │ │
  30. │ │ │
  31. ├─────────┴────────┤
  32. │Hello │
  33. │ │
  34. │ │
  35. └──────────────────┘";
  36. DriverAssert.AssertDriverContentsAre (looksLike, output);
  37. }
  38. [Fact]
  39. [AutoInitShutdown]
  40. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter1 ()
  41. {
  42. TileView tv = Get5x1TilesView ();
  43. tv.Tiles.ElementAt (0).MinSize = int.MaxValue;
  44. Application.LayoutAndDraw ();
  45. var looksLike =
  46. @"
  47. ┌────┬────┬────┬────┬───┐
  48. │1111│2222│3333│4444│555│
  49. │ │ │ │ │ │
  50. └────┴────┴────┴────┴───┘
  51. ";
  52. DriverAssert.AssertDriverContentsAre (looksLike, output);
  53. for (var x = 0; x <= 5; x++)
  54. {
  55. // All these values would result in tile 0 getting smaller
  56. // so are not allowed (tile[0] has a min size of Int.Max)
  57. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  58. }
  59. for (var x = 6; x < 10; x++)
  60. {
  61. // All these values would result in tile 0 getting bigger
  62. // so are allowed
  63. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  64. }
  65. for (var x = 10; x < 100; x++)
  66. {
  67. // These values would result in the first splitter moving past
  68. // the second splitter so are not allowed
  69. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  70. }
  71. Application.LayoutAndDraw ();
  72. looksLike =
  73. @"
  74. ┌────────┬┬────┬────┬───┐
  75. │11111111││3333│4444│555│
  76. │ ││ │ │ │
  77. └────────┴┴────┴────┴───┘
  78. ";
  79. DriverAssert.AssertDriverContentsAre (looksLike, output);
  80. }
  81. [Fact]
  82. [AutoInitShutdown]
  83. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter1_NoBorder ()
  84. {
  85. TileView tv = Get5x1TilesView (false);
  86. tv.Tiles.ElementAt (0).MinSize = int.MaxValue;
  87. Application.LayoutAndDraw ();
  88. var looksLike =
  89. @"
  90. 11111│2222│3333│4444│5555
  91. │ │ │ │
  92. │ │ │ │
  93. │ │ │ │
  94. ";
  95. DriverAssert.AssertDriverContentsAre (looksLike, output);
  96. for (var x = 0; x <= 5; x++)
  97. {
  98. // All these values would result in tile 0 getting smaller
  99. // so are not allowed (tile[0] has a min size of Int.Max)
  100. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  101. }
  102. for (var x = 6; x < 10; x++)
  103. {
  104. // All these values would result in tile 0 getting bigger
  105. // so are allowed
  106. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  107. }
  108. for (var x = 10; x < 100; x++)
  109. {
  110. // These values would result in the first splitter moving past
  111. // the second splitter so are not allowed
  112. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  113. }
  114. Application.LayoutAndDraw ();
  115. looksLike =
  116. @"
  117. 111111111││3333│4444│5555
  118. ││ │ │
  119. ││ │ │
  120. ││ │ │
  121. ";
  122. DriverAssert.AssertDriverContentsAre (looksLike, output);
  123. }
  124. [Fact]
  125. [AutoInitShutdown]
  126. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2 ()
  127. {
  128. TileView tv = Get5x1TilesView ();
  129. tv.Tiles.ElementAt (1).MinSize = 2;
  130. tv.Tiles.ElementAt (2).MinSize = 3;
  131. Application.LayoutAndDraw ();
  132. var looksLike =
  133. @"
  134. ┌────┬────┬────┬────┬───┐
  135. │1111│2222│3333│4444│555│
  136. │ │ │ │ │ │
  137. └────┴────┴────┴────┴───┘
  138. ";
  139. DriverAssert.AssertDriverContentsAre (looksLike, output);
  140. for (var x = 10; x > 7; x--)
  141. {
  142. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  143. }
  144. for (var x = 7; x > 0; x--)
  145. {
  146. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  147. }
  148. Application.LayoutAndDraw ();
  149. looksLike =
  150. @"
  151. ┌────┬──┬──────┬────┬───┐
  152. │1111│22│333333│4444│555│
  153. │ │ │ │ │ │
  154. └────┴──┴──────┴────┴───┘
  155. ";
  156. DriverAssert.AssertDriverContentsAre (looksLike, output);
  157. for (var x = 10; x < 12; x++)
  158. {
  159. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  160. }
  161. for (var x = 12; x < 25; x++)
  162. {
  163. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  164. }
  165. Application.Top!.Layout ();
  166. tv.Draw ();
  167. looksLike =
  168. @"
  169. ┌────┬─────┬───┬────┬───┐
  170. │1111│22222│333│4444│555│
  171. │ │ │ │ │ │
  172. └────┴─────┴───┴────┴───┘
  173. ";
  174. DriverAssert.AssertDriverContentsAre (looksLike, output);
  175. }
  176. [Fact]
  177. [AutoInitShutdown]
  178. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2_NoBorder ()
  179. {
  180. TileView tv = Get5x1TilesView (false);
  181. tv.Tiles.ElementAt (1).MinSize = 2;
  182. tv.Tiles.ElementAt (2).MinSize = 3;
  183. Application.LayoutAndDraw ();
  184. var looksLike =
  185. @"
  186. 11111│2222│3333│4444│5555
  187. │ │ │ │
  188. │ │ │ │
  189. │ │ │ │
  190. ";
  191. DriverAssert.AssertDriverContentsAre (looksLike, output);
  192. for (var x = 10; x > 7; x--)
  193. {
  194. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  195. }
  196. for (var x = 7; x > 0; x--)
  197. {
  198. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  199. }
  200. Application.LayoutAndDraw ();
  201. looksLike =
  202. @"
  203. 11111│22│333333│4444│5555
  204. │ │ │ │
  205. │ │ │ │
  206. │ │ │ │
  207. ";
  208. DriverAssert.AssertDriverContentsAre (looksLike, output);
  209. for (var x = 10; x < 12; x++)
  210. {
  211. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  212. }
  213. for (var x = 12; x < 25; x++)
  214. {
  215. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  216. }
  217. Application.LayoutAndDraw ();
  218. looksLike =
  219. @"
  220. 11111│22222│333│4444│5555
  221. │ │ │ │
  222. │ │ │ │
  223. │ │ │ │
  224. ";
  225. DriverAssert.AssertDriverContentsAre (looksLike, output);
  226. }
  227. [Fact]
  228. [AutoInitShutdown]
  229. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4 ()
  230. {
  231. TileView tv = Get5x1TilesView ();
  232. tv.Tiles.ElementAt (3).MinSize = 2;
  233. tv.Tiles.ElementAt (4).MinSize = 1;
  234. Application.LayoutAndDraw ();
  235. var looksLike =
  236. @"
  237. ┌────┬────┬────┬────┬───┐
  238. │1111│2222│3333│4444│555│
  239. │ │ │ │ │ │
  240. └────┴────┴────┴────┴───┘
  241. ";
  242. DriverAssert.AssertDriverContentsAre (looksLike, output);
  243. for (var x = 20; x > 17; x--)
  244. {
  245. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  246. }
  247. for (var x = 17; x > 0; x--)
  248. {
  249. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  250. }
  251. Application.LayoutAndDraw ();
  252. looksLike =
  253. @"
  254. ┌────┬────┬────┬──┬─────┐
  255. │1111│2222│3333│44│55555│
  256. │ │ │ │ │ │
  257. └────┴────┴────┴──┴─────┘
  258. ";
  259. DriverAssert.AssertDriverContentsAre (looksLike, output);
  260. for (var x = 20; x < 23; x++)
  261. {
  262. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  263. }
  264. for (var x = 23; x < 100; x++)
  265. {
  266. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  267. }
  268. Application.LayoutAndDraw ();
  269. looksLike =
  270. @"
  271. ┌────┬────┬────┬──────┬─┐
  272. │1111│2222│3333│444444│5│
  273. │ │ │ │ │ │
  274. └────┴────┴────┴──────┴─┘
  275. ";
  276. DriverAssert.AssertDriverContentsAre (looksLike, output);
  277. }
  278. [Fact]
  279. [AutoInitShutdown]
  280. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4_NoBorder ()
  281. {
  282. TileView tv = Get5x1TilesView (false);
  283. tv.Tiles.ElementAt (3).MinSize = 2;
  284. tv.Tiles.ElementAt (4).MinSize = 1;
  285. Application.LayoutAndDraw ();
  286. var looksLike =
  287. @"
  288. 11111│2222│3333│4444│5555
  289. │ │ │ │
  290. │ │ │ │
  291. │ │ │ │
  292. ";
  293. DriverAssert.AssertDriverContentsAre (looksLike, output);
  294. for (var x = 20; x > 17; x--)
  295. {
  296. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  297. }
  298. for (var x = 17; x > 0; x--)
  299. {
  300. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  301. }
  302. Application.LayoutAndDraw ();
  303. looksLike =
  304. @"
  305. 11111│2222│3333│44│555555
  306. │ │ │ │
  307. │ │ │ │
  308. │ │ │ │
  309. ";
  310. DriverAssert.AssertDriverContentsAre (looksLike, output);
  311. for (var x = 20; x < 24; x++)
  312. {
  313. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  314. }
  315. for (var x = 24; x < 100; x++)
  316. {
  317. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  318. }
  319. Application.LayoutAndDraw ();
  320. looksLike =
  321. @"
  322. 11111│2222│3333│4444444│5
  323. │ │ │ │
  324. │ │ │ │
  325. │ │ │ │
  326. ";
  327. DriverAssert.AssertDriverContentsAre (looksLike, output);
  328. }
  329. [Fact]
  330. [AutoInitShutdown]
  331. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossBorder ()
  332. {
  333. TileView tv = Get5x1TilesView ();
  334. Application.LayoutAndDraw ();
  335. var looksLike =
  336. @"
  337. ┌────┬────┬────┬────┬───┐
  338. │1111│2222│3333│4444│555│
  339. │ │ │ │ │ │
  340. └────┴────┴────┴────┴───┘
  341. ";
  342. DriverAssert.AssertDriverContentsAre (looksLike, output);
  343. for (var x = 5; x > 0; x--)
  344. {
  345. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  346. }
  347. Assert.False (tv.SetSplitterPos (0, 0));
  348. Application.LayoutAndDraw ();
  349. looksLike =
  350. @"
  351. ┌┬────────┬────┬────┬───┐
  352. ││22222222│3333│4444│555│
  353. ││ │ │ │ │
  354. └┴────────┴────┴────┴───┘
  355. ";
  356. DriverAssert.AssertDriverContentsAre (looksLike, output);
  357. for (var x = 6; x < 10; x++)
  358. {
  359. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  360. }
  361. for (var x = 10; x < 100; x++)
  362. {
  363. // These values would result in the first splitter moving past
  364. // the second splitter so are not allowed
  365. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  366. }
  367. Application.LayoutAndDraw ();
  368. looksLike =
  369. @"
  370. ┌────────┬┬────┬────┬───┐
  371. │11111111││3333│4444│555│
  372. │ ││ │ │ │
  373. └────────┴┴────┴────┴───┘
  374. ";
  375. DriverAssert.AssertDriverContentsAre (looksLike, output);
  376. }
  377. [Fact]
  378. [AutoInitShutdown]
  379. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossBorder_NoBorder ()
  380. {
  381. TileView tv = Get5x1TilesView (false);
  382. Application.LayoutAndDraw ();
  383. var looksLike =
  384. @"
  385. 11111│2222│3333│4444│5555
  386. │ │ │ │
  387. │ │ │ │
  388. │ │ │ │
  389. ";
  390. DriverAssert.AssertDriverContentsAre (looksLike, output);
  391. for (var x = 5; x >= 0; x--)
  392. {
  393. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  394. }
  395. Application.LayoutAndDraw ();
  396. looksLike =
  397. @"
  398. │222222222│3333│4444│5555
  399. │ │ │ │
  400. │ │ │ │
  401. │ │ │ │
  402. ";
  403. DriverAssert.AssertDriverContentsAre (looksLike, output);
  404. for (var x = 6; x < 10; x++)
  405. {
  406. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  407. }
  408. for (var x = 10; x < 100; x++)
  409. {
  410. // These values would result in the first splitter moving past
  411. // the second splitter so are not allowed
  412. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  413. }
  414. Application.LayoutAndDraw ();
  415. looksLike =
  416. @"
  417. 111111111││3333│4444│5555
  418. ││ │ │
  419. ││ │ │
  420. ││ │ │
  421. ";
  422. DriverAssert.AssertDriverContentsAre (looksLike, output);
  423. }
  424. [Fact]
  425. [AutoInitShutdown]
  426. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOverNeighbours ()
  427. {
  428. TileView tv = Get5x1TilesView ();
  429. Application.LayoutAndDraw ();
  430. var looksLike =
  431. @"
  432. ┌────┬────┬────┬────┬───┐
  433. │1111│2222│3333│4444│555│
  434. │ │ │ │ │ │
  435. └────┴────┴────┴────┴───┘
  436. ";
  437. DriverAssert.AssertDriverContentsAre (looksLike, output);
  438. for (var x = 10; x > 5; x--)
  439. {
  440. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  441. }
  442. for (var x = 5; x > 0; x--)
  443. {
  444. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  445. }
  446. Application.LayoutAndDraw ();
  447. looksLike =
  448. @"
  449. ┌────┬┬────────┬────┬───┐
  450. │1111││33333333│4444│555│
  451. │ ││ │ │ │
  452. └────┴┴────────┴────┴───┘
  453. ";
  454. DriverAssert.AssertDriverContentsAre (looksLike, output);
  455. for (var x = 10; x < 15; x++)
  456. {
  457. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  458. }
  459. for (var x = 15; x < 25; x++)
  460. {
  461. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  462. }
  463. Application.LayoutAndDraw ();
  464. looksLike =
  465. @"
  466. ┌────┬────────┬┬────┬───┐
  467. │1111│22222222││4444│555│
  468. │ │ ││ │ │
  469. └────┴────────┴┴────┴───┘
  470. ";
  471. DriverAssert.AssertDriverContentsAre (looksLike, output);
  472. }
  473. [Fact]
  474. [AutoInitShutdown]
  475. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOverNeighbours_NoBorder ()
  476. {
  477. TileView tv = Get5x1TilesView (false);
  478. Application.LayoutAndDraw ();
  479. var looksLike =
  480. @"
  481. 11111│2222│3333│4444│5555
  482. │ │ │ │
  483. │ │ │ │
  484. │ │ │ │
  485. ";
  486. DriverAssert.AssertDriverContentsAre (looksLike, output);
  487. for (var x = 10; x > 5; x--)
  488. {
  489. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  490. }
  491. for (var x = 5; x > 0; x--)
  492. {
  493. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  494. }
  495. Application.LayoutAndDraw ();
  496. looksLike =
  497. @"
  498. 11111││33333333│4444│5555
  499. ││ │ │
  500. ││ │ │
  501. ││ │ │
  502. ";
  503. DriverAssert.AssertDriverContentsAre (looksLike, output);
  504. for (var x = 10; x < 15; x++)
  505. {
  506. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  507. }
  508. for (var x = 15; x < 25; x++)
  509. {
  510. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  511. }
  512. Application.LayoutAndDraw ();
  513. looksLike =
  514. @"
  515. 11111│22222222││4444│5555
  516. │ ││ │
  517. │ ││ │
  518. │ ││ │
  519. ";
  520. DriverAssert.AssertDriverContentsAre (looksLike, output);
  521. }
  522. [Fact]
  523. [AutoInitShutdown]
  524. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOverNeighbours ()
  525. {
  526. TileView tv = Get5x1TilesView ();
  527. Application.LayoutAndDraw ();
  528. var looksLike =
  529. @"
  530. ┌────┬────┬────┬────┬───┐
  531. │1111│2222│3333│4444│555│
  532. │ │ │ │ │ │
  533. └────┴────┴────┴────┴───┘
  534. ";
  535. DriverAssert.AssertDriverContentsAre (looksLike, output);
  536. for (var x = 20; x > 15; x--)
  537. {
  538. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  539. }
  540. for (var x = 15; x > 0; x--)
  541. {
  542. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  543. }
  544. Application.LayoutAndDraw ();
  545. looksLike =
  546. @"
  547. ┌────┬────┬────┬┬───────┐
  548. │1111│2222│3333││5555555│
  549. │ │ │ ││ │
  550. └────┴────┴────┴┴───────┘
  551. ";
  552. DriverAssert.AssertDriverContentsAre (looksLike, output);
  553. for (var x = 20; x < 24; x++)
  554. {
  555. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  556. }
  557. for (var x = 24; x < 100; x++)
  558. {
  559. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  560. }
  561. Application.LayoutAndDraw ();
  562. looksLike =
  563. @"
  564. ┌────┬────┬────┬───────┬┐
  565. │1111│2222│3333│4444444││
  566. │ │ │ │ ││
  567. └────┴────┴────┴───────┴┘
  568. ";
  569. DriverAssert.AssertDriverContentsAre (looksLike, output);
  570. }
  571. [Fact]
  572. [AutoInitShutdown]
  573. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOverNeighbours_NoBorder ()
  574. {
  575. TileView tv = Get5x1TilesView (false);
  576. Application.LayoutAndDraw ();
  577. var looksLike =
  578. @"
  579. 11111│2222│3333│4444│5555
  580. │ │ │ │
  581. │ │ │ │
  582. │ │ │ │
  583. ";
  584. DriverAssert.AssertDriverContentsAre (looksLike, output);
  585. for (var x = 20; x > 15; x--)
  586. {
  587. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  588. }
  589. for (var x = 15; x > 0; x--)
  590. {
  591. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  592. }
  593. Application.LayoutAndDraw ();
  594. looksLike =
  595. @"
  596. 11111│2222│3333││55555555
  597. │ │ ││
  598. │ │ ││
  599. │ │ ││
  600. ";
  601. DriverAssert.AssertDriverContentsAre (looksLike, output);
  602. for (var x = 20; x < 25; x++)
  603. {
  604. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  605. }
  606. for (var x = 25; x < 100; x++)
  607. {
  608. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  609. }
  610. Application.LayoutAndDraw ();
  611. looksLike =
  612. @"
  613. 11111│2222│3333│44444444│
  614. │ │ │ │
  615. │ │ │ │
  616. │ │ │ │
  617. ";
  618. DriverAssert.AssertDriverContentsAre (looksLike, output);
  619. }
  620. [Fact]
  621. public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringInsertTile ()
  622. {
  623. TileView tv = GetTileView (20, 10);
  624. var myReusableView = new DisposeCounter ();
  625. // I want my view in the first tile
  626. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  627. Assert.Equal (0, myReusableView.DisposalCount);
  628. // I've changed my mind, I want 3 tiles now
  629. tv.InsertTile (0);
  630. tv.InsertTile (2);
  631. // but I still want my view in the first tile
  632. // BUGBUG: Adding a view twice is not legit
  633. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  634. Assert.Multiple (
  635. () => Assert.Equal (0, myReusableView.DisposalCount),
  636. () =>
  637. {
  638. tv.Dispose ();
  639. Assert.True (myReusableView.DisposalCount >= 1);
  640. }
  641. );
  642. }
  643. [Fact]
  644. public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringRebuildForTileCount ()
  645. {
  646. TileView tv = GetTileView (20, 10);
  647. var myReusableView = new DisposeCounter ();
  648. // I want my view in the first tile
  649. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  650. Assert.Equal (0, myReusableView.DisposalCount);
  651. // I've changed my mind, I want 3 tiles now
  652. tv.RebuildForTileCount (3);
  653. // but I still want my view in the first tile
  654. // BUGBUG: Adding a view twice is not legit
  655. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  656. Assert.Multiple (
  657. () => Assert.Equal (0, myReusableView.DisposalCount),
  658. () =>
  659. {
  660. tv.Dispose ();
  661. Assert.Equal (1, myReusableView.DisposalCount);
  662. }
  663. );
  664. Assert.NotNull (Application.Top);
  665. Application.Top.Dispose ();
  666. Application.Shutdown ();
  667. }
  668. [Theory]
  669. [InlineData (0)]
  670. [InlineData (1)]
  671. public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringRemoveTile (int idx)
  672. {
  673. TileView tv = GetTileView (20, 10);
  674. var myReusableView = new DisposeCounter ();
  675. // I want my view in the first tile
  676. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  677. Assert.Equal (0, myReusableView.DisposalCount);
  678. tv.RemoveTile (idx);
  679. // but I still want my view in the first tile
  680. // BUGBUG: Adding a view twice is not legit
  681. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  682. Assert.Multiple (
  683. () => Assert.Equal (0, myReusableView.DisposalCount),
  684. () =>
  685. {
  686. tv.Dispose ();
  687. Assert.True (myReusableView.DisposalCount >= 1);
  688. }
  689. );
  690. Assert.NotNull (Application.Top);
  691. Application.Top.Dispose ();
  692. Application.Shutdown ();
  693. }
  694. [Fact]
  695. [AutoInitShutdown]
  696. public void TestNestedContainer2LeftAnd1Right_RendersNicely ()
  697. {
  698. TileView tileView = GetNestedContainer2Left1Right (false);
  699. Assert.Equal (20, tileView.Frame.Width);
  700. Assert.Equal (10, tileView.Tiles.ElementAt (0).ContentView.Frame.Width);
  701. Assert.Equal (9, tileView.Tiles.ElementAt (1).ContentView.Frame.Width);
  702. Assert.IsType<TileView> (tileView.Tiles.ElementAt (0).ContentView);
  703. var left = (TileView)tileView.Tiles.ElementAt (0).ContentView;
  704. Assert.Same (left.SuperView, tileView);
  705. Assert.Equal (2, left.Tiles.ElementAt (0).ContentView.SubViews.Count);
  706. Assert.IsType<Label> (left.Tiles.ElementAt (0).ContentView.SubViews.ElementAt (0));
  707. Assert.IsType<Label> (left.Tiles.ElementAt (0).ContentView.SubViews.ElementAt (1));
  708. var onesTop = (Label)left.Tiles.ElementAt (0).ContentView.SubViews.ElementAt (0);
  709. var onesBottom = (Label)left.Tiles.ElementAt (0).ContentView.SubViews.ElementAt (1);
  710. Assert.Same (left.Tiles.ElementAt (0).ContentView, onesTop.SuperView);
  711. Assert.Same (left.Tiles.ElementAt (0).ContentView, onesBottom.SuperView);
  712. Assert.Equal (10, onesTop.Frame.Width);
  713. Assert.Equal (10, onesBottom.Frame.Width);
  714. tileView.Draw ();
  715. var looksLike =
  716. @"
  717. 1111111111│222222222
  718. 1111111111│222222222
  719. ──────────┤
  720. │";
  721. DriverAssert.AssertDriverContentsAre (looksLike, output);
  722. }
  723. [Fact]
  724. [AutoInitShutdown]
  725. public void TestNestedContainer3RightAnd1Down_RendersNicely ()
  726. {
  727. TileView tileView = GetNestedContainer3Right1Down (false);
  728. tileView.Draw ();
  729. var looksLike =
  730. @"
  731. 111111│222222│333333
  732. 111111│222222│333333
  733. 111111│222222│333333
  734. 111111│222222│333333
  735. 111111│222222│333333
  736. 111111│222222├──────
  737. 111111│222222│444444
  738. 111111│222222│444444
  739. 111111│222222│444444
  740. 111111│222222│444444
  741. ";
  742. DriverAssert.AssertDriverContentsAre (looksLike, output);
  743. // It looks good but lets double check the measurements incase
  744. // anything is sticking out but drawn over
  745. // 3 panels + 2 splitters
  746. Assert.Equal (5, tileView.SubViews.Count);
  747. // Check X and Widths of Tiles
  748. Assert.Equal (0, tileView.Tiles.ElementAt (0).ContentView.Frame.X);
  749. Assert.Equal (6, tileView.Tiles.ElementAt (0).ContentView.Frame.Width);
  750. Assert.Equal (7, tileView.Tiles.ElementAt (1).ContentView.Frame.X);
  751. Assert.Equal (6, tileView.Tiles.ElementAt (1).ContentView.Frame.Width);
  752. Assert.Equal (14, tileView.Tiles.ElementAt (2).ContentView.Frame.X);
  753. Assert.Equal (6, tileView.Tiles.ElementAt (2).ContentView.Frame.Width);
  754. // Check Y and Heights of Tiles
  755. Assert.Equal (0, tileView.Tiles.ElementAt (0).ContentView.Frame.Y);
  756. Assert.Equal (10, tileView.Tiles.ElementAt (0).ContentView.Frame.Height);
  757. Assert.Equal (0, tileView.Tiles.ElementAt (1).ContentView.Frame.Y);
  758. Assert.Equal (10, tileView.Tiles.ElementAt (1).ContentView.Frame.Height);
  759. Assert.Equal (0, tileView.Tiles.ElementAt (2).ContentView.Frame.Y);
  760. Assert.Equal (10, tileView.Tiles.ElementAt (2).ContentView.Frame.Height);
  761. // Check Sub containers in last panel
  762. var subSplit = (TileView)tileView.Tiles.ElementAt (2).ContentView;
  763. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.X);
  764. Assert.Equal (6, subSplit.Tiles.ElementAt (0).ContentView.Frame.Width);
  765. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.Y);
  766. Assert.Equal (5, subSplit.Tiles.ElementAt (0).ContentView.Frame.Height);
  767. //Assert.IsType<TextView> (subSplit.Tiles.ElementAt (0).ContentView.SubViews.Single ());
  768. Assert.Equal (0, subSplit.Tiles.ElementAt (1).ContentView.Frame.X);
  769. Assert.Equal (6, subSplit.Tiles.ElementAt (1).ContentView.Frame.Width);
  770. Assert.Equal (6, subSplit.Tiles.ElementAt (1).ContentView.Frame.Y);
  771. Assert.Equal (4, subSplit.Tiles.ElementAt (1).ContentView.Frame.Height);
  772. //Assert.IsType<TextView> (subSplit.Tiles.ElementAt (1).ContentView.SubViews.Single ());
  773. }
  774. [Fact]
  775. [AutoInitShutdown]
  776. public void TestNestedContainer3RightAnd1Down_TileVisibility_WithBorder ()
  777. {
  778. TileView tileView = GetNestedContainer3Right1Down (true);
  779. Application.LayoutAndDraw ();
  780. var looksLike =
  781. @"
  782. ┌─────┬──────┬─────┐
  783. │11111│222222│33333│
  784. │11111│222222│33333│
  785. │11111│222222│33333│
  786. │11111│222222│33333│
  787. │11111│222222├─────┤
  788. │11111│222222│44444│
  789. │11111│222222│44444│
  790. │11111│222222│44444│
  791. └─────┴──────┴─────┘";
  792. DriverAssert.AssertDriverContentsAre (looksLike, output);
  793. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  794. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  795. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  796. Application.LayoutAndDraw ();
  797. looksLike =
  798. @"
  799. ┌────────────┬─────┐
  800. │222222222222│33333│
  801. │222222222222│33333│
  802. │222222222222│33333│
  803. │222222222222│33333│
  804. │222222222222├─────┤
  805. │222222222222│44444│
  806. │222222222222│44444│
  807. │222222222222│44444│
  808. └────────────┴─────┘";
  809. DriverAssert.AssertDriverContentsAre (looksLike, output);
  810. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  811. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  812. Application.LayoutAndDraw ();
  813. looksLike =
  814. @"
  815. ┌────────────┬─────┐
  816. │111111111111│33333│
  817. │111111111111│33333│
  818. │111111111111│33333│
  819. │111111111111│33333│
  820. │111111111111├─────┤
  821. │111111111111│44444│
  822. │111111111111│44444│
  823. │111111111111│44444│
  824. └────────────┴─────┘";
  825. DriverAssert.AssertDriverContentsAre (looksLike, output);
  826. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  827. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  828. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  829. Application.LayoutAndDraw ();
  830. looksLike =
  831. @"
  832. ┌─────┬────────────┐
  833. │11111│222222222222│
  834. │11111│222222222222│
  835. │11111│222222222222│
  836. │11111│222222222222│
  837. │11111│222222222222│
  838. │11111│222222222222│
  839. │11111│222222222222│
  840. │11111│222222222222│
  841. └─────┴────────────┘";
  842. DriverAssert.AssertDriverContentsAre (looksLike, output);
  843. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  844. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  845. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  846. Application.LayoutAndDraw ();
  847. looksLike =
  848. @"
  849. ┌──────────────────┐
  850. │111111111111111111│
  851. │111111111111111111│
  852. │111111111111111111│
  853. │111111111111111111│
  854. │111111111111111111│
  855. │111111111111111111│
  856. │111111111111111111│
  857. │111111111111111111│
  858. └──────────────────┘";
  859. DriverAssert.AssertDriverContentsAre (looksLike, output);
  860. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  861. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  862. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  863. Application.LayoutAndDraw ();
  864. looksLike =
  865. @"
  866. ┌──────────────────┐
  867. │222222222222222222│
  868. │222222222222222222│
  869. │222222222222222222│
  870. │222222222222222222│
  871. │222222222222222222│
  872. │222222222222222222│
  873. │222222222222222222│
  874. │222222222222222222│
  875. └──────────────────┘";
  876. DriverAssert.AssertDriverContentsAre (looksLike, output);
  877. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  878. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  879. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  880. Application.LayoutAndDraw ();
  881. looksLike =
  882. @"
  883. ┌──────────────────┐
  884. │333333333333333333│
  885. │333333333333333333│
  886. │333333333333333333│
  887. │333333333333333333│
  888. ├──────────────────┤
  889. │444444444444444444│
  890. │444444444444444444│
  891. │444444444444444444│
  892. └──────────────────┘";
  893. DriverAssert.AssertDriverContentsAre (looksLike, output);
  894. DriverAssert.AssertDriverContentsAre (looksLike, output);
  895. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  896. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  897. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  898. Application.LayoutAndDraw ();
  899. looksLike =
  900. @"
  901. ┌──────────────────┐
  902. │ │
  903. │ │
  904. │ │
  905. │ │
  906. │ │
  907. │ │
  908. │ │
  909. │ │
  910. └──────────────────┘";
  911. DriverAssert.AssertDriverContentsAre (looksLike, output);
  912. }
  913. [Fact]
  914. [AutoInitShutdown]
  915. public void TestNestedContainer3RightAnd1Down_TileVisibility_WithoutBorder ()
  916. {
  917. TileView tileView = GetNestedContainer3Right1Down (false);
  918. Application.LayoutAndDraw ();
  919. var looksLike =
  920. @"
  921. 111111│222222│333333
  922. 111111│222222│333333
  923. 111111│222222│333333
  924. 111111│222222│333333
  925. 111111│222222│333333
  926. 111111│222222├──────
  927. 111111│222222│444444
  928. 111111│222222│444444
  929. 111111│222222│444444
  930. 111111│222222│444444";
  931. DriverAssert.AssertDriverContentsAre (looksLike, output);
  932. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  933. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  934. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  935. Application.LayoutAndDraw ();
  936. looksLike =
  937. @"
  938. 2222222222222│333333
  939. 2222222222222│333333
  940. 2222222222222│333333
  941. 2222222222222│333333
  942. 2222222222222│333333
  943. 2222222222222├──────
  944. 2222222222222│444444
  945. 2222222222222│444444
  946. 2222222222222│444444
  947. 2222222222222│444444";
  948. DriverAssert.AssertDriverContentsAre (looksLike, output);
  949. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  950. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  951. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  952. Application.LayoutAndDraw ();
  953. looksLike =
  954. @"
  955. 1111111111111│333333
  956. 1111111111111│333333
  957. 1111111111111│333333
  958. 1111111111111│333333
  959. 1111111111111│333333
  960. 1111111111111├──────
  961. 1111111111111│444444
  962. 1111111111111│444444
  963. 1111111111111│444444
  964. 1111111111111│444444";
  965. DriverAssert.AssertDriverContentsAre (looksLike, output);
  966. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  967. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  968. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  969. Application.LayoutAndDraw ();
  970. looksLike =
  971. @"
  972. 111111│2222222222222
  973. 111111│2222222222222
  974. 111111│2222222222222
  975. 111111│2222222222222
  976. 111111│2222222222222
  977. 111111│2222222222222
  978. 111111│2222222222222
  979. 111111│2222222222222
  980. 111111│2222222222222
  981. 111111│2222222222222";
  982. DriverAssert.AssertDriverContentsAre (looksLike, output);
  983. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  984. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  985. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  986. Application.LayoutAndDraw ();
  987. looksLike =
  988. @"
  989. 11111111111111111111
  990. 11111111111111111111
  991. 11111111111111111111
  992. 11111111111111111111
  993. 11111111111111111111
  994. 11111111111111111111
  995. 11111111111111111111
  996. 11111111111111111111
  997. 11111111111111111111
  998. 11111111111111111111";
  999. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1000. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1001. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  1002. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  1003. Application.LayoutAndDraw ();
  1004. looksLike =
  1005. @"
  1006. 22222222222222222222
  1007. 22222222222222222222
  1008. 22222222222222222222
  1009. 22222222222222222222
  1010. 22222222222222222222
  1011. 22222222222222222222
  1012. 22222222222222222222
  1013. 22222222222222222222
  1014. 22222222222222222222
  1015. 22222222222222222222";
  1016. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1017. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1018. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  1019. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  1020. Application.LayoutAndDraw ();
  1021. looksLike =
  1022. @"
  1023. 33333333333333333333
  1024. 33333333333333333333
  1025. 33333333333333333333
  1026. 33333333333333333333
  1027. 33333333333333333333
  1028. ────────────────────
  1029. 44444444444444444444
  1030. 44444444444444444444
  1031. 44444444444444444444
  1032. 44444444444444444444";
  1033. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1034. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1035. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1036. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  1037. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  1038. Application.LayoutAndDraw ();
  1039. looksLike =
  1040. @"
  1041. ";
  1042. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1043. }
  1044. [Fact]
  1045. [AutoInitShutdown]
  1046. public void TestNestedContainer3RightAnd1Down_TitleDoesNotOverspill ()
  1047. {
  1048. TileView tileView = GetNestedContainer3Right1Down (true, true, 1);
  1049. Application.LayoutAndDraw ();
  1050. var looksLike =
  1051. @"
  1052. ┌ T1 ─┬ T3 ──┬ T2 ─┐
  1053. │11111│333333│22222│
  1054. │11111│333333│22222│
  1055. │11111│333333│22222│
  1056. │11111│333333│22222│
  1057. │11111├ T4 ──┤22222│
  1058. │11111│444444│22222│
  1059. │11111│444444│22222│
  1060. │11111│444444│22222│
  1061. └─────┴──────┴─────┘";
  1062. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1063. }
  1064. [Fact]
  1065. [AutoInitShutdown]
  1066. public void TestNestedContainer3RightAnd1Down_TitleTriesToOverspill ()
  1067. {
  1068. TileView tileView = GetNestedContainer3Right1Down (true, true, 1);
  1069. tileView.Tiles.ElementAt (0).Title = new ('x', 100);
  1070. ((TileView)tileView.Tiles.ElementAt (1).ContentView)
  1071. .Tiles.ElementAt (1)
  1072. .Title = new ('y', 100);
  1073. Application.LayoutAndDraw ();
  1074. var looksLike =
  1075. @"
  1076. ┌ xxxx┬ T3 ──┬ T2 ─┐
  1077. │11111│333333│22222│
  1078. │11111│333333│22222│
  1079. │11111│333333│22222│
  1080. │11111│333333│22222│
  1081. │11111├ yyyyy┤22222│
  1082. │11111│444444│22222│
  1083. │11111│444444│22222│
  1084. │11111│444444│22222│
  1085. └─────┴──────┴─────┘";
  1086. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1087. }
  1088. [Fact]
  1089. [AutoInitShutdown]
  1090. public void TestNestedContainer3RightAnd1Down_WithBorder_RemovingTiles ()
  1091. {
  1092. TileView tileView = GetNestedContainer3Right1Down (true);
  1093. Application.LayoutAndDraw ();
  1094. var looksLike =
  1095. @"
  1096. ┌─────┬──────┬─────┐
  1097. │11111│222222│33333│
  1098. │11111│222222│33333│
  1099. │11111│222222│33333│
  1100. │11111│222222│33333│
  1101. │11111│222222├─────┤
  1102. │11111│222222│44444│
  1103. │11111│222222│44444│
  1104. │11111│222222│44444│
  1105. └─────┴──────┴─────┘";
  1106. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1107. Tile toRemove = tileView.Tiles.ElementAt (1);
  1108. Tile removed = tileView.RemoveTile (1);
  1109. Assert.Same (toRemove, removed);
  1110. Assert.DoesNotContain (removed, tileView.Tiles);
  1111. Application.LayoutAndDraw ();
  1112. looksLike =
  1113. @"
  1114. ┌─────────┬────────┐
  1115. │111111111│33333333│
  1116. │111111111│33333333│
  1117. │111111111│33333333│
  1118. │111111111│33333333│
  1119. │111111111├────────┤
  1120. │111111111│44444444│
  1121. │111111111│44444444│
  1122. │111111111│44444444│
  1123. └─────────┴────────┘";
  1124. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1125. // cannot remove at this index because there is only one horizontal tile left
  1126. Assert.Null (tileView.RemoveTile (2));
  1127. tileView.RemoveTile (0);
  1128. Application.LayoutAndDraw ();
  1129. looksLike =
  1130. @"
  1131. ┌──────────────────┐
  1132. │333333333333333333│
  1133. │333333333333333333│
  1134. │333333333333333333│
  1135. │333333333333333333│
  1136. ├──────────────────┤
  1137. │444444444444444444│
  1138. │444444444444444444│
  1139. │444444444444444444│
  1140. └──────────────────┘";
  1141. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1142. Assert.NotNull (tileView.RemoveTile (0));
  1143. Application.LayoutAndDraw ();
  1144. looksLike =
  1145. @"
  1146. ┌──────────────────┐
  1147. │ │
  1148. │ │
  1149. │ │
  1150. │ │
  1151. │ │
  1152. │ │
  1153. │ │
  1154. │ │
  1155. └──────────────────┘";
  1156. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1157. // cannot remove
  1158. Assert.Null (tileView.RemoveTile (0));
  1159. }
  1160. [Fact]
  1161. [AutoInitShutdown]
  1162. public void TestNestedContainer3RightAnd1Down_WithBorder_RendersNicely ()
  1163. {
  1164. TileView tileView = GetNestedContainer3Right1Down (true);
  1165. Application.LayoutAndDraw ();
  1166. var looksLike =
  1167. @"
  1168. ┌─────┬──────┬─────┐
  1169. │11111│222222│33333│
  1170. │11111│222222│33333│
  1171. │11111│222222│33333│
  1172. │11111│222222│33333│
  1173. │11111│222222├─────┤
  1174. │11111│222222│44444│
  1175. │11111│222222│44444│
  1176. │11111│222222│44444│
  1177. └─────┴──────┴─────┘";
  1178. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1179. // It looks good but lets double check the measurements incase
  1180. // anything is sticking out but drawn over
  1181. // 3 panels + 2 splitters
  1182. Assert.Equal (5, tileView.SubViews.Count);
  1183. // Check X and Widths of Tiles
  1184. Assert.Equal (1, tileView.Tiles.ElementAt (0).ContentView.Frame.X);
  1185. Assert.Equal (5, tileView.Tiles.ElementAt (0).ContentView.Frame.Width);
  1186. Assert.Equal (7, tileView.Tiles.ElementAt (1).ContentView.Frame.X);
  1187. Assert.Equal (6, tileView.Tiles.ElementAt (1).ContentView.Frame.Width);
  1188. Assert.Equal (14, tileView.Tiles.ElementAt (2).ContentView.Frame.X);
  1189. Assert.Equal (5, tileView.Tiles.ElementAt (2).ContentView.Frame.Width);
  1190. // Check Y and Heights of Tiles
  1191. Assert.Equal (1, tileView.Tiles.ElementAt (0).ContentView.Frame.Y);
  1192. Assert.Equal (8, tileView.Tiles.ElementAt (0).ContentView.Frame.Height);
  1193. Assert.Equal (1, tileView.Tiles.ElementAt (1).ContentView.Frame.Y);
  1194. Assert.Equal (8, tileView.Tiles.ElementAt (1).ContentView.Frame.Height);
  1195. Assert.Equal (1, tileView.Tiles.ElementAt (2).ContentView.Frame.Y);
  1196. Assert.Equal (8, tileView.Tiles.ElementAt (2).ContentView.Frame.Height);
  1197. // Check Sub containers in last panel
  1198. var subSplit = (TileView)tileView.Tiles.ElementAt (2).ContentView;
  1199. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.X);
  1200. Assert.Equal (5, subSplit.Tiles.ElementAt (0).ContentView.Frame.Width);
  1201. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.Y);
  1202. Assert.Equal (4, subSplit.Tiles.ElementAt (0).ContentView.Frame.Height);
  1203. //Assert.IsType<TextView> (subSplit.Tiles.ElementAt (0).ContentView.SubViews.Single ());
  1204. Assert.Equal (0, subSplit.Tiles.ElementAt (1).ContentView.Frame.X);
  1205. Assert.Equal (5, subSplit.Tiles.ElementAt (1).ContentView.Frame.Width);
  1206. Assert.Equal (5, subSplit.Tiles.ElementAt (1).ContentView.Frame.Y);
  1207. Assert.Equal (3, subSplit.Tiles.ElementAt (1).ContentView.Frame.Height);
  1208. //Assert.IsType<TextView> (subSplit.Tiles.ElementAt (1).ContentView.SubViews.Single ());
  1209. }
  1210. [Fact]
  1211. [AutoInitShutdown]
  1212. public void TestNestedContainer3RightAnd1Down_WithTitledBorder_RendersNicely ()
  1213. {
  1214. TileView tileView = GetNestedContainer3Right1Down (true, true);
  1215. tileView.Draw ();
  1216. var looksLike =
  1217. @"
  1218. ┌ T1 ─┬ T2 ──┬ T3 ─┐
  1219. │11111│222222│33333│
  1220. │11111│222222│33333│
  1221. │11111│222222│33333│
  1222. │11111│222222│33333│
  1223. │11111│222222├ T4 ─┤
  1224. │11111│222222│44444│
  1225. │11111│222222│44444│
  1226. │11111│222222│44444│
  1227. └─────┴──────┴─────┘";
  1228. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1229. }
  1230. [Fact]
  1231. [AutoInitShutdown]
  1232. public void TestNestedNonRoots_OnlyOneRoot_OnlyRootCanHaveBorders ()
  1233. {
  1234. var tv = new TileView
  1235. {
  1236. Width = 10, Height = 5, LineStyle = LineStyle.Single
  1237. };
  1238. tv.TrySplitTile (1, 2, out TileView tv2);
  1239. // tv2.Scheme = new ();
  1240. tv2.LineStyle = LineStyle.Single;
  1241. tv2.Orientation = Orientation.Horizontal;
  1242. Assert.True (tv.IsRootTileView ());
  1243. var top = new Toplevel ();
  1244. top.Add (tv);
  1245. tv.BeginInit ();
  1246. tv.EndInit ();
  1247. tv.LayoutSubViews ();
  1248. tv.LayoutSubViews ();
  1249. tv.Tiles.ElementAt (1).ContentView.LayoutSubViews ();
  1250. tv2.LayoutSubViews ();
  1251. // tv2 is not considered a root because
  1252. // it was created via TrySplitTile so it
  1253. // will have its lines joined to
  1254. // parent and cannot have its own border
  1255. Assert.False (tv2.IsRootTileView ());
  1256. tv.Draw ();
  1257. var looksLike =
  1258. @"
  1259. ┌────┬───┐
  1260. │ │ │
  1261. │ ├───┤
  1262. │ │ │
  1263. └────┴───┘
  1264. ";
  1265. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1266. }
  1267. [Fact]
  1268. [AutoInitShutdown]
  1269. public void TestNestedRoots_BothRoots_BothCanHaveBorders ()
  1270. {
  1271. var tv = new TileView
  1272. {
  1273. Width = 10, Height = 5, LineStyle = LineStyle.Single
  1274. };
  1275. var tv2 = new TileView
  1276. {
  1277. Width = Dim.Fill (),
  1278. Height = Dim.Fill (),
  1279. LineStyle = LineStyle.Single,
  1280. Orientation = Orientation.Horizontal
  1281. };
  1282. Assert.True (tv.IsRootTileView ());
  1283. tv.Tiles.ElementAt (1).ContentView.Add (tv2);
  1284. var top = new Toplevel ();
  1285. top.Add (tv);
  1286. tv.BeginInit ();
  1287. tv.EndInit ();
  1288. tv.LayoutSubViews ();
  1289. tv.LayoutSubViews ();
  1290. tv.Tiles.ElementAt (1).ContentView.LayoutSubViews ();
  1291. tv2.LayoutSubViews ();
  1292. // tv2 is still considered a root because
  1293. // it was manually created by API user. That
  1294. // means it will not have its lines joined to
  1295. // parents and it is permitted to have a border
  1296. Assert.True (tv2.IsRootTileView ());
  1297. tv.Draw ();
  1298. var looksLike =
  1299. @"
  1300. ┌────┬───┐
  1301. │ │┌─┐│
  1302. │ │├─┤│
  1303. │ │└─┘│
  1304. └────┴───┘
  1305. ";
  1306. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1307. }
  1308. [Fact]
  1309. [AutoInitShutdown]
  1310. public void TestTileView_CannotSetSplitterPosToFuncEtc ()
  1311. {
  1312. TileView tileView = Get11By3TileView ();
  1313. var ex = Assert.Throws<ArgumentException> (() => tileView.SetSplitterPos (0, Pos.Right (tileView)));
  1314. Assert.Equal ("Only Percent and Absolute values are supported. Passed value was PosView", ex.Message);
  1315. ex = Assert.Throws<ArgumentException> (() => tileView.SetSplitterPos (0, Pos.Func (_ => 1)));
  1316. Assert.Equal ("Only Percent and Absolute values are supported. Passed value was PosFunc", ex.Message);
  1317. // Also not allowed because this results in a PosCombine
  1318. ex = Assert.Throws<ArgumentException> (() => tileView.SetSplitterPos (0, Pos.Percent (50) - 1));
  1319. Assert.Equal (
  1320. "Only Percent and Absolute values are supported. Passed value was PosCombine",
  1321. ex.Message
  1322. );
  1323. }
  1324. [Fact]
  1325. [AutoInitShutdown]
  1326. public void TestTileView_Horizontal ()
  1327. {
  1328. TileView tileView = Get11By3TileView (out LineView line);
  1329. tileView.Orientation = Orientation.Horizontal;
  1330. tileView.Layout ();
  1331. tileView.Draw ();
  1332. var looksLike =
  1333. @"
  1334. 11111111111
  1335. ───────────
  1336. 22222222222";
  1337. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1338. // Keyboard movement on splitter should have no effect if it is not focused
  1339. bool handled = tileView.NewKeyDownEvent (Key.CursorDown);
  1340. Assert.False (handled);
  1341. tileView.SetNeedsDraw ();
  1342. tileView.Draw ();
  1343. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1344. }
  1345. [Fact]
  1346. [AutoInitShutdown]
  1347. public void TestTileView_Horizontal_Focused ()
  1348. {
  1349. TileView tileView = Get11By3TileView (out LineView line);
  1350. tileView.Orientation = Orientation.Horizontal;
  1351. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1352. Assert.True (line.HasFocus);
  1353. Application.LayoutAndDraw ();
  1354. var looksLike =
  1355. @"
  1356. 11111111111
  1357. ─────◊─────
  1358. 22222222222";
  1359. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1360. // Now move splitter line down
  1361. tileView.NewKeyDownEvent (Key.CursorDown);
  1362. Application.LayoutAndDraw ();
  1363. looksLike =
  1364. @"
  1365. 11111111111
  1366. 11111111111
  1367. ─────◊─────";
  1368. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1369. // And 2 up
  1370. line.NewKeyDownEvent (Key.CursorUp);
  1371. Application.LayoutAndDraw ();
  1372. line.NewKeyDownEvent (Key.CursorUp);
  1373. Application.LayoutAndDraw ();
  1374. looksLike =
  1375. @"
  1376. ─────◊─────
  1377. 22222222222
  1378. 22222222222";
  1379. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1380. }
  1381. [Fact]
  1382. [AutoInitShutdown]
  1383. public void TestTileView_Horizontal_View1MinSize_Absolute ()
  1384. {
  1385. TileView tileView = Get11By3TileView (out LineView line);
  1386. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1387. tileView.Orientation = Orientation.Horizontal;
  1388. tileView.Tiles.ElementAt (0).MinSize = 1;
  1389. // 0 should not be allowed because it brings us below minimum size of View1
  1390. Assert.False (tileView.SetSplitterPos (0, 0));
  1391. // position should remain where it was, at 50%
  1392. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1393. Application.LayoutAndDraw ();
  1394. var looksLike =
  1395. @"
  1396. 11111111111
  1397. ─────◊─────
  1398. 22222222222";
  1399. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1400. // Now move splitter line down (allowed
  1401. line.NewKeyDownEvent (Key.CursorDown);
  1402. Application.LayoutAndDraw ();
  1403. looksLike =
  1404. @"
  1405. 11111111111
  1406. 11111111111
  1407. ─────◊─────";
  1408. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1409. // And up 2 (only 1 is allowed because of minimum size of 1 on view1)
  1410. line.NewKeyDownEvent (Key.CursorUp);
  1411. line.NewKeyDownEvent (Key.CursorUp);
  1412. tileView.SetNeedsDraw ();
  1413. Application.LayoutAndDraw ();
  1414. looksLike =
  1415. @"
  1416. 11111111111
  1417. ─────◊─────
  1418. 22222222222";
  1419. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1420. }
  1421. [Theory]
  1422. [AutoInitShutdown]
  1423. [InlineData (true)]
  1424. [InlineData (false)]
  1425. public void TestTileView_IndexOf (bool recursive)
  1426. {
  1427. var tv = new TileView ();
  1428. var lbl1 = new Label ();
  1429. var lbl2 = new Label ();
  1430. var frame = new FrameView ();
  1431. var sub = new Label ();
  1432. frame.Add (sub);
  1433. // IndexOf returns -1 when view not found
  1434. Assert.Equal (-1, tv.IndexOf (lbl1, recursive));
  1435. Assert.Equal (-1, tv.IndexOf (lbl2, recursive));
  1436. // IndexOf supports looking for Tile.View
  1437. Assert.Equal (0, tv.IndexOf (tv.Tiles.ElementAt (0).ContentView, recursive));
  1438. Assert.Equal (1, tv.IndexOf (tv.Tiles.ElementAt (1).ContentView, recursive));
  1439. // IndexOf supports looking for Tile.View.SubViews
  1440. tv.Tiles.ElementAt (0).ContentView.Add (lbl1);
  1441. Assert.Equal (0, tv.IndexOf (lbl1, recursive));
  1442. tv.Tiles.ElementAt (1).ContentView.Add (lbl2);
  1443. Assert.Equal (1, tv.IndexOf (lbl2, recursive));
  1444. // IndexOf supports looking deep into subviews only when
  1445. // the recursive true value is passed
  1446. tv.Tiles.ElementAt (1).ContentView.Add (frame);
  1447. if (recursive)
  1448. {
  1449. Assert.Equal (1, tv.IndexOf (sub, recursive));
  1450. }
  1451. else
  1452. {
  1453. Assert.Equal (-1, tv.IndexOf (sub, recursive));
  1454. }
  1455. }
  1456. [Fact]
  1457. [AutoInitShutdown]
  1458. public void TestTileView_InsertPanelAtEnd ()
  1459. {
  1460. TileView tileView = Get11By3TileView (out LineView line, true);
  1461. tileView.InsertTile (2);
  1462. tileView.Layout ();
  1463. tileView.Draw ();
  1464. // so should ignore the 2 distance and stick to 6
  1465. var looksLike =
  1466. @"
  1467. ┌──┬───┬──┐
  1468. │11│222│ │
  1469. └──┴───┴──┘";
  1470. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1471. }
  1472. [Fact]
  1473. [AutoInitShutdown]
  1474. public void TestTileView_InsertPanelAtStart ()
  1475. {
  1476. TileView tileView = Get11By3TileView (out LineView line, true);
  1477. tileView.InsertTile (0);
  1478. tileView.Layout ();
  1479. tileView.Draw ();
  1480. // so should ignore the 2 distance and stick to 6
  1481. var looksLike =
  1482. @"
  1483. ┌──┬───┬──┐
  1484. │ │111│22│
  1485. └──┴───┴──┘";
  1486. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1487. }
  1488. [Fact]
  1489. [AutoInitShutdown]
  1490. public void TestTileView_InsertPanelMiddle ()
  1491. {
  1492. TileView tileView = Get11By3TileView (out LineView line, true);
  1493. tileView.InsertTile (1);
  1494. tileView.Layout ();
  1495. tileView.Draw ();
  1496. // so should ignore the 2 distance and stick to 6
  1497. var looksLike =
  1498. @"
  1499. ┌──┬───┬──┐
  1500. │11│ │22│
  1501. └──┴───┴──┘";
  1502. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1503. }
  1504. [Fact]
  1505. [AutoInitShutdown]
  1506. public void TestTileView_Vertical ()
  1507. {
  1508. TileView tileView = Get11By3TileView (out LineView line);
  1509. tileView.Layout ();
  1510. tileView.Draw ();
  1511. var looksLike =
  1512. @"
  1513. 11111│22222
  1514. 11111│22222
  1515. │ ";
  1516. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1517. // Keyboard movement on splitter should have no effect if it is not focused
  1518. tileView.NewKeyDownEvent (Key.CursorRight);
  1519. tileView.SetNeedsDraw ();
  1520. tileView.Draw ();
  1521. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1522. }
  1523. [Fact]
  1524. [AutoInitShutdown]
  1525. public void TestTileView_Vertical_Focused ()
  1526. {
  1527. TileView tileView = Get11By3TileView (out LineView line);
  1528. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1529. Application.LayoutAndDraw ();
  1530. var looksLike =
  1531. @"
  1532. 11111│22222
  1533. 11111◊22222
  1534. │ ";
  1535. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1536. // Now while focused move the splitter 1 unit right
  1537. line.NewKeyDownEvent (Key.CursorRight);
  1538. Application.LayoutAndDraw ();
  1539. looksLike =
  1540. @"
  1541. 111111│2222
  1542. 111111◊2222
  1543. │ ";
  1544. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1545. // and 2 to the left
  1546. line.NewKeyDownEvent (Key.CursorLeft);
  1547. tileView.Layout ();
  1548. line.NewKeyDownEvent (Key.CursorLeft);
  1549. Application.LayoutAndDraw ();
  1550. looksLike =
  1551. @"
  1552. 1111│222222
  1553. 1111◊222222
  1554. │ ";
  1555. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1556. }
  1557. [Fact]
  1558. [AutoInitShutdown]
  1559. public void TestTileView_Vertical_Focused_50PercentSplit ()
  1560. {
  1561. TileView tileView = Get11By3TileView (out LineView line);
  1562. tileView.SetSplitterPos (0, Pos.Percent (50));
  1563. Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
  1564. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1565. Application.LayoutAndDraw ();
  1566. var looksLike =
  1567. @"
  1568. 11111│22222
  1569. 11111◊22222
  1570. │ ";
  1571. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1572. // Now while focused move the splitter 1 unit right
  1573. line.NewKeyDownEvent (Key.CursorRight);
  1574. Application.LayoutAndDraw ();
  1575. looksLike =
  1576. @"
  1577. 111111│2222
  1578. 111111◊2222
  1579. │ ";
  1580. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1581. // Even when moving the splitter location it should stay a Percentage based one
  1582. Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
  1583. // and 2 to the left
  1584. line.NewKeyDownEvent (Key.CursorLeft);
  1585. tileView.Layout ();
  1586. line.NewKeyDownEvent (Key.CursorLeft);
  1587. Application.LayoutAndDraw ();
  1588. looksLike =
  1589. @"
  1590. 1111│222222
  1591. 1111◊222222
  1592. │ ";
  1593. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1594. // Even when moving the splitter location it should stay a Percentage based one
  1595. Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
  1596. }
  1597. [Fact]
  1598. [AutoInitShutdown]
  1599. public void TestTileView_Vertical_Focused_WithBorder ()
  1600. {
  1601. TileView tileView = Get11By3TileView (out LineView line, true);
  1602. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1603. Application.LayoutAndDraw ();
  1604. var looksLike =
  1605. @"
  1606. ┌────┬────┐
  1607. │1111◊2222│
  1608. └────┴────┘";
  1609. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1610. // Now while focused move the splitter 1 unit right
  1611. line.NewKeyDownEvent (Key.CursorRight);
  1612. Application.LayoutAndDraw ();
  1613. looksLike =
  1614. @"
  1615. ┌─────┬───┐
  1616. │11111◊222│
  1617. └─────┴───┘";
  1618. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1619. // and 2 to the left
  1620. line.NewKeyDownEvent (Key.CursorLeft);
  1621. tileView.Layout ();
  1622. line.NewKeyDownEvent (Key.CursorLeft);
  1623. Application.LayoutAndDraw ();
  1624. looksLike =
  1625. @"
  1626. ┌───┬─────┐
  1627. │111◊22222│
  1628. └───┴─────┘";
  1629. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1630. }
  1631. [Fact]
  1632. [AutoInitShutdown]
  1633. public void TestTileView_Vertical_View1MinSize_Absolute ()
  1634. {
  1635. TileView tileView = Get11By3TileView (out LineView line);
  1636. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1637. tileView.Tiles.ElementAt (0).MinSize = 6;
  1638. // distance is too small (below 6)
  1639. Assert.False (tileView.SetSplitterPos (0, 2));
  1640. // Should stay where it was originally at (50%)
  1641. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1642. Application.LayoutAndDraw ();
  1643. // so should ignore the 2 distance and stick to 6
  1644. var looksLike =
  1645. @"
  1646. 11111│22222
  1647. 11111◊22222
  1648. │ ";
  1649. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1650. // Keyboard movement on splitter should have no effect because it
  1651. // would take us below the minimum splitter size
  1652. line.NewKeyDownEvent (Key.CursorLeft);
  1653. Application.LayoutAndDraw ();
  1654. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1655. // but we can continue to move the splitter right if we want
  1656. line.NewKeyDownEvent (Key.CursorRight);
  1657. Application.LayoutAndDraw ();
  1658. looksLike =
  1659. @"
  1660. 111111│2222
  1661. 111111◊2222
  1662. │ ";
  1663. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1664. }
  1665. [Fact]
  1666. [AutoInitShutdown]
  1667. public void TestTileView_Vertical_View1MinSize_Absolute_WithBorder ()
  1668. {
  1669. TileView tileView = Get11By3TileView (out LineView line, true);
  1670. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1671. tileView.Tiles.ElementAt (0).MinSize = 5;
  1672. // distance is too small (below 5)
  1673. Assert.False (tileView.SetSplitterPos (0, 2));
  1674. // Should stay where it was originally at (50%)
  1675. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1676. Application.LayoutAndDraw ();
  1677. // so should ignore the 2 distance and stick to 5
  1678. var looksLike =
  1679. @"
  1680. ┌────┬────┐
  1681. │1111◊2222│
  1682. └────┴────┘";
  1683. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1684. // Keyboard movement on splitter should have no effect because it
  1685. // would take us below the minimum splitter size
  1686. line.NewKeyDownEvent (Key.CursorLeft);
  1687. Application.LayoutAndDraw ();
  1688. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1689. // but we can continue to move the splitter right if we want
  1690. line.NewKeyDownEvent (Key.CursorRight);
  1691. Application.LayoutAndDraw ();
  1692. looksLike =
  1693. @"
  1694. ┌─────┬───┐
  1695. │11111◊222│
  1696. └─────┴───┘";
  1697. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1698. }
  1699. [Fact]
  1700. [AutoInitShutdown]
  1701. public void TestTileView_Vertical_View2MinSize_Absolute ()
  1702. {
  1703. TileView tileView = Get11By3TileView (out LineView line);
  1704. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1705. tileView.Tiles.ElementAt (1).MinSize = 6;
  1706. Application.LayoutAndDraw ();
  1707. // distance leaves too little space for view2 (less than 6 would remain)
  1708. Assert.False (tileView.SetSplitterPos (0, 8));
  1709. // Should stay where it was originally at (50%)
  1710. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1711. Application.LayoutAndDraw ();
  1712. // so should ignore the 2 distance and stick to 6
  1713. var looksLike =
  1714. @"
  1715. 11111│22222
  1716. 11111◊22222
  1717. │ ";
  1718. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1719. // Keyboard movement on splitter should have no effect because it
  1720. // would take us below the minimum splitter size
  1721. line.NewKeyDownEvent (Key.CursorRight);
  1722. Application.LayoutAndDraw ();
  1723. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1724. // but we can continue to move the splitter left if we want
  1725. line.NewKeyDownEvent (Key.CursorLeft);
  1726. Application.LayoutAndDraw ();
  1727. looksLike =
  1728. @"
  1729. 1111│222222
  1730. 1111◊222222
  1731. │ ";
  1732. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1733. }
  1734. [Fact]
  1735. [AutoInitShutdown]
  1736. public void TestTileView_Vertical_View2MinSize_Absolute_WithBorder ()
  1737. {
  1738. TileView tileView = Get11By3TileView (out LineView line, true);
  1739. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1740. tileView.Tiles.ElementAt (1).MinSize = 5;
  1741. // distance leaves too little space for view2 (less than 5 would remain)
  1742. Assert.False (tileView.SetSplitterPos (0, 8));
  1743. Application.LayoutAndDraw ();
  1744. // Should stay where it was originally at (50%)
  1745. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1746. Application.LayoutAndDraw ();
  1747. // so should ignore the 2 distance and stick to 6
  1748. var looksLike =
  1749. @"
  1750. ┌────┬────┐
  1751. │1111◊2222│
  1752. └────┴────┘";
  1753. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1754. // Keyboard movement on splitter should have no effect because it
  1755. // would take us below the minimum splitter size
  1756. line.NewKeyDownEvent (Key.CursorRight);
  1757. Application.LayoutAndDraw ();
  1758. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1759. // but we can continue to move the splitter left if we want
  1760. line.NewKeyDownEvent (Key.CursorLeft);
  1761. Application.LayoutAndDraw ();
  1762. looksLike =
  1763. @"
  1764. ┌───┬─────┐
  1765. │111◊22222│
  1766. └───┴─────┘";
  1767. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1768. }
  1769. [Fact]
  1770. [AutoInitShutdown]
  1771. public void TestTileView_Vertical_WithBorder ()
  1772. {
  1773. TileView tileView = Get11By3TileView (out LineView line, true);
  1774. Application.LayoutAndDraw ();
  1775. var looksLike =
  1776. @"
  1777. ┌────┬────┐
  1778. │1111│2222│
  1779. └────┴────┘";
  1780. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1781. // Keyboard movement on splitter should have no effect if it is not focused
  1782. tileView.NewKeyDownEvent (Key.CursorRight);
  1783. Application.LayoutAndDraw ();
  1784. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1785. }
  1786. [Fact]
  1787. [AutoInitShutdown]
  1788. public void TestTrySplit_ShouldRetainTitle ()
  1789. {
  1790. var tv = new TileView ();
  1791. tv.Tiles.ElementAt (0).Title = "flibble";
  1792. tv.TrySplitTile (0, 2, out TileView subTileView);
  1793. // We moved the content so the title should also have been moved
  1794. Assert.Equal ("flibble", subTileView.Tiles.ElementAt (0).Title);
  1795. // Secondly we should have cleared the old title (it should have been moved not copied)
  1796. Assert.Empty (tv.Tiles.ElementAt (0).Title);
  1797. }
  1798. private TileView Get11By3TileView (out LineView line, bool withBorder = false)
  1799. {
  1800. TileView split = Get11By3TileView (withBorder);
  1801. line = GetLine (split);
  1802. return split;
  1803. }
  1804. private TileView Get11By3TileView (bool withBorder = false) { return GetTileView (11, 3, withBorder); }
  1805. private TileView Get5x1TilesView (bool border = true)
  1806. {
  1807. var tv = new TileView (5)
  1808. {
  1809. Width = 25, Height = 4, LineStyle = LineStyle.Single
  1810. };
  1811. if (!border)
  1812. {
  1813. tv.LineStyle = LineStyle.None;
  1814. }
  1815. tv.Tiles.ElementAt (0)
  1816. .ContentView.Add (
  1817. new Label { Width = Dim.Fill (), Height = 1, Text = new ('1', 100) }
  1818. );
  1819. tv.Tiles.ElementAt (1)
  1820. .ContentView.Add (
  1821. new Label { Width = Dim.Fill (), Height = 1, Text = new ('2', 100) }
  1822. );
  1823. tv.Tiles.ElementAt (2)
  1824. .ContentView.Add (
  1825. new Label { Width = Dim.Fill (), Height = 1, Text = new ('3', 100) }
  1826. );
  1827. tv.Tiles.ElementAt (3)
  1828. .ContentView.Add (
  1829. new Label { Width = Dim.Fill (), Height = 1, Text = new ('4', 100) }
  1830. );
  1831. tv.Tiles.ElementAt (4)
  1832. .ContentView.Add (
  1833. new Label { Width = Dim.Fill (), Height = 1, Text = new ('5', 100) }
  1834. );
  1835. Application.Top = new ();
  1836. Application.Top.Add (tv);
  1837. Application.Begin (Application.Top);
  1838. return tv;
  1839. }
  1840. private LineView GetLine (TileView tileView) { return tileView.SubViews.OfType<LineView> ().Single (); }
  1841. /// <summary>Creates a vertical orientation root container with left pane split into two (with horizontal splitter line).</summary>
  1842. /// <param name="withBorder"></param>
  1843. /// <returns></returns>
  1844. private TileView GetNestedContainer2Left1Right (bool withBorder)
  1845. {
  1846. TileView container = GetTileView (20, 10, withBorder);
  1847. Assert.True (container.TrySplitTile (0, 2, out TileView newContainer));
  1848. newContainer.Orientation = Orientation.Horizontal;
  1849. container.LayoutSubViews ();
  1850. return container;
  1851. }
  1852. /// <summary>Creates a vertical orientation root container with 3 tiles. The rightmost is split horizontally</summary>
  1853. /// <param name="withBorder"></param>
  1854. /// <returns></returns>
  1855. private TileView GetNestedContainer3Right1Down (bool withBorder, bool withTitles = false, int split = 2)
  1856. {
  1857. Application.Top = new ();
  1858. var container = new TileView (3) { Width = 20, Height = 10 };
  1859. container.LineStyle = withBorder ? LineStyle.Single : LineStyle.None;
  1860. Assert.True (container.TrySplitTile (split, 2, out TileView newContainer));
  1861. newContainer.Orientation = Orientation.Horizontal;
  1862. var i = 0;
  1863. foreach (Tile tile in container.Tiles.Union (newContainer.Tiles))
  1864. {
  1865. if (tile.ContentView is TileView)
  1866. {
  1867. continue;
  1868. }
  1869. i++;
  1870. if (withTitles)
  1871. {
  1872. tile.Title = "T" + i;
  1873. }
  1874. tile.ContentView.Add (
  1875. new TextView
  1876. {
  1877. Width = Dim.Fill (),
  1878. Height = Dim.Fill (),
  1879. Text =
  1880. string.Join (
  1881. '\n',
  1882. Enumerable.Repeat (
  1883. new string (i.ToString () [0], 100),
  1884. 10
  1885. )
  1886. .ToArray ()
  1887. ),
  1888. WordWrap = false
  1889. }
  1890. );
  1891. }
  1892. Application.Top.Add (container);
  1893. Application.Begin (Application.Top);
  1894. return container;
  1895. }
  1896. private TileView GetTileView (int width, int height, bool withBorder = false)
  1897. {
  1898. var container = new TileView
  1899. {
  1900. Id = "container",
  1901. Width = width, Height = height
  1902. };
  1903. container.LineStyle = withBorder ? LineStyle.Single : LineStyle.None;
  1904. container.Tiles.ElementAt (0)
  1905. .ContentView.Add (
  1906. new Label { Id = "label1", Width = Dim.Fill (), Height = 1, Text = new ('1', 100) }
  1907. );
  1908. container.Tiles.ElementAt (0)
  1909. .ContentView.Add (
  1910. new Label
  1911. {
  1912. Id = "label2",
  1913. Width = Dim.Fill (),
  1914. Height = 1,
  1915. Y = 1,
  1916. Text = new ('1', 100)
  1917. }
  1918. );
  1919. container.Tiles.ElementAt (1)
  1920. .ContentView.Add (
  1921. new Label { Id = "label3", Width = Dim.Fill (), Height = 1, Text = new ('2', 100) }
  1922. );
  1923. container.Tiles.ElementAt (1)
  1924. .ContentView.Add (
  1925. new Label
  1926. {
  1927. Id = "label4",
  1928. Width = Dim.Fill (),
  1929. Height = 1,
  1930. Y = 1,
  1931. Text = new ('2', 100)
  1932. }
  1933. );
  1934. container.Tiles.ElementAt (0).MinSize = 0;
  1935. container.Tiles.ElementAt (1).MinSize = 0;
  1936. Application.Top = new ();
  1937. Application.Top.Add (container);
  1938. Application.Begin (Application.Top);
  1939. return container;
  1940. }
  1941. private class DisposeCounter : View
  1942. {
  1943. public int DisposalCount;
  1944. protected override void Dispose (bool disposing)
  1945. {
  1946. DisposalCount++;
  1947. base.Dispose (disposing);
  1948. }
  1949. }
  1950. }