TileViewTests.cs 64 KB

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