TileViewTests.cs 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402
  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.ColorScheme = new ();
  20. top.ColorScheme = 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, ColorScheme = new (), LineStyle = LineStyle.Single
  1231. };
  1232. tv.TrySplitTile (1, 2, out TileView tv2);
  1233. tv2.ColorScheme = 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, ColorScheme = new (), LineStyle = LineStyle.Single
  1268. };
  1269. var tv2 = new TileView
  1270. {
  1271. Width = Dim.Fill (),
  1272. Height = Dim.Fill (),
  1273. ColorScheme = new (),
  1274. LineStyle = LineStyle.Single,
  1275. Orientation = Orientation.Horizontal
  1276. };
  1277. Assert.True (tv.IsRootTileView ());
  1278. tv.Tiles.ElementAt (1).ContentView.Add (tv2);
  1279. var top = new Toplevel ();
  1280. top.Add (tv);
  1281. tv.BeginInit ();
  1282. tv.EndInit ();
  1283. tv.LayoutSubViews ();
  1284. tv.LayoutSubViews ();
  1285. tv.Tiles.ElementAt (1).ContentView.LayoutSubViews ();
  1286. tv2.LayoutSubViews ();
  1287. // tv2 is still considered a root because
  1288. // it was manually created by API user. That
  1289. // means it will not have its lines joined to
  1290. // parents and it is permitted to have a border
  1291. Assert.True (tv2.IsRootTileView ());
  1292. tv.Draw ();
  1293. var looksLike =
  1294. @"
  1295. ┌────┬───┐
  1296. │ │┌─┐│
  1297. │ │├─┤│
  1298. │ │└─┘│
  1299. └────┴───┘
  1300. ";
  1301. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1302. }
  1303. [Fact]
  1304. [AutoInitShutdown]
  1305. public void TestTileView_CannotSetSplitterPosToFuncEtc ()
  1306. {
  1307. TileView tileView = Get11By3TileView ();
  1308. var ex = Assert.Throws<ArgumentException> (() => tileView.SetSplitterPos (0, Pos.Right (tileView)));
  1309. Assert.Equal ("Only Percent and Absolute values are supported. Passed value was PosView", ex.Message);
  1310. ex = Assert.Throws<ArgumentException> (() => tileView.SetSplitterPos (0, Pos.Func (() => 1)));
  1311. Assert.Equal ("Only Percent and Absolute values are supported. Passed value was PosFunc", ex.Message);
  1312. // Also not allowed because this results in a PosCombine
  1313. ex = Assert.Throws<ArgumentException> (() => tileView.SetSplitterPos (0, Pos.Percent (50) - 1));
  1314. Assert.Equal (
  1315. "Only Percent and Absolute values are supported. Passed value was PosCombine",
  1316. ex.Message
  1317. );
  1318. }
  1319. [Fact]
  1320. [AutoInitShutdown]
  1321. public void TestTileView_Horizontal ()
  1322. {
  1323. TileView tileView = Get11By3TileView (out LineView line);
  1324. tileView.Orientation = Orientation.Horizontal;
  1325. tileView.Layout ();
  1326. tileView.Draw ();
  1327. var looksLike =
  1328. @"
  1329. 11111111111
  1330. ───────────
  1331. 22222222222";
  1332. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1333. // Keyboard movement on splitter should have no effect if it is not focused
  1334. bool handled = tileView.NewKeyDownEvent (Key.CursorDown);
  1335. Assert.False (handled);
  1336. tileView.SetNeedsDraw ();
  1337. tileView.Draw ();
  1338. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1339. }
  1340. [Fact]
  1341. [AutoInitShutdown]
  1342. public void TestTileView_Horizontal_Focused ()
  1343. {
  1344. TileView tileView = Get11By3TileView (out LineView line);
  1345. tileView.Orientation = Orientation.Horizontal;
  1346. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1347. Assert.True (line.HasFocus);
  1348. Application.LayoutAndDraw ();
  1349. var looksLike =
  1350. @"
  1351. 11111111111
  1352. ─────◊─────
  1353. 22222222222";
  1354. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1355. // Now move splitter line down
  1356. tileView.NewKeyDownEvent (Key.CursorDown);
  1357. Application.LayoutAndDraw ();
  1358. looksLike =
  1359. @"
  1360. 11111111111
  1361. 11111111111
  1362. ─────◊─────";
  1363. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1364. // And 2 up
  1365. line.NewKeyDownEvent (Key.CursorUp);
  1366. Application.LayoutAndDraw ();
  1367. line.NewKeyDownEvent (Key.CursorUp);
  1368. Application.LayoutAndDraw ();
  1369. looksLike =
  1370. @"
  1371. ─────◊─────
  1372. 22222222222
  1373. 22222222222";
  1374. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1375. }
  1376. [Fact]
  1377. [AutoInitShutdown]
  1378. public void TestTileView_Horizontal_View1MinSize_Absolute ()
  1379. {
  1380. TileView tileView = Get11By3TileView (out LineView line);
  1381. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1382. tileView.Orientation = Orientation.Horizontal;
  1383. tileView.Tiles.ElementAt (0).MinSize = 1;
  1384. // 0 should not be allowed because it brings us below minimum size of View1
  1385. Assert.False (tileView.SetSplitterPos (0, 0));
  1386. // position should remain where it was, at 50%
  1387. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1388. Application.LayoutAndDraw ();
  1389. var looksLike =
  1390. @"
  1391. 11111111111
  1392. ─────◊─────
  1393. 22222222222";
  1394. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1395. // Now move splitter line down (allowed
  1396. line.NewKeyDownEvent (Key.CursorDown);
  1397. Application.LayoutAndDraw ();
  1398. looksLike =
  1399. @"
  1400. 11111111111
  1401. 11111111111
  1402. ─────◊─────";
  1403. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1404. // And up 2 (only 1 is allowed because of minimum size of 1 on view1)
  1405. line.NewKeyDownEvent (Key.CursorUp);
  1406. line.NewKeyDownEvent (Key.CursorUp);
  1407. tileView.SetNeedsDraw ();
  1408. Application.LayoutAndDraw ();
  1409. looksLike =
  1410. @"
  1411. 11111111111
  1412. ─────◊─────
  1413. 22222222222";
  1414. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1415. }
  1416. [Theory]
  1417. [AutoInitShutdown]
  1418. [InlineData (true)]
  1419. [InlineData (false)]
  1420. public void TestTileView_IndexOf (bool recursive)
  1421. {
  1422. var tv = new TileView ();
  1423. var lbl1 = new Label ();
  1424. var lbl2 = new Label ();
  1425. var frame = new FrameView ();
  1426. var sub = new Label ();
  1427. frame.Add (sub);
  1428. // IndexOf returns -1 when view not found
  1429. Assert.Equal (-1, tv.IndexOf (lbl1, recursive));
  1430. Assert.Equal (-1, tv.IndexOf (lbl2, recursive));
  1431. // IndexOf supports looking for Tile.View
  1432. Assert.Equal (0, tv.IndexOf (tv.Tiles.ElementAt (0).ContentView, recursive));
  1433. Assert.Equal (1, tv.IndexOf (tv.Tiles.ElementAt (1).ContentView, recursive));
  1434. // IndexOf supports looking for Tile.View.SubViews
  1435. tv.Tiles.ElementAt (0).ContentView.Add (lbl1);
  1436. Assert.Equal (0, tv.IndexOf (lbl1, recursive));
  1437. tv.Tiles.ElementAt (1).ContentView.Add (lbl2);
  1438. Assert.Equal (1, tv.IndexOf (lbl2, recursive));
  1439. // IndexOf supports looking deep into subviews only when
  1440. // the recursive true value is passed
  1441. tv.Tiles.ElementAt (1).ContentView.Add (frame);
  1442. if (recursive)
  1443. {
  1444. Assert.Equal (1, tv.IndexOf (sub, recursive));
  1445. }
  1446. else
  1447. {
  1448. Assert.Equal (-1, tv.IndexOf (sub, recursive));
  1449. }
  1450. }
  1451. [Fact]
  1452. [AutoInitShutdown]
  1453. public void TestTileView_InsertPanelAtEnd ()
  1454. {
  1455. TileView tileView = Get11By3TileView (out LineView line, true);
  1456. tileView.InsertTile (2);
  1457. tileView.Layout ();
  1458. tileView.Draw ();
  1459. // so should ignore the 2 distance and stick to 6
  1460. var looksLike =
  1461. @"
  1462. ┌──┬───┬──┐
  1463. │11│222│ │
  1464. └──┴───┴──┘";
  1465. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1466. }
  1467. [Fact]
  1468. [AutoInitShutdown]
  1469. public void TestTileView_InsertPanelAtStart ()
  1470. {
  1471. TileView tileView = Get11By3TileView (out LineView line, true);
  1472. tileView.InsertTile (0);
  1473. tileView.Layout ();
  1474. tileView.Draw ();
  1475. // so should ignore the 2 distance and stick to 6
  1476. var looksLike =
  1477. @"
  1478. ┌──┬───┬──┐
  1479. │ │111│22│
  1480. └──┴───┴──┘";
  1481. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1482. }
  1483. [Fact]
  1484. [AutoInitShutdown]
  1485. public void TestTileView_InsertPanelMiddle ()
  1486. {
  1487. TileView tileView = Get11By3TileView (out LineView line, true);
  1488. tileView.InsertTile (1);
  1489. tileView.Layout ();
  1490. tileView.Draw ();
  1491. // so should ignore the 2 distance and stick to 6
  1492. var looksLike =
  1493. @"
  1494. ┌──┬───┬──┐
  1495. │11│ │22│
  1496. └──┴───┴──┘";
  1497. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1498. }
  1499. [Fact]
  1500. [AutoInitShutdown]
  1501. public void TestTileView_Vertical ()
  1502. {
  1503. TileView tileView = Get11By3TileView (out LineView line);
  1504. tileView.Layout ();
  1505. tileView.Draw ();
  1506. var looksLike =
  1507. @"
  1508. 11111│22222
  1509. 11111│22222
  1510. │ ";
  1511. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1512. // Keyboard movement on splitter should have no effect if it is not focused
  1513. tileView.NewKeyDownEvent (Key.CursorRight);
  1514. tileView.SetNeedsDraw ();
  1515. tileView.Draw ();
  1516. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1517. }
  1518. [Fact]
  1519. [AutoInitShutdown]
  1520. public void TestTileView_Vertical_Focused ()
  1521. {
  1522. TileView tileView = Get11By3TileView (out LineView line);
  1523. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1524. Application.LayoutAndDraw ();
  1525. var looksLike =
  1526. @"
  1527. 11111│22222
  1528. 11111◊22222
  1529. │ ";
  1530. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1531. // Now while focused move the splitter 1 unit right
  1532. line.NewKeyDownEvent (Key.CursorRight);
  1533. Application.LayoutAndDraw ();
  1534. looksLike =
  1535. @"
  1536. 111111│2222
  1537. 111111◊2222
  1538. │ ";
  1539. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1540. // and 2 to the left
  1541. line.NewKeyDownEvent (Key.CursorLeft);
  1542. tileView.Layout ();
  1543. line.NewKeyDownEvent (Key.CursorLeft);
  1544. Application.LayoutAndDraw ();
  1545. looksLike =
  1546. @"
  1547. 1111│222222
  1548. 1111◊222222
  1549. │ ";
  1550. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1551. }
  1552. [Fact]
  1553. [AutoInitShutdown]
  1554. public void TestTileView_Vertical_Focused_50PercentSplit ()
  1555. {
  1556. TileView tileView = Get11By3TileView (out LineView line);
  1557. tileView.SetSplitterPos (0, Pos.Percent (50));
  1558. Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
  1559. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1560. Application.LayoutAndDraw ();
  1561. var looksLike =
  1562. @"
  1563. 11111│22222
  1564. 11111◊22222
  1565. │ ";
  1566. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1567. // Now while focused move the splitter 1 unit right
  1568. line.NewKeyDownEvent (Key.CursorRight);
  1569. Application.LayoutAndDraw ();
  1570. looksLike =
  1571. @"
  1572. 111111│2222
  1573. 111111◊2222
  1574. │ ";
  1575. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1576. // Even when moving the splitter location it should stay a Percentage based one
  1577. Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
  1578. // and 2 to the left
  1579. line.NewKeyDownEvent (Key.CursorLeft);
  1580. tileView.Layout ();
  1581. line.NewKeyDownEvent (Key.CursorLeft);
  1582. Application.LayoutAndDraw ();
  1583. looksLike =
  1584. @"
  1585. 1111│222222
  1586. 1111◊222222
  1587. │ ";
  1588. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1589. // Even when moving the splitter location it should stay a Percentage based one
  1590. Assert.IsType<PosPercent> (tileView.SplitterDistances.ElementAt (0));
  1591. }
  1592. [Fact]
  1593. [AutoInitShutdown]
  1594. public void TestTileView_Vertical_Focused_WithBorder ()
  1595. {
  1596. TileView tileView = Get11By3TileView (out LineView line, true);
  1597. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1598. Application.LayoutAndDraw ();
  1599. var looksLike =
  1600. @"
  1601. ┌────┬────┐
  1602. │1111◊2222│
  1603. └────┴────┘";
  1604. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1605. // Now while focused move the splitter 1 unit right
  1606. line.NewKeyDownEvent (Key.CursorRight);
  1607. Application.LayoutAndDraw ();
  1608. looksLike =
  1609. @"
  1610. ┌─────┬───┐
  1611. │11111◊222│
  1612. └─────┴───┘";
  1613. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1614. // and 2 to the left
  1615. line.NewKeyDownEvent (Key.CursorLeft);
  1616. tileView.Layout ();
  1617. line.NewKeyDownEvent (Key.CursorLeft);
  1618. Application.LayoutAndDraw ();
  1619. looksLike =
  1620. @"
  1621. ┌───┬─────┐
  1622. │111◊22222│
  1623. └───┴─────┘";
  1624. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1625. }
  1626. [Fact]
  1627. [AutoInitShutdown]
  1628. public void TestTileView_Vertical_View1MinSize_Absolute ()
  1629. {
  1630. TileView tileView = Get11By3TileView (out LineView line);
  1631. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1632. tileView.Tiles.ElementAt (0).MinSize = 6;
  1633. // distance is too small (below 6)
  1634. Assert.False (tileView.SetSplitterPos (0, 2));
  1635. // Should stay where it was originally at (50%)
  1636. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1637. Application.LayoutAndDraw ();
  1638. // so should ignore the 2 distance and stick to 6
  1639. var looksLike =
  1640. @"
  1641. 11111│22222
  1642. 11111◊22222
  1643. │ ";
  1644. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1645. // Keyboard movement on splitter should have no effect because it
  1646. // would take us below the minimum splitter size
  1647. line.NewKeyDownEvent (Key.CursorLeft);
  1648. Application.LayoutAndDraw ();
  1649. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1650. // but we can continue to move the splitter right if we want
  1651. line.NewKeyDownEvent (Key.CursorRight);
  1652. Application.LayoutAndDraw ();
  1653. looksLike =
  1654. @"
  1655. 111111│2222
  1656. 111111◊2222
  1657. │ ";
  1658. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1659. }
  1660. [Fact]
  1661. [AutoInitShutdown]
  1662. public void TestTileView_Vertical_View1MinSize_Absolute_WithBorder ()
  1663. {
  1664. TileView tileView = Get11By3TileView (out LineView line, true);
  1665. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1666. tileView.Tiles.ElementAt (0).MinSize = 5;
  1667. // distance is too small (below 5)
  1668. Assert.False (tileView.SetSplitterPos (0, 2));
  1669. // Should stay where it was originally at (50%)
  1670. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1671. Application.LayoutAndDraw ();
  1672. // so should ignore the 2 distance and stick to 5
  1673. var looksLike =
  1674. @"
  1675. ┌────┬────┐
  1676. │1111◊2222│
  1677. └────┴────┘";
  1678. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1679. // Keyboard movement on splitter should have no effect because it
  1680. // would take us below the minimum splitter size
  1681. line.NewKeyDownEvent (Key.CursorLeft);
  1682. Application.LayoutAndDraw ();
  1683. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1684. // but we can continue to move the splitter right if we want
  1685. line.NewKeyDownEvent (Key.CursorRight);
  1686. Application.LayoutAndDraw ();
  1687. looksLike =
  1688. @"
  1689. ┌─────┬───┐
  1690. │11111◊222│
  1691. └─────┴───┘";
  1692. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1693. }
  1694. [Fact]
  1695. [AutoInitShutdown]
  1696. public void TestTileView_Vertical_View2MinSize_Absolute ()
  1697. {
  1698. TileView tileView = Get11By3TileView (out LineView line);
  1699. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1700. tileView.Tiles.ElementAt (1).MinSize = 6;
  1701. Application.LayoutAndDraw ();
  1702. // distance leaves too little space for view2 (less than 6 would remain)
  1703. Assert.False (tileView.SetSplitterPos (0, 8));
  1704. // Should stay where it was originally at (50%)
  1705. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1706. Application.LayoutAndDraw ();
  1707. // so should ignore the 2 distance and stick to 6
  1708. var looksLike =
  1709. @"
  1710. 11111│22222
  1711. 11111◊22222
  1712. │ ";
  1713. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1714. // Keyboard movement on splitter should have no effect because it
  1715. // would take us below the minimum splitter size
  1716. line.NewKeyDownEvent (Key.CursorRight);
  1717. Application.LayoutAndDraw ();
  1718. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1719. // but we can continue to move the splitter left if we want
  1720. line.NewKeyDownEvent (Key.CursorLeft);
  1721. Application.LayoutAndDraw ();
  1722. looksLike =
  1723. @"
  1724. 1111│222222
  1725. 1111◊222222
  1726. │ ";
  1727. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1728. }
  1729. [Fact]
  1730. [AutoInitShutdown]
  1731. public void TestTileView_Vertical_View2MinSize_Absolute_WithBorder ()
  1732. {
  1733. TileView tileView = Get11By3TileView (out LineView line, true);
  1734. tileView.NewKeyDownEvent (new (tileView.ToggleResizable));
  1735. tileView.Tiles.ElementAt (1).MinSize = 5;
  1736. // distance leaves too little space for view2 (less than 5 would remain)
  1737. Assert.False (tileView.SetSplitterPos (0, 8));
  1738. Application.LayoutAndDraw ();
  1739. // Should stay where it was originally at (50%)
  1740. Assert.Equal (Pos.Percent (50), tileView.SplitterDistances.ElementAt (0));
  1741. Application.LayoutAndDraw ();
  1742. // so should ignore the 2 distance and stick to 6
  1743. var looksLike =
  1744. @"
  1745. ┌────┬────┐
  1746. │1111◊2222│
  1747. └────┴────┘";
  1748. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1749. // Keyboard movement on splitter should have no effect because it
  1750. // would take us below the minimum splitter size
  1751. line.NewKeyDownEvent (Key.CursorRight);
  1752. Application.LayoutAndDraw ();
  1753. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1754. // but we can continue to move the splitter left if we want
  1755. line.NewKeyDownEvent (Key.CursorLeft);
  1756. Application.LayoutAndDraw ();
  1757. looksLike =
  1758. @"
  1759. ┌───┬─────┐
  1760. │111◊22222│
  1761. └───┴─────┘";
  1762. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1763. }
  1764. [Fact]
  1765. [AutoInitShutdown]
  1766. public void TestTileView_Vertical_WithBorder ()
  1767. {
  1768. TileView tileView = Get11By3TileView (out LineView line, true);
  1769. Application.LayoutAndDraw ();
  1770. var looksLike =
  1771. @"
  1772. ┌────┬────┐
  1773. │1111│2222│
  1774. └────┴────┘";
  1775. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1776. // Keyboard movement on splitter should have no effect if it is not focused
  1777. tileView.NewKeyDownEvent (Key.CursorRight);
  1778. Application.LayoutAndDraw ();
  1779. DriverAssert.AssertDriverContentsAre (looksLike, output);
  1780. }
  1781. [Fact]
  1782. [AutoInitShutdown]
  1783. public void TestTrySplit_ShouldRetainTitle ()
  1784. {
  1785. var tv = new TileView ();
  1786. tv.Tiles.ElementAt (0).Title = "flibble";
  1787. tv.TrySplitTile (0, 2, out TileView subTileView);
  1788. // We moved the content so the title should also have been moved
  1789. Assert.Equal ("flibble", subTileView.Tiles.ElementAt (0).Title);
  1790. // Secondly we should have cleared the old title (it should have been moved not copied)
  1791. Assert.Empty (tv.Tiles.ElementAt (0).Title);
  1792. }
  1793. private TileView Get11By3TileView (out LineView line, bool withBorder = false)
  1794. {
  1795. TileView split = Get11By3TileView (withBorder);
  1796. line = GetLine (split);
  1797. return split;
  1798. }
  1799. private TileView Get11By3TileView (bool withBorder = false) { return GetTileView (11, 3, withBorder); }
  1800. private TileView Get5x1TilesView (bool border = true)
  1801. {
  1802. var tv = new TileView (5)
  1803. {
  1804. Width = 25, Height = 4, ColorScheme = new (), LineStyle = LineStyle.Single
  1805. };
  1806. if (!border)
  1807. {
  1808. tv.LineStyle = LineStyle.None;
  1809. }
  1810. tv.Tiles.ElementAt (0)
  1811. .ContentView.Add (
  1812. new Label { Width = Dim.Fill (), Height = 1, Text = new ('1', 100) }
  1813. );
  1814. tv.Tiles.ElementAt (1)
  1815. .ContentView.Add (
  1816. new Label { Width = Dim.Fill (), Height = 1, Text = new ('2', 100) }
  1817. );
  1818. tv.Tiles.ElementAt (2)
  1819. .ContentView.Add (
  1820. new Label { Width = Dim.Fill (), Height = 1, Text = new ('3', 100) }
  1821. );
  1822. tv.Tiles.ElementAt (3)
  1823. .ContentView.Add (
  1824. new Label { Width = Dim.Fill (), Height = 1, Text = new ('4', 100) }
  1825. );
  1826. tv.Tiles.ElementAt (4)
  1827. .ContentView.Add (
  1828. new Label { Width = Dim.Fill (), Height = 1, Text = new ('5', 100) }
  1829. );
  1830. Application.Top = new ();
  1831. Application.Top.Add (tv);
  1832. Application.Begin (Application.Top);
  1833. return tv;
  1834. }
  1835. private LineView GetLine (TileView tileView) { return tileView.SubViews.OfType<LineView> ().Single (); }
  1836. /// <summary>Creates a vertical orientation root container with left pane split into two (with horizontal splitter line).</summary>
  1837. /// <param name="withBorder"></param>
  1838. /// <returns></returns>
  1839. private TileView GetNestedContainer2Left1Right (bool withBorder)
  1840. {
  1841. TileView container = GetTileView (20, 10, withBorder);
  1842. Assert.True (container.TrySplitTile (0, 2, out TileView newContainer));
  1843. newContainer.Orientation = Orientation.Horizontal;
  1844. newContainer.ColorScheme = new ();
  1845. container.ColorScheme = new ();
  1846. container.LayoutSubViews ();
  1847. return container;
  1848. }
  1849. /// <summary>Creates a vertical orientation root container with 3 tiles. The rightmost is split horizontally</summary>
  1850. /// <param name="withBorder"></param>
  1851. /// <returns></returns>
  1852. private TileView GetNestedContainer3Right1Down (bool withBorder, bool withTitles = false, int split = 2)
  1853. {
  1854. Application.Top = new ();
  1855. var container = new TileView (3) { Width = 20, Height = 10 };
  1856. container.LineStyle = withBorder ? LineStyle.Single : LineStyle.None;
  1857. Assert.True (container.TrySplitTile (split, 2, out TileView newContainer));
  1858. newContainer.Orientation = Orientation.Horizontal;
  1859. var i = 0;
  1860. foreach (Tile tile in container.Tiles.Union (newContainer.Tiles))
  1861. {
  1862. if (tile.ContentView is TileView)
  1863. {
  1864. continue;
  1865. }
  1866. i++;
  1867. if (withTitles)
  1868. {
  1869. tile.Title = "T" + i;
  1870. }
  1871. tile.ContentView.Add (
  1872. new TextView
  1873. {
  1874. Width = Dim.Fill (),
  1875. Height = Dim.Fill (),
  1876. Text =
  1877. string.Join (
  1878. '\n',
  1879. Enumerable.Repeat (
  1880. new string (i.ToString () [0], 100),
  1881. 10
  1882. )
  1883. .ToArray ()
  1884. ),
  1885. WordWrap = false
  1886. }
  1887. );
  1888. }
  1889. newContainer.ColorScheme = new ();
  1890. container.ColorScheme = new ();
  1891. Application.Top.Add (container);
  1892. Application.Begin (Application.Top);
  1893. return container;
  1894. }
  1895. private TileView GetTileView (int width, int height, bool withBorder = false)
  1896. {
  1897. var container = new TileView
  1898. {
  1899. Id = "container",
  1900. Width = width, Height = height
  1901. };
  1902. container.LineStyle = withBorder ? LineStyle.Single : LineStyle.None;
  1903. container.Tiles.ElementAt (0)
  1904. .ContentView.Add (
  1905. new Label { Id = "label1", Width = Dim.Fill (), Height = 1, Text = new ('1', 100) }
  1906. );
  1907. container.Tiles.ElementAt (0)
  1908. .ContentView.Add (
  1909. new Label
  1910. {
  1911. Id = "label2",
  1912. Width = Dim.Fill (),
  1913. Height = 1,
  1914. Y = 1,
  1915. Text = new ('1', 100)
  1916. }
  1917. );
  1918. container.Tiles.ElementAt (1)
  1919. .ContentView.Add (
  1920. new Label { Id = "label3", Width = Dim.Fill (), Height = 1, Text = new ('2', 100) }
  1921. );
  1922. container.Tiles.ElementAt (1)
  1923. .ContentView.Add (
  1924. new Label
  1925. {
  1926. Id = "label4",
  1927. Width = Dim.Fill (),
  1928. Height = 1,
  1929. Y = 1,
  1930. Text = new ('2', 100)
  1931. }
  1932. );
  1933. container.Tiles.ElementAt (0).MinSize = 0;
  1934. container.Tiles.ElementAt (1).MinSize = 0;
  1935. Application.Top = new ();
  1936. Application.Top.Add (container);
  1937. container.ColorScheme = new ();
  1938. Application.Begin (Application.Top);
  1939. return container;
  1940. }
  1941. private class DisposeCounter : View
  1942. {
  1943. public int DisposalCount;
  1944. protected override void Dispose (bool disposing)
  1945. {
  1946. DisposalCount++;
  1947. base.Dispose (disposing);
  1948. }
  1949. }
  1950. }