TileViewTests.cs 75 KB

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