TileViewTests.cs 74 KB

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