TileViewTests.cs 68 KB

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