TileViewTests.cs 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396
  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. }
  665. [Theory]
  666. [InlineData (0)]
  667. [InlineData (1)]
  668. public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringRemoveTile (int idx)
  669. {
  670. TileView tv = GetTileView (20, 10);
  671. var myReusableView = new DisposeCounter ();
  672. // I want my view in the first tile
  673. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  674. Assert.Equal (0, myReusableView.DisposalCount);
  675. tv.RemoveTile (idx);
  676. // but I still want my view in the first tile
  677. // BUGBUG: Adding a view twice is not legit
  678. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  679. Assert.Multiple (
  680. () => Assert.Equal (0, myReusableView.DisposalCount),
  681. () =>
  682. {
  683. tv.Dispose ();
  684. Assert.True (myReusableView.DisposalCount >= 1);
  685. }
  686. );
  687. }
  688. [Fact]
  689. [AutoInitShutdown]
  690. public void TestNestedContainer2LeftAnd1Right_RendersNicely ()
  691. {
  692. TileView tileView = GetNestedContainer2Left1Right (false);
  693. Assert.Equal (20, tileView.Frame.Width);
  694. Assert.Equal (10, tileView.Tiles.ElementAt (0).ContentView.Frame.Width);
  695. Assert.Equal (9, tileView.Tiles.ElementAt (1).ContentView.Frame.Width);
  696. Assert.IsType<TileView> (tileView.Tiles.ElementAt (0).ContentView);
  697. var left = (TileView)tileView.Tiles.ElementAt (0).ContentView;
  698. Assert.Same (left.SuperView, tileView);
  699. Assert.Equal (2, left.Tiles.ElementAt (0).ContentView.SubViews.Count);
  700. Assert.IsType<Label> (left.Tiles.ElementAt (0).ContentView.SubViews.ElementAt (0));
  701. Assert.IsType<Label> (left.Tiles.ElementAt (0).ContentView.SubViews.ElementAt (1));
  702. var onesTop = (Label)left.Tiles.ElementAt (0).ContentView.SubViews.ElementAt (0);
  703. var onesBottom = (Label)left.Tiles.ElementAt (0).ContentView.SubViews.ElementAt (1);
  704. Assert.Same (left.Tiles.ElementAt (0).ContentView, onesTop.SuperView);
  705. Assert.Same (left.Tiles.ElementAt (0).ContentView, onesBottom.SuperView);
  706. Assert.Equal (10, onesTop.Frame.Width);
  707. Assert.Equal (10, onesBottom.Frame.Width);
  708. tileView.Draw ();
  709. var looksLike =
  710. @"
  711. 1111111111│222222222
  712. 1111111111│222222222
  713. ──────────┤
  714. │";
  715. DriverAssert.AssertDriverContentsAre (looksLike, output);
  716. }
  717. [Fact]
  718. [AutoInitShutdown]
  719. public void TestNestedContainer3RightAnd1Down_RendersNicely ()
  720. {
  721. TileView tileView = GetNestedContainer3Right1Down (false);
  722. tileView.Draw ();
  723. var looksLike =
  724. @"
  725. 111111│222222│333333
  726. 111111│222222│333333
  727. 111111│222222│333333
  728. 111111│222222│333333
  729. 111111│222222│333333
  730. 111111│222222├──────
  731. 111111│222222│444444
  732. 111111│222222│444444
  733. 111111│222222│444444
  734. 111111│222222│444444
  735. ";
  736. DriverAssert.AssertDriverContentsAre (looksLike, output);
  737. // It looks good but lets double check the measurements incase
  738. // anything is sticking out but drawn over
  739. // 3 panels + 2 splitters
  740. Assert.Equal (5, tileView.SubViews.Count);
  741. // Check X and Widths of Tiles
  742. Assert.Equal (0, tileView.Tiles.ElementAt (0).ContentView.Frame.X);
  743. Assert.Equal (6, tileView.Tiles.ElementAt (0).ContentView.Frame.Width);
  744. Assert.Equal (7, tileView.Tiles.ElementAt (1).ContentView.Frame.X);
  745. Assert.Equal (6, tileView.Tiles.ElementAt (1).ContentView.Frame.Width);
  746. Assert.Equal (14, tileView.Tiles.ElementAt (2).ContentView.Frame.X);
  747. Assert.Equal (6, tileView.Tiles.ElementAt (2).ContentView.Frame.Width);
  748. // Check Y and Heights of Tiles
  749. Assert.Equal (0, tileView.Tiles.ElementAt (0).ContentView.Frame.Y);
  750. Assert.Equal (10, tileView.Tiles.ElementAt (0).ContentView.Frame.Height);
  751. Assert.Equal (0, tileView.Tiles.ElementAt (1).ContentView.Frame.Y);
  752. Assert.Equal (10, tileView.Tiles.ElementAt (1).ContentView.Frame.Height);
  753. Assert.Equal (0, tileView.Tiles.ElementAt (2).ContentView.Frame.Y);
  754. Assert.Equal (10, tileView.Tiles.ElementAt (2).ContentView.Frame.Height);
  755. // Check Sub containers in last panel
  756. var subSplit = (TileView)tileView.Tiles.ElementAt (2).ContentView;
  757. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.X);
  758. Assert.Equal (6, subSplit.Tiles.ElementAt (0).ContentView.Frame.Width);
  759. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.Y);
  760. Assert.Equal (5, subSplit.Tiles.ElementAt (0).ContentView.Frame.Height);
  761. //Assert.IsType<TextView> (subSplit.Tiles.ElementAt (0).ContentView.SubViews.Single ());
  762. Assert.Equal (0, subSplit.Tiles.ElementAt (1).ContentView.Frame.X);
  763. Assert.Equal (6, subSplit.Tiles.ElementAt (1).ContentView.Frame.Width);
  764. Assert.Equal (6, subSplit.Tiles.ElementAt (1).ContentView.Frame.Y);
  765. Assert.Equal (4, subSplit.Tiles.ElementAt (1).ContentView.Frame.Height);
  766. //Assert.IsType<TextView> (subSplit.Tiles.ElementAt (1).ContentView.SubViews.Single ());
  767. }
  768. [Fact]
  769. [AutoInitShutdown]
  770. public void TestNestedContainer3RightAnd1Down_TileVisibility_WithBorder ()
  771. {
  772. TileView tileView = GetNestedContainer3Right1Down (true);
  773. Application.LayoutAndDraw ();
  774. var looksLike =
  775. @"
  776. ┌─────┬──────┬─────┐
  777. │11111│222222│33333│
  778. │11111│222222│33333│
  779. │11111│222222│33333│
  780. │11111│222222│33333│
  781. │11111│222222├─────┤
  782. │11111│222222│44444│
  783. │11111│222222│44444│
  784. │11111│222222│44444│
  785. └─────┴──────┴─────┘";
  786. DriverAssert.AssertDriverContentsAre (looksLike, output);
  787. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  788. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  789. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  790. Application.LayoutAndDraw ();
  791. looksLike =
  792. @"
  793. ┌────────────┬─────┐
  794. │222222222222│33333│
  795. │222222222222│33333│
  796. │222222222222│33333│
  797. │222222222222│33333│
  798. │222222222222├─────┤
  799. │222222222222│44444│
  800. │222222222222│44444│
  801. │222222222222│44444│
  802. └────────────┴─────┘";
  803. DriverAssert.AssertDriverContentsAre (looksLike, output);
  804. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  805. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  806. Application.LayoutAndDraw ();
  807. looksLike =
  808. @"
  809. ┌────────────┬─────┐
  810. │111111111111│33333│
  811. │111111111111│33333│
  812. │111111111111│33333│
  813. │111111111111│33333│
  814. │111111111111├─────┤
  815. │111111111111│44444│
  816. │111111111111│44444│
  817. │111111111111│44444│
  818. └────────────┴─────┘";
  819. DriverAssert.AssertDriverContentsAre (looksLike, output);
  820. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  821. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  822. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  823. Application.LayoutAndDraw ();
  824. looksLike =
  825. @"
  826. ┌─────┬────────────┐
  827. │11111│222222222222│
  828. │11111│222222222222│
  829. │11111│222222222222│
  830. │11111│222222222222│
  831. │11111│222222222222│
  832. │11111│222222222222│
  833. │11111│222222222222│
  834. │11111│222222222222│
  835. └─────┴────────────┘";
  836. DriverAssert.AssertDriverContentsAre (looksLike, output);
  837. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  838. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  839. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  840. Application.LayoutAndDraw ();
  841. looksLike =
  842. @"
  843. ┌──────────────────┐
  844. │111111111111111111│
  845. │111111111111111111│
  846. │111111111111111111│
  847. │111111111111111111│
  848. │111111111111111111│
  849. │111111111111111111│
  850. │111111111111111111│
  851. │111111111111111111│
  852. └──────────────────┘";
  853. DriverAssert.AssertDriverContentsAre (looksLike, output);
  854. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  855. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  856. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  857. Application.LayoutAndDraw ();
  858. looksLike =
  859. @"
  860. ┌──────────────────┐
  861. │222222222222222222│
  862. │222222222222222222│
  863. │222222222222222222│
  864. │222222222222222222│
  865. │222222222222222222│
  866. │222222222222222222│
  867. │222222222222222222│
  868. │222222222222222222│
  869. └──────────────────┘";
  870. DriverAssert.AssertDriverContentsAre (looksLike, output);
  871. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  872. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  873. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  874. Application.LayoutAndDraw ();
  875. looksLike =
  876. @"
  877. ┌──────────────────┐
  878. │333333333333333333│
  879. │333333333333333333│
  880. │333333333333333333│
  881. │333333333333333333│
  882. ├──────────────────┤
  883. │444444444444444444│
  884. │444444444444444444│
  885. │444444444444444444│
  886. └──────────────────┘";
  887. DriverAssert.AssertDriverContentsAre (looksLike, output);
  888. DriverAssert.AssertDriverContentsAre (looksLike, output);
  889. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  890. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  891. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  892. Application.LayoutAndDraw ();
  893. looksLike =
  894. @"
  895. ┌──────────────────┐
  896. │ │
  897. │ │
  898. │ │
  899. │ │
  900. │ │
  901. │ │
  902. │ │
  903. │ │
  904. └──────────────────┘";
  905. DriverAssert.AssertDriverContentsAre (looksLike, output);
  906. }
  907. [Fact]
  908. [AutoInitShutdown]
  909. public void TestNestedContainer3RightAnd1Down_TileVisibility_WithoutBorder ()
  910. {
  911. TileView tileView = GetNestedContainer3Right1Down (false);
  912. Application.LayoutAndDraw ();
  913. var looksLike =
  914. @"
  915. 111111│222222│333333
  916. 111111│222222│333333
  917. 111111│222222│333333
  918. 111111│222222│333333
  919. 111111│222222│333333
  920. 111111│222222├──────
  921. 111111│222222│444444
  922. 111111│222222│444444
  923. 111111│222222│444444
  924. 111111│222222│444444";
  925. DriverAssert.AssertDriverContentsAre (looksLike, output);
  926. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  927. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  928. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  929. Application.LayoutAndDraw ();
  930. looksLike =
  931. @"
  932. 2222222222222│333333
  933. 2222222222222│333333
  934. 2222222222222│333333
  935. 2222222222222│333333
  936. 2222222222222│333333
  937. 2222222222222├──────
  938. 2222222222222│444444
  939. 2222222222222│444444
  940. 2222222222222│444444
  941. 2222222222222│444444";
  942. DriverAssert.AssertDriverContentsAre (looksLike, output);
  943. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  944. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  945. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  946. Application.LayoutAndDraw ();
  947. looksLike =
  948. @"
  949. 1111111111111│333333
  950. 1111111111111│333333
  951. 1111111111111│333333
  952. 1111111111111│333333
  953. 1111111111111│333333
  954. 1111111111111├──────
  955. 1111111111111│444444
  956. 1111111111111│444444
  957. 1111111111111│444444
  958. 1111111111111│444444";
  959. DriverAssert.AssertDriverContentsAre (looksLike, output);
  960. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  961. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  962. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  963. Application.LayoutAndDraw ();
  964. looksLike =
  965. @"
  966. 111111│2222222222222
  967. 111111│2222222222222
  968. 111111│2222222222222
  969. 111111│2222222222222
  970. 111111│2222222222222
  971. 111111│2222222222222
  972. 111111│2222222222222
  973. 111111│2222222222222
  974. 111111│2222222222222
  975. 111111│2222222222222";
  976. DriverAssert.AssertDriverContentsAre (looksLike, output);
  977. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  978. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  979. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  980. Application.LayoutAndDraw ();
  981. looksLike =
  982. @"
  983. 11111111111111111111
  984. 11111111111111111111
  985. 11111111111111111111
  986. 11111111111111111111
  987. 11111111111111111111
  988. 11111111111111111111
  989. 11111111111111111111
  990. 11111111111111111111
  991. 11111111111111111111
  992. 11111111111111111111";
  993. DriverAssert.AssertDriverContentsAre (looksLike, output);
  994. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  995. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  996. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  997. Application.LayoutAndDraw ();
  998. looksLike =
  999. @"
  1000. 22222222222222222222
  1001. 22222222222222222222
  1002. 22222222222222222222
  1003. 22222222222222222222
  1004. 22222222222222222222
  1005. 22222222222222222222
  1006. 22222222222222222222
  1007. 22222222222222222222
  1008. 22222222222222222222
  1009. 22222222222222222222";
  1010. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1011. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1012. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  1013. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  1014. Application.LayoutAndDraw ();
  1015. looksLike =
  1016. @"
  1017. 33333333333333333333
  1018. 33333333333333333333
  1019. 33333333333333333333
  1020. 33333333333333333333
  1021. 33333333333333333333
  1022. ────────────────────
  1023. 44444444444444444444
  1024. 44444444444444444444
  1025. 44444444444444444444
  1026. 44444444444444444444";
  1027. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1028. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1029. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1030. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  1031. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  1032. Application.LayoutAndDraw ();
  1033. looksLike =
  1034. @"
  1035. ";
  1036. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1037. }
  1038. [Fact]
  1039. [AutoInitShutdown]
  1040. public void TestNestedContainer3RightAnd1Down_TitleDoesNotOverspill ()
  1041. {
  1042. TileView tileView = GetNestedContainer3Right1Down (true, true, 1);
  1043. Application.LayoutAndDraw ();
  1044. var looksLike =
  1045. @"
  1046. ┌ T1 ─┬ T3 ──┬ T2 ─┐
  1047. │11111│333333│22222│
  1048. │11111│333333│22222│
  1049. │11111│333333│22222│
  1050. │11111│333333│22222│
  1051. │11111├ T4 ──┤22222│
  1052. │11111│444444│22222│
  1053. │11111│444444│22222│
  1054. │11111│444444│22222│
  1055. └─────┴──────┴─────┘";
  1056. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1057. }
  1058. [Fact]
  1059. [AutoInitShutdown]
  1060. public void TestNestedContainer3RightAnd1Down_TitleTriesToOverspill ()
  1061. {
  1062. TileView tileView = GetNestedContainer3Right1Down (true, true, 1);
  1063. tileView.Tiles.ElementAt (0).Title = new ('x', 100);
  1064. ((TileView)tileView.Tiles.ElementAt (1).ContentView)
  1065. .Tiles.ElementAt (1)
  1066. .Title = new ('y', 100);
  1067. Application.LayoutAndDraw ();
  1068. var looksLike =
  1069. @"
  1070. ┌ xxxx┬ T3 ──┬ T2 ─┐
  1071. │11111│333333│22222│
  1072. │11111│333333│22222│
  1073. │11111│333333│22222│
  1074. │11111│333333│22222│
  1075. │11111├ yyyyy┤22222│
  1076. │11111│444444│22222│
  1077. │11111│444444│22222│
  1078. │11111│444444│22222│
  1079. └─────┴──────┴─────┘";
  1080. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1081. }
  1082. [Fact]
  1083. [AutoInitShutdown]
  1084. public void TestNestedContainer3RightAnd1Down_WithBorder_RemovingTiles ()
  1085. {
  1086. TileView tileView = GetNestedContainer3Right1Down (true);
  1087. Application.LayoutAndDraw ();
  1088. var looksLike =
  1089. @"
  1090. ┌─────┬──────┬─────┐
  1091. │11111│222222│33333│
  1092. │11111│222222│33333│
  1093. │11111│222222│33333│
  1094. │11111│222222│33333│
  1095. │11111│222222├─────┤
  1096. │11111│222222│44444│
  1097. │11111│222222│44444│
  1098. │11111│222222│44444│
  1099. └─────┴──────┴─────┘";
  1100. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1101. Tile toRemove = tileView.Tiles.ElementAt (1);
  1102. Tile removed = tileView.RemoveTile (1);
  1103. Assert.Same (toRemove, removed);
  1104. Assert.DoesNotContain (removed, tileView.Tiles);
  1105. Application.LayoutAndDraw ();
  1106. looksLike =
  1107. @"
  1108. ┌─────────┬────────┐
  1109. │111111111│33333333│
  1110. │111111111│33333333│
  1111. │111111111│33333333│
  1112. │111111111│33333333│
  1113. │111111111├────────┤
  1114. │111111111│44444444│
  1115. │111111111│44444444│
  1116. │111111111│44444444│
  1117. └─────────┴────────┘";
  1118. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1119. // cannot remove at this index because there is only one horizontal tile left
  1120. Assert.Null (tileView.RemoveTile (2));
  1121. tileView.RemoveTile (0);
  1122. Application.LayoutAndDraw ();
  1123. looksLike =
  1124. @"
  1125. ┌──────────────────┐
  1126. │333333333333333333│
  1127. │333333333333333333│
  1128. │333333333333333333│
  1129. │333333333333333333│
  1130. ├──────────────────┤
  1131. │444444444444444444│
  1132. │444444444444444444│
  1133. │444444444444444444│
  1134. └──────────────────┘";
  1135. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1136. Assert.NotNull (tileView.RemoveTile (0));
  1137. Application.LayoutAndDraw ();
  1138. looksLike =
  1139. @"
  1140. ┌──────────────────┐
  1141. │ │
  1142. │ │
  1143. │ │
  1144. │ │
  1145. │ │
  1146. │ │
  1147. │ │
  1148. │ │
  1149. └──────────────────┘";
  1150. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1151. // cannot remove
  1152. Assert.Null (tileView.RemoveTile (0));
  1153. }
  1154. [Fact]
  1155. [AutoInitShutdown]
  1156. public void TestNestedContainer3RightAnd1Down_WithBorder_RendersNicely ()
  1157. {
  1158. TileView tileView = GetNestedContainer3Right1Down (true);
  1159. Application.LayoutAndDraw ();
  1160. var looksLike =
  1161. @"
  1162. ┌─────┬──────┬─────┐
  1163. │11111│222222│33333│
  1164. │11111│222222│33333│
  1165. │11111│222222│33333│
  1166. │11111│222222│33333│
  1167. │11111│222222├─────┤
  1168. │11111│222222│44444│
  1169. │11111│222222│44444│
  1170. │11111│222222│44444│
  1171. └─────┴──────┴─────┘";
  1172. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1173. // It looks good but lets double check the measurements incase
  1174. // anything is sticking out but drawn over
  1175. // 3 panels + 2 splitters
  1176. Assert.Equal (5, tileView.SubViews.Count);
  1177. // Check X and Widths of Tiles
  1178. Assert.Equal (1, tileView.Tiles.ElementAt (0).ContentView.Frame.X);
  1179. Assert.Equal (5, tileView.Tiles.ElementAt (0).ContentView.Frame.Width);
  1180. Assert.Equal (7, tileView.Tiles.ElementAt (1).ContentView.Frame.X);
  1181. Assert.Equal (6, tileView.Tiles.ElementAt (1).ContentView.Frame.Width);
  1182. Assert.Equal (14, tileView.Tiles.ElementAt (2).ContentView.Frame.X);
  1183. Assert.Equal (5, tileView.Tiles.ElementAt (2).ContentView.Frame.Width);
  1184. // Check Y and Heights of Tiles
  1185. Assert.Equal (1, tileView.Tiles.ElementAt (0).ContentView.Frame.Y);
  1186. Assert.Equal (8, tileView.Tiles.ElementAt (0).ContentView.Frame.Height);
  1187. Assert.Equal (1, tileView.Tiles.ElementAt (1).ContentView.Frame.Y);
  1188. Assert.Equal (8, tileView.Tiles.ElementAt (1).ContentView.Frame.Height);
  1189. Assert.Equal (1, tileView.Tiles.ElementAt (2).ContentView.Frame.Y);
  1190. Assert.Equal (8, tileView.Tiles.ElementAt (2).ContentView.Frame.Height);
  1191. // Check Sub containers in last panel
  1192. var subSplit = (TileView)tileView.Tiles.ElementAt (2).ContentView;
  1193. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.X);
  1194. Assert.Equal (5, subSplit.Tiles.ElementAt (0).ContentView.Frame.Width);
  1195. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.Y);
  1196. Assert.Equal (4, subSplit.Tiles.ElementAt (0).ContentView.Frame.Height);
  1197. //Assert.IsType<TextView> (subSplit.Tiles.ElementAt (0).ContentView.SubViews.Single ());
  1198. Assert.Equal (0, subSplit.Tiles.ElementAt (1).ContentView.Frame.X);
  1199. Assert.Equal (5, subSplit.Tiles.ElementAt (1).ContentView.Frame.Width);
  1200. Assert.Equal (5, subSplit.Tiles.ElementAt (1).ContentView.Frame.Y);
  1201. Assert.Equal (3, subSplit.Tiles.ElementAt (1).ContentView.Frame.Height);
  1202. //Assert.IsType<TextView> (subSplit.Tiles.ElementAt (1).ContentView.SubViews.Single ());
  1203. }
  1204. [Fact]
  1205. [AutoInitShutdown]
  1206. public void TestNestedContainer3RightAnd1Down_WithTitledBorder_RendersNicely ()
  1207. {
  1208. TileView tileView = GetNestedContainer3Right1Down (true, true);
  1209. tileView.Draw ();
  1210. var looksLike =
  1211. @"
  1212. ┌ T1 ─┬ T2 ──┬ T3 ─┐
  1213. │11111│222222│33333│
  1214. │11111│222222│33333│
  1215. │11111│222222│33333│
  1216. │11111│222222│33333│
  1217. │11111│222222├ T4 ─┤
  1218. │11111│222222│44444│
  1219. │11111│222222│44444│
  1220. │11111│222222│44444│
  1221. └─────┴──────┴─────┘";
  1222. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1223. }
  1224. [Fact]
  1225. [AutoInitShutdown]
  1226. public void TestNestedNonRoots_OnlyOneRoot_OnlyRootCanHaveBorders ()
  1227. {
  1228. var tv = new TileView
  1229. {
  1230. Width = 10, Height = 5, LineStyle = LineStyle.Single
  1231. };
  1232. tv.TrySplitTile (1, 2, out TileView tv2);
  1233. // tv2.Scheme = new ();
  1234. tv2.LineStyle = LineStyle.Single;
  1235. tv2.Orientation = Orientation.Horizontal;
  1236. Assert.True (tv.IsRootTileView ());
  1237. var top = new Toplevel ();
  1238. top.Add (tv);
  1239. tv.BeginInit ();
  1240. tv.EndInit ();
  1241. tv.LayoutSubViews ();
  1242. tv.LayoutSubViews ();
  1243. tv.Tiles.ElementAt (1).ContentView.LayoutSubViews ();
  1244. tv2.LayoutSubViews ();
  1245. // tv2 is not considered a root because
  1246. // it was created via TrySplitTile so it
  1247. // will have its lines joined to
  1248. // parent and cannot have its own border
  1249. Assert.False (tv2.IsRootTileView ());
  1250. tv.Draw ();
  1251. var looksLike =
  1252. @"
  1253. ┌────┬───┐
  1254. │ │ │
  1255. │ ├───┤
  1256. │ │ │
  1257. └────┴───┘
  1258. ";
  1259. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1260. }
  1261. [Fact]
  1262. [AutoInitShutdown]
  1263. public void TestNestedRoots_BothRoots_BothCanHaveBorders ()
  1264. {
  1265. var tv = new TileView
  1266. {
  1267. Width = 10, Height = 5, LineStyle = LineStyle.Single
  1268. };
  1269. var tv2 = new TileView
  1270. {
  1271. Width = Dim.Fill (),
  1272. Height = Dim.Fill (),
  1273. LineStyle = LineStyle.Single,
  1274. Orientation = Orientation.Horizontal
  1275. };
  1276. Assert.True (tv.IsRootTileView ());
  1277. tv.Tiles.ElementAt (1).ContentView.Add (tv2);
  1278. var top = new Toplevel ();
  1279. top.Add (tv);
  1280. tv.BeginInit ();
  1281. tv.EndInit ();
  1282. tv.LayoutSubViews ();
  1283. tv.LayoutSubViews ();
  1284. tv.Tiles.ElementAt (1).ContentView.LayoutSubViews ();
  1285. tv2.LayoutSubViews ();
  1286. // tv2 is still considered a root because
  1287. // it was manually created by API user. That
  1288. // means it will not have its lines joined to
  1289. // parents and it is permitted to have a border
  1290. Assert.True (tv2.IsRootTileView ());
  1291. tv.Draw ();
  1292. var looksLike =
  1293. @"
  1294. ┌────┬───┐
  1295. │ │┌─┐│
  1296. │ │├─┤│
  1297. │ │└─┘│
  1298. └────┴───┘
  1299. ";
  1300. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1301. }
  1302. [Fact]
  1303. [AutoInitShutdown]
  1304. public void TestTileView_CannotSetSplitterPosToFuncEtc ()
  1305. {
  1306. TileView tileView = Get11By3TileView ();
  1307. var ex = Assert.Throws<ArgumentException> (() => tileView.SetSplitterPos (0, Pos.Right (tileView)));
  1308. Assert.Equal ("Only Percent and Absolute values are supported. Passed value was PosView", ex.Message);
  1309. ex = Assert.Throws<ArgumentException> (() => tileView.SetSplitterPos (0, Pos.Func (() => 1)));
  1310. Assert.Equal ("Only Percent and Absolute values are supported. Passed value was PosFunc", ex.Message);
  1311. // Also not allowed because this results in a PosCombine
  1312. ex = Assert.Throws<ArgumentException> (() => tileView.SetSplitterPos (0, Pos.Percent (50) - 1));
  1313. Assert.Equal (
  1314. "Only Percent and Absolute values are supported. Passed value was PosCombine",
  1315. ex.Message
  1316. );
  1317. }
  1318. [Fact]
  1319. [AutoInitShutdown]
  1320. public void TestTileView_Horizontal ()
  1321. {
  1322. TileView tileView = Get11By3TileView (out LineView line);
  1323. tileView.Orientation = Orientation.Horizontal;
  1324. tileView.Layout ();
  1325. tileView.Draw ();
  1326. var looksLike =
  1327. @"
  1328. 11111111111
  1329. ───────────
  1330. 22222222222";
  1331. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1332. // Keyboard movement on splitter should have no effect if it is not focused
  1333. bool handled = tileView.NewKeyDownEvent (Key.CursorDown);
  1334. Assert.False (handled);
  1335. tileView.SetNeedsDraw ();
  1336. tileView.Draw ();
  1337. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1338. }
  1339. [Fact]
  1340. [AutoInitShutdown]
  1341. public void TestTileView_Horizontal_Focused ()
  1342. {
  1343. TileView tileView = Get11By3TileView (out LineView line);
  1344. tileView.Orientation = Orientation.Horizontal;
  1345. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1346. Assert.True (line.HasFocus);
  1347. Application.LayoutAndDraw ();
  1348. var looksLike =
  1349. @"
  1350. 11111111111
  1351. ─────◊─────
  1352. 22222222222";
  1353. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1354. // Now move splitter line down
  1355. tileView.NewKeyDownEvent (Key.CursorDown);
  1356. Application.LayoutAndDraw ();
  1357. looksLike =
  1358. @"
  1359. 11111111111
  1360. 11111111111
  1361. ─────◊─────";
  1362. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1363. // And 2 up
  1364. line.NewKeyDownEvent (Key.CursorUp);
  1365. Application.LayoutAndDraw ();
  1366. line.NewKeyDownEvent (Key.CursorUp);
  1367. Application.LayoutAndDraw ();
  1368. looksLike =
  1369. @"
  1370. ─────◊─────
  1371. 22222222222
  1372. 22222222222";
  1373. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1374. }
  1375. [Fact]
  1376. [AutoInitShutdown]
  1377. public void TestTileView_Horizontal_View1MinSize_Absolute ()
  1378. {
  1379. TileView tileView = Get11By3TileView (out LineView line);
  1380. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1381. tileView.Orientation = Orientation.Horizontal;
  1382. tileView.Tiles.ElementAt (0).MinSize = 1;
  1383. // 0 should not be allowed because it brings us below minimum size of View1
  1384. Assert.False (tileView.SetSplitterPos (0, 0));
  1385. // position should remain where it was, at 50%
  1386. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1387. Application.LayoutAndDraw ();
  1388. var looksLike =
  1389. @"
  1390. 11111111111
  1391. ─────◊─────
  1392. 22222222222";
  1393. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1394. // Now move splitter line down (allowed
  1395. line.NewKeyDownEvent (Key.CursorDown);
  1396. Application.LayoutAndDraw ();
  1397. looksLike =
  1398. @"
  1399. 11111111111
  1400. 11111111111
  1401. ─────◊─────";
  1402. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1403. // And up 2 (only 1 is allowed because of minimum size of 1 on view1)
  1404. line.NewKeyDownEvent (Key.CursorUp);
  1405. line.NewKeyDownEvent (Key.CursorUp);
  1406. tileView.SetNeedsDraw ();
  1407. Application.LayoutAndDraw ();
  1408. looksLike =
  1409. @"
  1410. 11111111111
  1411. ─────◊─────
  1412. 22222222222";
  1413. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1414. }
  1415. [Theory]
  1416. [AutoInitShutdown]
  1417. [InlineData (true)]
  1418. [InlineData (false)]
  1419. public void TestTileView_IndexOf (bool recursive)
  1420. {
  1421. var tv = new TileView ();
  1422. var lbl1 = new Label ();
  1423. var lbl2 = new Label ();
  1424. var frame = new FrameView ();
  1425. var sub = new Label ();
  1426. frame.Add (sub);
  1427. // IndexOf returns -1 when view not found
  1428. Assert.Equal (-1, tv.IndexOf (lbl1, recursive));
  1429. Assert.Equal (-1, tv.IndexOf (lbl2, recursive));
  1430. // IndexOf supports looking for Tile.View
  1431. Assert.Equal (0, tv.IndexOf (tv.Tiles.ElementAt (0).ContentView, recursive));
  1432. Assert.Equal (1, tv.IndexOf (tv.Tiles.ElementAt (1).ContentView, recursive));
  1433. // IndexOf supports looking for Tile.View.SubViews
  1434. tv.Tiles.ElementAt (0).ContentView.Add (lbl1);
  1435. Assert.Equal (0, tv.IndexOf (lbl1, recursive));
  1436. tv.Tiles.ElementAt (1).ContentView.Add (lbl2);
  1437. Assert.Equal (1, tv.IndexOf (lbl2, recursive));
  1438. // IndexOf supports looking deep into subviews only when
  1439. // the recursive true value is passed
  1440. tv.Tiles.ElementAt (1).ContentView.Add (frame);
  1441. if (recursive)
  1442. {
  1443. Assert.Equal (1, tv.IndexOf (sub, recursive));
  1444. }
  1445. else
  1446. {
  1447. Assert.Equal (-1, tv.IndexOf (sub, recursive));
  1448. }
  1449. }
  1450. [Fact]
  1451. [AutoInitShutdown]
  1452. public void TestTileView_InsertPanelAtEnd ()
  1453. {
  1454. TileView tileView = Get11By3TileView (out LineView line, true);
  1455. tileView.InsertTile (2);
  1456. tileView.Layout ();
  1457. tileView.Draw ();
  1458. // so should ignore the 2 distance and stick to 6
  1459. var looksLike =
  1460. @"
  1461. ┌──┬───┬──┐
  1462. │11│222│ │
  1463. └──┴───┴──┘";
  1464. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1465. }
  1466. [Fact]
  1467. [AutoInitShutdown]
  1468. public void TestTileView_InsertPanelAtStart ()
  1469. {
  1470. TileView tileView = Get11By3TileView (out LineView line, true);
  1471. tileView.InsertTile (0);
  1472. tileView.Layout ();
  1473. tileView.Draw ();
  1474. // so should ignore the 2 distance and stick to 6
  1475. var looksLike =
  1476. @"
  1477. ┌──┬───┬──┐
  1478. │ │111│22│
  1479. └──┴───┴──┘";
  1480. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1481. }
  1482. [Fact]
  1483. [AutoInitShutdown]
  1484. public void TestTileView_InsertPanelMiddle ()
  1485. {
  1486. TileView tileView = Get11By3TileView (out LineView line, true);
  1487. tileView.InsertTile (1);
  1488. tileView.Layout ();
  1489. tileView.Draw ();
  1490. // so should ignore the 2 distance and stick to 6
  1491. var looksLike =
  1492. @"
  1493. ┌──┬───┬──┐
  1494. │11│ │22│
  1495. └──┴───┴──┘";
  1496. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1497. }
  1498. [Fact]
  1499. [AutoInitShutdown]
  1500. public void TestTileView_Vertical ()
  1501. {
  1502. TileView tileView = Get11By3TileView (out LineView line);
  1503. tileView.Layout ();
  1504. tileView.Draw ();
  1505. var looksLike =
  1506. @"
  1507. 11111│22222
  1508. 11111│22222
  1509. │ ";
  1510. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1511. // Keyboard movement on splitter should have no effect if it is not focused
  1512. tileView.NewKeyDownEvent (Key.CursorRight);
  1513. tileView.SetNeedsDraw ();
  1514. tileView.Draw ();
  1515. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1516. }
  1517. [Fact]
  1518. [AutoInitShutdown]
  1519. public void TestTileView_Vertical_Focused ()
  1520. {
  1521. TileView tileView = Get11By3TileView (out LineView line);
  1522. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1523. Application.LayoutAndDraw ();
  1524. var looksLike =
  1525. @"
  1526. 11111│22222
  1527. 11111◊22222
  1528. │ ";
  1529. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1530. // Now while focused move the splitter 1 unit right
  1531. line.NewKeyDownEvent (Key.CursorRight);
  1532. Application.LayoutAndDraw ();
  1533. looksLike =
  1534. @"
  1535. 111111│2222
  1536. 111111◊2222
  1537. │ ";
  1538. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1539. // and 2 to the left
  1540. line.NewKeyDownEvent (Key.CursorLeft);
  1541. tileView.Layout ();
  1542. line.NewKeyDownEvent (Key.CursorLeft);
  1543. Application.LayoutAndDraw ();
  1544. looksLike =
  1545. @"
  1546. 1111│222222
  1547. 1111◊222222
  1548. │ ";
  1549. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1550. }
  1551. [Fact]
  1552. [AutoInitShutdown]
  1553. public void TestTileView_Vertical_Focused_50PercentSplit ()
  1554. {
  1555. TileView tileView = Get11By3TileView (out LineView line);
  1556. tileView.SetSplitterPos (0, Pos.Percent (50));
  1557. Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
  1558. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1559. Application.LayoutAndDraw ();
  1560. var looksLike =
  1561. @"
  1562. 11111│22222
  1563. 11111◊22222
  1564. │ ";
  1565. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1566. // Now while focused move the splitter 1 unit right
  1567. line.NewKeyDownEvent (Key.CursorRight);
  1568. Application.LayoutAndDraw ();
  1569. looksLike =
  1570. @"
  1571. 111111│2222
  1572. 111111◊2222
  1573. │ ";
  1574. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1575. // Even when moving the splitter location it should stay a Percentage based one
  1576. Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
  1577. // and 2 to the left
  1578. line.NewKeyDownEvent (Key.CursorLeft);
  1579. tileView.Layout ();
  1580. line.NewKeyDownEvent (Key.CursorLeft);
  1581. Application.LayoutAndDraw ();
  1582. looksLike =
  1583. @"
  1584. 1111│222222
  1585. 1111◊222222
  1586. │ ";
  1587. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1588. // Even when moving the splitter location it should stay a Percentage based one
  1589. Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
  1590. }
  1591. [Fact]
  1592. [AutoInitShutdown]
  1593. public void TestTileView_Vertical_Focused_WithBorder ()
  1594. {
  1595. TileView tileView = Get11By3TileView (out LineView line, true);
  1596. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1597. Application.LayoutAndDraw ();
  1598. var looksLike =
  1599. @"
  1600. ┌────┬────┐
  1601. │1111◊2222│
  1602. └────┴────┘";
  1603. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1604. // Now while focused move the splitter 1 unit right
  1605. line.NewKeyDownEvent (Key.CursorRight);
  1606. Application.LayoutAndDraw ();
  1607. looksLike =
  1608. @"
  1609. ┌─────┬───┐
  1610. │11111◊222│
  1611. └─────┴───┘";
  1612. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1613. // and 2 to the left
  1614. line.NewKeyDownEvent (Key.CursorLeft);
  1615. tileView.Layout ();
  1616. line.NewKeyDownEvent (Key.CursorLeft);
  1617. Application.LayoutAndDraw ();
  1618. looksLike =
  1619. @"
  1620. ┌───┬─────┐
  1621. │111◊22222│
  1622. └───┴─────┘";
  1623. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1624. }
  1625. [Fact]
  1626. [AutoInitShutdown]
  1627. public void TestTileView_Vertical_View1MinSize_Absolute ()
  1628. {
  1629. TileView tileView = Get11By3TileView (out LineView line);
  1630. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1631. tileView.Tiles.ElementAt (0).MinSize = 6;
  1632. // distance is too small (below 6)
  1633. Assert.False (tileView.SetSplitterPos (0, 2));
  1634. // Should stay where it was originally at (50%)
  1635. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1636. Application.LayoutAndDraw ();
  1637. // so should ignore the 2 distance and stick to 6
  1638. var looksLike =
  1639. @"
  1640. 11111│22222
  1641. 11111◊22222
  1642. │ ";
  1643. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1644. // Keyboard movement on splitter should have no effect because it
  1645. // would take us below the minimum splitter size
  1646. line.NewKeyDownEvent (Key.CursorLeft);
  1647. Application.LayoutAndDraw ();
  1648. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1649. // but we can continue to move the splitter right if we want
  1650. line.NewKeyDownEvent (Key.CursorRight);
  1651. Application.LayoutAndDraw ();
  1652. looksLike =
  1653. @"
  1654. 111111│2222
  1655. 111111◊2222
  1656. │ ";
  1657. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1658. }
  1659. [Fact]
  1660. [AutoInitShutdown]
  1661. public void TestTileView_Vertical_View1MinSize_Absolute_WithBorder ()
  1662. {
  1663. TileView tileView = Get11By3TileView (out LineView line, true);
  1664. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1665. tileView.Tiles.ElementAt (0).MinSize = 5;
  1666. // distance is too small (below 5)
  1667. Assert.False (tileView.SetSplitterPos (0, 2));
  1668. // Should stay where it was originally at (50%)
  1669. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1670. Application.LayoutAndDraw ();
  1671. // so should ignore the 2 distance and stick to 5
  1672. var looksLike =
  1673. @"
  1674. ┌────┬────┐
  1675. │1111◊2222│
  1676. └────┴────┘";
  1677. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1678. // Keyboard movement on splitter should have no effect because it
  1679. // would take us below the minimum splitter size
  1680. line.NewKeyDownEvent (Key.CursorLeft);
  1681. Application.LayoutAndDraw ();
  1682. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1683. // but we can continue to move the splitter right if we want
  1684. line.NewKeyDownEvent (Key.CursorRight);
  1685. Application.LayoutAndDraw ();
  1686. looksLike =
  1687. @"
  1688. ┌─────┬───┐
  1689. │11111◊222│
  1690. └─────┴───┘";
  1691. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1692. }
  1693. [Fact]
  1694. [AutoInitShutdown]
  1695. public void TestTileView_Vertical_View2MinSize_Absolute ()
  1696. {
  1697. TileView tileView = Get11By3TileView (out LineView line);
  1698. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1699. tileView.Tiles.ElementAt (1).MinSize = 6;
  1700. Application.LayoutAndDraw ();
  1701. // distance leaves too little space for view2 (less than 6 would remain)
  1702. Assert.False (tileView.SetSplitterPos (0, 8));
  1703. // Should stay where it was originally at (50%)
  1704. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1705. Application.LayoutAndDraw ();
  1706. // so should ignore the 2 distance and stick to 6
  1707. var looksLike =
  1708. @"
  1709. 11111│22222
  1710. 11111◊22222
  1711. │ ";
  1712. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1713. // Keyboard movement on splitter should have no effect because it
  1714. // would take us below the minimum splitter size
  1715. line.NewKeyDownEvent (Key.CursorRight);
  1716. Application.LayoutAndDraw ();
  1717. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1718. // but we can continue to move the splitter left if we want
  1719. line.NewKeyDownEvent (Key.CursorLeft);
  1720. Application.LayoutAndDraw ();
  1721. looksLike =
  1722. @"
  1723. 1111│222222
  1724. 1111◊222222
  1725. │ ";
  1726. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1727. }
  1728. [Fact]
  1729. [AutoInitShutdown]
  1730. public void TestTileView_Vertical_View2MinSize_Absolute_WithBorder ()
  1731. {
  1732. TileView tileView = Get11By3TileView (out LineView line, true);
  1733. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1734. tileView.Tiles.ElementAt (1).MinSize = 5;
  1735. // distance leaves too little space for view2 (less than 5 would remain)
  1736. Assert.False (tileView.SetSplitterPos (0, 8));
  1737. Application.LayoutAndDraw ();
  1738. // Should stay where it was originally at (50%)
  1739. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1740. Application.LayoutAndDraw ();
  1741. // so should ignore the 2 distance and stick to 6
  1742. var looksLike =
  1743. @"
  1744. ┌────┬────┐
  1745. │1111◊2222│
  1746. └────┴────┘";
  1747. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1748. // Keyboard movement on splitter should have no effect because it
  1749. // would take us below the minimum splitter size
  1750. line.NewKeyDownEvent (Key.CursorRight);
  1751. Application.LayoutAndDraw ();
  1752. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1753. // but we can continue to move the splitter left if we want
  1754. line.NewKeyDownEvent (Key.CursorLeft);
  1755. Application.LayoutAndDraw ();
  1756. looksLike =
  1757. @"
  1758. ┌───┬─────┐
  1759. │111◊22222│
  1760. └───┴─────┘";
  1761. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1762. }
  1763. [Fact]
  1764. [AutoInitShutdown]
  1765. public void TestTileView_Vertical_WithBorder ()
  1766. {
  1767. TileView tileView = Get11By3TileView (out LineView line, true);
  1768. Application.LayoutAndDraw ();
  1769. var looksLike =
  1770. @"
  1771. ┌────┬────┐
  1772. │1111│2222│
  1773. └────┴────┘";
  1774. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1775. // Keyboard movement on splitter should have no effect if it is not focused
  1776. tileView.NewKeyDownEvent (Key.CursorRight);
  1777. Application.LayoutAndDraw ();
  1778. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1779. }
  1780. [Fact]
  1781. [AutoInitShutdown]
  1782. public void TestTrySplit_ShouldRetainTitle ()
  1783. {
  1784. var tv = new TileView ();
  1785. tv.Tiles.ElementAt (0).Title = "flibble";
  1786. tv.TrySplitTile (0, 2, out TileView subTileView);
  1787. // We moved the content so the title should also have been moved
  1788. Assert.Equal ("flibble", subTileView.Tiles.ElementAt (0).Title);
  1789. // Secondly we should have cleared the old title (it should have been moved not copied)
  1790. Assert.Empty (tv.Tiles.ElementAt (0).Title);
  1791. }
  1792. private TileView Get11By3TileView (out LineView line, bool withBorder = false)
  1793. {
  1794. TileView split = Get11By3TileView (withBorder);
  1795. line = GetLine (split);
  1796. return split;
  1797. }
  1798. private TileView Get11By3TileView (bool withBorder = false) { return GetTileView (11, 3, withBorder); }
  1799. private TileView Get5x1TilesView (bool border = true)
  1800. {
  1801. var tv = new TileView (5)
  1802. {
  1803. Width = 25, Height = 4, LineStyle = LineStyle.Single
  1804. };
  1805. if (!border)
  1806. {
  1807. tv.LineStyle = LineStyle.None;
  1808. }
  1809. tv.Tiles.ElementAt (0)
  1810. .ContentView.Add (
  1811. new Label { Width = Dim.Fill (), Height = 1, Text = new ('1', 100) }
  1812. );
  1813. tv.Tiles.ElementAt (1)
  1814. .ContentView.Add (
  1815. new Label { Width = Dim.Fill (), Height = 1, Text = new ('2', 100) }
  1816. );
  1817. tv.Tiles.ElementAt (2)
  1818. .ContentView.Add (
  1819. new Label { Width = Dim.Fill (), Height = 1, Text = new ('3', 100) }
  1820. );
  1821. tv.Tiles.ElementAt (3)
  1822. .ContentView.Add (
  1823. new Label { Width = Dim.Fill (), Height = 1, Text = new ('4', 100) }
  1824. );
  1825. tv.Tiles.ElementAt (4)
  1826. .ContentView.Add (
  1827. new Label { Width = Dim.Fill (), Height = 1, Text = new ('5', 100) }
  1828. );
  1829. Application.Top = new ();
  1830. Application.Top.Add (tv);
  1831. Application.Begin (Application.Top);
  1832. return tv;
  1833. }
  1834. private LineView GetLine (TileView tileView) { return tileView.SubViews.OfType<LineView> ().Single (); }
  1835. /// <summary>Creates a vertical orientation root container with left pane split into two (with horizontal splitter line).</summary>
  1836. /// <param name="withBorder"></param>
  1837. /// <returns></returns>
  1838. private TileView GetNestedContainer2Left1Right (bool withBorder)
  1839. {
  1840. TileView container = GetTileView (20, 10, withBorder);
  1841. Assert.True (container.TrySplitTile (0, 2, out TileView newContainer));
  1842. newContainer.Orientation = Orientation.Horizontal;
  1843. container.LayoutSubViews ();
  1844. return container;
  1845. }
  1846. /// <summary>Creates a vertical orientation root container with 3 tiles. The rightmost is split horizontally</summary>
  1847. /// <param name="withBorder"></param>
  1848. /// <returns></returns>
  1849. private TileView GetNestedContainer3Right1Down (bool withBorder, bool withTitles = false, int split = 2)
  1850. {
  1851. Application.Top = new ();
  1852. var container = new TileView (3) { Width = 20, Height = 10 };
  1853. container.LineStyle = withBorder ? LineStyle.Single : LineStyle.None;
  1854. Assert.True (container.TrySplitTile (split, 2, out TileView newContainer));
  1855. newContainer.Orientation = Orientation.Horizontal;
  1856. var i = 0;
  1857. foreach (Tile tile in container.Tiles.Union (newContainer.Tiles))
  1858. {
  1859. if (tile.ContentView is TileView)
  1860. {
  1861. continue;
  1862. }
  1863. i++;
  1864. if (withTitles)
  1865. {
  1866. tile.Title = "T" + i;
  1867. }
  1868. tile.ContentView.Add (
  1869. new TextView
  1870. {
  1871. Width = Dim.Fill (),
  1872. Height = Dim.Fill (),
  1873. Text =
  1874. string.Join (
  1875. '\n',
  1876. Enumerable.Repeat (
  1877. new string (i.ToString () [0], 100),
  1878. 10
  1879. )
  1880. .ToArray ()
  1881. ),
  1882. WordWrap = false
  1883. }
  1884. );
  1885. }
  1886. Application.Top.Add (container);
  1887. Application.Begin (Application.Top);
  1888. return container;
  1889. }
  1890. private TileView GetTileView (int width, int height, bool withBorder = false)
  1891. {
  1892. var container = new TileView
  1893. {
  1894. Id = "container",
  1895. Width = width, Height = height
  1896. };
  1897. container.LineStyle = withBorder ? LineStyle.Single : LineStyle.None;
  1898. container.Tiles.ElementAt (0)
  1899. .ContentView.Add (
  1900. new Label { Id = "label1", Width = Dim.Fill (), Height = 1, Text = new ('1', 100) }
  1901. );
  1902. container.Tiles.ElementAt (0)
  1903. .ContentView.Add (
  1904. new Label
  1905. {
  1906. Id = "label2",
  1907. Width = Dim.Fill (),
  1908. Height = 1,
  1909. Y = 1,
  1910. Text = new ('1', 100)
  1911. }
  1912. );
  1913. container.Tiles.ElementAt (1)
  1914. .ContentView.Add (
  1915. new Label { Id = "label3", Width = Dim.Fill (), Height = 1, Text = new ('2', 100) }
  1916. );
  1917. container.Tiles.ElementAt (1)
  1918. .ContentView.Add (
  1919. new Label
  1920. {
  1921. Id = "label4",
  1922. Width = Dim.Fill (),
  1923. Height = 1,
  1924. Y = 1,
  1925. Text = new ('2', 100)
  1926. }
  1927. );
  1928. container.Tiles.ElementAt (0).MinSize = 0;
  1929. container.Tiles.ElementAt (1).MinSize = 0;
  1930. Application.Top = new ();
  1931. Application.Top.Add (container);
  1932. Application.Begin (Application.Top);
  1933. return container;
  1934. }
  1935. private class DisposeCounter : View
  1936. {
  1937. public int DisposalCount;
  1938. protected override void Dispose (bool disposing)
  1939. {
  1940. DisposalCount++;
  1941. base.Dispose (disposing);
  1942. }
  1943. }
  1944. }