TileViewTests.cs 75 KB

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