TileViewTests.cs 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457
  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. tileView.SetSplitterPos (0, 2);
  176. // Should bound the value to the minimum distance
  177. Assert.Equal (6, 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. 111111│2222
  183. 111111◊2222
  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. 1111111│222
  199. 1111111◊222
  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. tileView.SetSplitterPos (0, 2);
  211. // Should bound the value to the minimum distance
  212. Assert.Equal (6, 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. │11111◊222│
  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. │111111◊22│
  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. tileView.SetSplitterPos (0, 8);
  246. // Should bound the value to the minimum distance
  247. Assert.Equal (4, 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. 1111│222222
  253. 1111◊222222
  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. 111│2222222
  269. 111◊2222222
  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. tileView.SetSplitterPos (0, 8);
  281. // Should bound the value to the minimum distance
  282. Assert.Equal (4, 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. │111◊22222│
  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. │11◊222222│
  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.Redraw (tileView.Bounds);
  379. looksLike =
  380. @"
  381. ─────◊─────
  382. 22222222222
  383. 22222222222";
  384. TestHelpers.AssertDriverContentsAre (looksLike, output);
  385. }
  386. [Fact, AutoInitShutdown]
  387. public void TestTileView_Horizontal_View1MinSize_Absolute ()
  388. {
  389. var tileView = Get11By3TileView (out var line);
  390. tileView.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
  391. SetInputFocusLine (tileView);
  392. tileView.Tiles.ElementAt (0).MinSize = 1;
  393. // 0 should not be allowed because it brings us below minimum size of View1
  394. tileView.SetSplitterPos (0, 0);
  395. Assert.Equal ((Pos)1, tileView.SplitterDistances.ElementAt (0));
  396. tileView.Redraw (tileView.Bounds);
  397. string looksLike =
  398. @"
  399. 11111111111
  400. ─────◊─────
  401. 22222222222";
  402. TestHelpers.AssertDriverContentsAre (looksLike, output);
  403. // Now move splitter line down (allowed
  404. line.ProcessKey (new KeyEvent (Key.CursorDown, new KeyModifiers ()));
  405. tileView.Redraw (tileView.Bounds);
  406. looksLike =
  407. @"
  408. 11111111111
  409. 11111111111
  410. ─────◊─────";
  411. TestHelpers.AssertDriverContentsAre (looksLike, output);
  412. // And up 2 (only 1 is allowed because of minimum size of 1 on view1)
  413. line.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()));
  414. line.ProcessKey (new KeyEvent (Key.CursorUp, new KeyModifiers ()));
  415. tileView.Redraw (tileView.Bounds);
  416. looksLike =
  417. @"
  418. 11111111111
  419. ─────◊─────
  420. 22222222222";
  421. TestHelpers.AssertDriverContentsAre (looksLike, output);
  422. }
  423. [Fact, AutoInitShutdown]
  424. public void TestTileView_CannotSetSplitterPosToFuncEtc ()
  425. {
  426. var tileView = Get11By3TileView ();
  427. var ex = Assert.Throws<ArgumentException> (() => tileView.SetSplitterPos (0, Pos.Right (tileView)));
  428. Assert.Equal ("Only Percent and Absolute values are supported. Passed value was PosCombine", ex.Message);
  429. ex = Assert.Throws<ArgumentException> (() => tileView.SetSplitterPos (0, Pos.Function (() => 1)));
  430. Assert.Equal ("Only Percent and Absolute values are supported. Passed value was PosFunc", ex.Message);
  431. // Also not allowed because this results in a PosCombine
  432. ex = Assert.Throws<ArgumentException> (() => tileView.SetSplitterPos (0, Pos.Percent (50) - 1));
  433. Assert.Equal ("Only Percent and Absolute values are supported. Passed value was PosCombine", ex.Message);
  434. }
  435. [Fact, AutoInitShutdown]
  436. public void TestNestedContainer2LeftAnd1Right_RendersNicely ()
  437. {
  438. var tileView = GetNestedContainer2Left1Right (false);
  439. Assert.Equal (20, tileView.Frame.Width);
  440. Assert.Equal (10, tileView.Tiles.ElementAt (0).View.Frame.Width);
  441. Assert.Equal (9, tileView.Tiles.ElementAt (1).View.Frame.Width);
  442. Assert.IsType<TileView> (tileView.Tiles.ElementAt (0).View);
  443. var left = (TileView)tileView.Tiles.ElementAt (0).View;
  444. Assert.Same (left.SuperView, tileView);
  445. Assert.Equal (2, left.Tiles.ElementAt (0).View.Subviews.Count);
  446. Assert.IsType<Label> (left.Tiles.ElementAt (0).View.Subviews [0]);
  447. Assert.IsType<Label> (left.Tiles.ElementAt (0).View.Subviews [1]);
  448. var onesTop = (Label)left.Tiles.ElementAt (0).View.Subviews [0];
  449. var onesBottom = (Label)left.Tiles.ElementAt (0).View.Subviews [1];
  450. Assert.Same (left.Tiles.ElementAt (0).View, onesTop.SuperView);
  451. Assert.Same (left.Tiles.ElementAt (0).View, onesBottom.SuperView);
  452. Assert.Equal (10, onesTop.Frame.Width);
  453. Assert.Equal (10, onesBottom.Frame.Width);
  454. tileView.Redraw (tileView.Bounds);
  455. string looksLike =
  456. @"
  457. 1111111111│222222222
  458. 1111111111│222222222
  459. ──────────┤
  460. │";
  461. TestHelpers.AssertDriverContentsAre (looksLike, output);
  462. }
  463. [Fact, AutoInitShutdown]
  464. public void TestNestedContainer3RightAnd1Down_RendersNicely ()
  465. {
  466. var tileView = GetNestedContainer3Right1Down (false);
  467. tileView.Redraw (tileView.Bounds);
  468. string looksLike =
  469. @"
  470. 111111│222222│333333
  471. 111111│222222│333333
  472. 111111│222222│333333
  473. 111111│222222│333333
  474. 111111│222222│333333
  475. 111111│222222├──────
  476. 111111│222222│444444
  477. 111111│222222│444444
  478. 111111│222222│444444
  479. 111111│222222│444444
  480. ";
  481. TestHelpers.AssertDriverContentsAre (looksLike, output);
  482. // It looks good but lets double check the measurements incase
  483. // anything is sticking out but drawn over
  484. // 3 panels + 2 splitters
  485. Assert.Equal (5, tileView.Subviews.Count);
  486. // Check X and Widths of Tiles
  487. Assert.Equal (0, tileView.Tiles.ElementAt (0).View.Frame.X);
  488. Assert.Equal (6, tileView.Tiles.ElementAt (0).View.Frame.Width);
  489. Assert.Equal (7, tileView.Tiles.ElementAt (1).View.Frame.X);
  490. Assert.Equal (6, tileView.Tiles.ElementAt (1).View.Frame.Width);
  491. Assert.Equal (14, tileView.Tiles.ElementAt (2).View.Frame.X);
  492. Assert.Equal (6, tileView.Tiles.ElementAt (2).View.Frame.Width);
  493. // Check Y and Heights of Tiles
  494. Assert.Equal (0, tileView.Tiles.ElementAt (0).View.Frame.Y);
  495. Assert.Equal (10, tileView.Tiles.ElementAt (0).View.Frame.Height);
  496. Assert.Equal (0, tileView.Tiles.ElementAt (1).View.Frame.Y);
  497. Assert.Equal (10, tileView.Tiles.ElementAt (1).View.Frame.Height);
  498. Assert.Equal (0, tileView.Tiles.ElementAt (2).View.Frame.Y);
  499. Assert.Equal (10, tileView.Tiles.ElementAt (2).View.Frame.Height);
  500. // Check Sub containers in last panel
  501. var subSplit = (TileView)tileView.Tiles.ElementAt (2).View;
  502. Assert.Equal (0, subSplit.Tiles.ElementAt (0).View.Frame.X);
  503. Assert.Equal (6, subSplit.Tiles.ElementAt (0).View.Frame.Width);
  504. Assert.Equal (0, subSplit.Tiles.ElementAt (0).View.Frame.Y);
  505. Assert.Equal (5, subSplit.Tiles.ElementAt (0).View.Frame.Height);
  506. Assert.IsType<TextView> (subSplit.Tiles.ElementAt (0).View.Subviews.Single ());
  507. Assert.Equal (0, subSplit.Tiles.ElementAt (1).View.Frame.X);
  508. Assert.Equal (6, subSplit.Tiles.ElementAt (1).View.Frame.Width);
  509. Assert.Equal (6, subSplit.Tiles.ElementAt (1).View.Frame.Y);
  510. Assert.Equal (4, subSplit.Tiles.ElementAt (1).View.Frame.Height);
  511. Assert.IsType<TextView> (subSplit.Tiles.ElementAt (1).View.Subviews.Single ());
  512. }
  513. [Fact, AutoInitShutdown]
  514. public void TestNestedContainer3RightAnd1Down_WithBorder_RendersNicely ()
  515. {
  516. var tileView = GetNestedContainer3Right1Down (true);
  517. tileView.Redraw (tileView.Bounds);
  518. string looksLike =
  519. @"
  520. ┌─────┬──────┬─────┐
  521. │11111│222222│33333│
  522. │11111│222222│33333│
  523. │11111│222222│33333│
  524. │11111│222222│33333│
  525. │11111│222222├─────┤
  526. │11111│222222│44444│
  527. │11111│222222│44444│
  528. │11111│222222│44444│
  529. └─────┴──────┴─────┘";
  530. TestHelpers.AssertDriverContentsAre (looksLike, output);
  531. // It looks good but lets double check the measurements incase
  532. // anything is sticking out but drawn over
  533. // 3 panels + 2 splitters
  534. Assert.Equal (5, tileView.Subviews.Count);
  535. // Check X and Widths of Tiles
  536. Assert.Equal (1, tileView.Tiles.ElementAt (0).View.Frame.X);
  537. Assert.Equal (5, tileView.Tiles.ElementAt (0).View.Frame.Width);
  538. Assert.Equal (7, tileView.Tiles.ElementAt (1).View.Frame.X);
  539. Assert.Equal (6, tileView.Tiles.ElementAt (1).View.Frame.Width);
  540. Assert.Equal (14, tileView.Tiles.ElementAt (2).View.Frame.X);
  541. Assert.Equal (5, tileView.Tiles.ElementAt (2).View.Frame.Width);
  542. // Check Y and Heights of Tiles
  543. Assert.Equal (1, tileView.Tiles.ElementAt (0).View.Frame.Y);
  544. Assert.Equal (8, tileView.Tiles.ElementAt (0).View.Frame.Height);
  545. Assert.Equal (1, tileView.Tiles.ElementAt (1).View.Frame.Y);
  546. Assert.Equal (8, tileView.Tiles.ElementAt (1).View.Frame.Height);
  547. Assert.Equal (1, tileView.Tiles.ElementAt (2).View.Frame.Y);
  548. Assert.Equal (8, tileView.Tiles.ElementAt (2).View.Frame.Height);
  549. // Check Sub containers in last panel
  550. var subSplit = (TileView)tileView.Tiles.ElementAt (2).View;
  551. Assert.Equal (0, subSplit.Tiles.ElementAt (0).View.Frame.X);
  552. Assert.Equal (5, subSplit.Tiles.ElementAt (0).View.Frame.Width);
  553. Assert.Equal (0, subSplit.Tiles.ElementAt (0).View.Frame.Y);
  554. Assert.Equal (4, subSplit.Tiles.ElementAt (0).View.Frame.Height);
  555. Assert.IsType<TextView> (subSplit.Tiles.ElementAt (0).View.Subviews.Single ());
  556. Assert.Equal (0, subSplit.Tiles.ElementAt (1).View.Frame.X);
  557. Assert.Equal (5, subSplit.Tiles.ElementAt (1).View.Frame.Width);
  558. Assert.Equal (5, subSplit.Tiles.ElementAt (1).View.Frame.Y);
  559. Assert.Equal (3, subSplit.Tiles.ElementAt (1).View.Frame.Height);
  560. Assert.IsType<TextView> (subSplit.Tiles.ElementAt (1).View.Subviews.Single ());
  561. }
  562. [Fact, AutoInitShutdown]
  563. public void TestNestedContainer3RightAnd1Down_WithTitledBorder_RendersNicely ()
  564. {
  565. var tileView = GetNestedContainer3Right1Down (true, true);
  566. tileView.Redraw (tileView.Bounds);
  567. string looksLike =
  568. @"
  569. ┌T1───┬T2────┬T3───┐
  570. │11111│222222│33333│
  571. │11111│222222│33333│
  572. │11111│222222│33333│
  573. │11111│222222│33333│
  574. │11111│222222├T4───┤
  575. │11111│222222│44444│
  576. │11111│222222│44444│
  577. │11111│222222│44444│
  578. └─────┴──────┴─────┘";
  579. TestHelpers.AssertDriverContentsAre (looksLike, output);
  580. }
  581. [Fact, AutoInitShutdown]
  582. public void TestNestedContainer3RightAnd1Down_WithBorder_RemovingTiles ()
  583. {
  584. var tileView = GetNestedContainer3Right1Down (true);
  585. tileView.Redraw (tileView.Bounds);
  586. string looksLike =
  587. @"
  588. ┌─────┬──────┬─────┐
  589. │11111│222222│33333│
  590. │11111│222222│33333│
  591. │11111│222222│33333│
  592. │11111│222222│33333│
  593. │11111│222222├─────┤
  594. │11111│222222│44444│
  595. │11111│222222│44444│
  596. │11111│222222│44444│
  597. └─────┴──────┴─────┘";
  598. TestHelpers.AssertDriverContentsAre (looksLike, output);
  599. var toRemove = tileView.Tiles.ElementAt (1);
  600. var removed = tileView.RemoveTile (1);
  601. Assert.Same (toRemove, removed);
  602. Assert.DoesNotContain (removed, tileView.Tiles);
  603. tileView.Redraw (tileView.Bounds);
  604. looksLike =
  605. @"
  606. ┌─────────┬────────┐
  607. │111111111│33333333│
  608. │111111111│33333333│
  609. │111111111│33333333│
  610. │111111111│33333333│
  611. │111111111├────────┤
  612. │111111111│44444444│
  613. │111111111│44444444│
  614. │111111111│44444444│
  615. └─────────┴────────┘";
  616. TestHelpers.AssertDriverContentsAre (looksLike, output);
  617. // cannot remove at this index because there is only one horizontal tile left
  618. Assert.Null (tileView.RemoveTile (2));
  619. tileView.RemoveTile (0);
  620. tileView.Redraw (tileView.Bounds);
  621. looksLike =
  622. @"
  623. ┌──────────────────┐
  624. │333333333333333333│
  625. │333333333333333333│
  626. │333333333333333333│
  627. │333333333333333333│
  628. ├──────────────────┤
  629. │444444444444444444│
  630. │444444444444444444│
  631. │444444444444444444│
  632. └──────────────────┘";
  633. TestHelpers.AssertDriverContentsAre (looksLike, output);
  634. Assert.NotNull (tileView.RemoveTile (0));
  635. tileView.Redraw (tileView.Bounds);
  636. looksLike =
  637. @"
  638. ┌──────────────────┐
  639. │ │
  640. │ │
  641. │ │
  642. │ │
  643. │ │
  644. │ │
  645. │ │
  646. │ │
  647. └──────────────────┘";
  648. TestHelpers.AssertDriverContentsAre (looksLike, output);
  649. // cannot remove
  650. Assert.Null (tileView.RemoveTile (0));
  651. }
  652. [Theory, AutoInitShutdown]
  653. [InlineData (true)]
  654. [InlineData (false)]
  655. public void TestTileView_IndexOf (bool recursive)
  656. {
  657. var tv = new TileView ();
  658. var lbl1 = new Label ();
  659. var lbl2 = new Label ();
  660. var frame = new FrameView ();
  661. var sub = new Label ();
  662. frame.Add (sub);
  663. // IndexOf returns -1 when view not found
  664. Assert.Equal (-1, tv.IndexOf (lbl1, recursive));
  665. Assert.Equal (-1, tv.IndexOf (lbl2, recursive));
  666. // IndexOf supports looking for Tile.View
  667. Assert.Equal (0, tv.IndexOf (tv.Tiles.ElementAt (0).View, recursive));
  668. Assert.Equal (1, tv.IndexOf (tv.Tiles.ElementAt (1).View, recursive));
  669. // IndexOf supports looking for Tile.View.Subviews
  670. tv.Tiles.ElementAt (0).View.Add (lbl1);
  671. Assert.Equal (0, tv.IndexOf (lbl1, recursive));
  672. tv.Tiles.ElementAt (1).View.Add (lbl2);
  673. Assert.Equal (1, tv.IndexOf (lbl2, recursive));
  674. // IndexOf supports looking deep into subviews only when
  675. // the recursive true value is passed
  676. tv.Tiles.ElementAt (1).View.Add (frame);
  677. if (recursive) {
  678. Assert.Equal (1, tv.IndexOf (sub, recursive));
  679. } else {
  680. Assert.Equal (-1, tv.IndexOf (sub, recursive));
  681. }
  682. }
  683. [Fact, AutoInitShutdown]
  684. public void TestNestedRoots_BothRoots_BothCanHaveBorders ()
  685. {
  686. var tv = new TileView { Width = 10, Height = 5, ColorScheme = new ColorScheme (), IntegratedBorder = BorderStyle.Single };
  687. var tv2 = new TileView {
  688. Width = Dim.Fill (),
  689. Height = Dim.Fill (),
  690. ColorScheme = new ColorScheme (),
  691. IntegratedBorder = BorderStyle.Single,
  692. Orientation = Orientation.Horizontal
  693. };
  694. Assert.True (tv.IsRootTileView ());
  695. tv.Tiles.ElementAt (1).View.Add (tv2);
  696. Application.Top.Add (tv);
  697. tv.BeginInit ();
  698. tv.EndInit ();
  699. tv.LayoutSubviews ();
  700. tv.LayoutSubviews ();
  701. tv.Tiles.ElementAt (1).View.LayoutSubviews ();
  702. tv2.LayoutSubviews ();
  703. // tv2 is still considered a root because
  704. // it was manually created by API user. That
  705. // means it will not have its lines joined to
  706. // parents and it is permitted to have a border
  707. Assert.True (tv2.IsRootTileView ());
  708. tv.Redraw (tv.Bounds);
  709. var looksLike =
  710. @"
  711. ┌────┬───┐
  712. │ │┌─┐│
  713. │ │├─┤│
  714. │ │└─┘│
  715. └────┴───┘
  716. ";
  717. TestHelpers.AssertDriverContentsAre (looksLike, output);
  718. }
  719. [Fact,AutoInitShutdown]
  720. public void Test5Panel_MinSizes_VerticalSplitters()
  721. {
  722. var tv = new TileView (5){ Width = 25, Height = 4, ColorScheme = new ColorScheme (), IntegratedBorder = BorderStyle.Single };
  723. tv.Tiles.ElementAt (0).View.Add (new Label(new string('1',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
  724. tv.Tiles.ElementAt (1).View.Add (new Label(new string('2',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
  725. tv.Tiles.ElementAt (2).View.Add (new Label(new string('3',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
  726. tv.Tiles.ElementAt (3).View.Add (new Label(new string('4',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
  727. tv.Tiles.ElementAt (4).View.Add (new Label(new string('5',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
  728. Application.Top.Add (tv);
  729. tv.BeginInit ();
  730. tv.EndInit ();
  731. tv.LayoutSubviews ();
  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. // TODO : Apply min sizes and create test assertions
  742. }
  743. [Fact, AutoInitShutdown]
  744. public void TestNestedNonRoots_OnlyOneRoot_OnlyRootCanHaveBorders ()
  745. {
  746. var tv = new TileView { Width = 10, Height = 5, ColorScheme = new ColorScheme (), IntegratedBorder = BorderStyle.Single };
  747. tv.TrySplitTile (1, 2, out var tv2);
  748. tv2.ColorScheme = new ColorScheme ();
  749. tv2.IntegratedBorder = BorderStyle.Single; // will not be respected
  750. tv2.Orientation = Orientation.Horizontal;
  751. Assert.True (tv.IsRootTileView ());
  752. Application.Top.Add (tv);
  753. tv.BeginInit ();
  754. tv.EndInit ();
  755. tv.LayoutSubviews ();
  756. tv.LayoutSubviews ();
  757. tv.Tiles.ElementAt (1).View.LayoutSubviews ();
  758. tv2.LayoutSubviews ();
  759. // tv2 is not considered a root because
  760. // it was created via TrySplitTile so it
  761. // will have its lines joined to
  762. // parent and cannot have its own border
  763. Assert.False (tv2.IsRootTileView ());
  764. tv.Redraw (tv.Bounds);
  765. var looksLike =
  766. @"
  767. ┌────┬───┐
  768. │ │ │
  769. │ ├───┤
  770. │ │ │
  771. └────┴───┘
  772. ";
  773. TestHelpers.AssertDriverContentsAre (looksLike, output);
  774. }
  775. [Fact, AutoInitShutdown]
  776. public void TestNestedContainer3RightAnd1Down_TileVisibility_WithBorder ()
  777. {
  778. var tileView = GetNestedContainer3Right1Down (true);
  779. tileView.Redraw (tileView.Bounds);
  780. string looksLike =
  781. @"
  782. ┌─────┬──────┬─────┐
  783. │11111│222222│33333│
  784. │11111│222222│33333│
  785. │11111│222222│33333│
  786. │11111│222222│33333│
  787. │11111│222222├─────┤
  788. │11111│222222│44444│
  789. │11111│222222│44444│
  790. │11111│222222│44444│
  791. └─────┴──────┴─────┘";
  792. TestHelpers.AssertDriverContentsAre (looksLike, output);
  793. tileView.Tiles.ElementAt (0).View.Visible = false;
  794. tileView.Tiles.ElementAt (1).View.Visible = true;
  795. tileView.Tiles.ElementAt (2).View.Visible = true;
  796. tileView.LayoutSubviews ();
  797. tileView.Redraw (tileView.Bounds);
  798. looksLike =
  799. @"
  800. ┌────────────┬─────┐
  801. │222222222222│33333│
  802. │222222222222│33333│
  803. │222222222222│33333│
  804. │222222222222│33333│
  805. │222222222222├─────┤
  806. │222222222222│44444│
  807. │222222222222│44444│
  808. │222222222222│44444│
  809. └────────────┴─────┘";
  810. TestHelpers.AssertDriverContentsAre (looksLike, output);
  811. tileView.Tiles.ElementAt (0).View.Visible = true;
  812. tileView.Tiles.ElementAt (1).View.Visible = false;
  813. tileView.Tiles.ElementAt (2).View.Visible = true;
  814. tileView.LayoutSubviews ();
  815. tileView.Redraw (tileView.Bounds);
  816. looksLike =
  817. @"
  818. ┌────────────┬─────┐
  819. │111111111111│33333│
  820. │111111111111│33333│
  821. │111111111111│33333│
  822. │111111111111│33333│
  823. │111111111111├─────┤
  824. │111111111111│44444│
  825. │111111111111│44444│
  826. │111111111111│44444│
  827. └────────────┴─────┘";
  828. TestHelpers.AssertDriverContentsAre (looksLike, output);
  829. tileView.Tiles.ElementAt (0).View.Visible = true;
  830. tileView.Tiles.ElementAt (1).View.Visible = true;
  831. tileView.Tiles.ElementAt (2).View.Visible = false;
  832. tileView.LayoutSubviews ();
  833. tileView.Redraw (tileView.Bounds);
  834. looksLike =
  835. @"
  836. ┌─────┬────────────┐
  837. │11111│222222222222│
  838. │11111│222222222222│
  839. │11111│222222222222│
  840. │11111│222222222222│
  841. │11111│222222222222│
  842. │11111│222222222222│
  843. │11111│222222222222│
  844. │11111│222222222222│
  845. └─────┴────────────┘";
  846. TestHelpers.AssertDriverContentsAre (looksLike, output);
  847. tileView.Tiles.ElementAt (0).View.Visible = true;
  848. tileView.Tiles.ElementAt (1).View.Visible = false;
  849. tileView.Tiles.ElementAt (2).View.Visible = false;
  850. tileView.LayoutSubviews ();
  851. tileView.Redraw (tileView.Bounds);
  852. looksLike =
  853. @"
  854. ┌──────────────────┐
  855. │111111111111111111│
  856. │111111111111111111│
  857. │111111111111111111│
  858. │111111111111111111│
  859. │111111111111111111│
  860. │111111111111111111│
  861. │111111111111111111│
  862. │111111111111111111│
  863. └──────────────────┘";
  864. TestHelpers.AssertDriverContentsAre (looksLike, output);
  865. tileView.Tiles.ElementAt (0).View.Visible = false;
  866. tileView.Tiles.ElementAt (1).View.Visible = true;
  867. tileView.Tiles.ElementAt (2).View.Visible = false;
  868. tileView.LayoutSubviews ();
  869. tileView.Redraw (tileView.Bounds);
  870. looksLike =
  871. @"
  872. ┌──────────────────┐
  873. │222222222222222222│
  874. │222222222222222222│
  875. │222222222222222222│
  876. │222222222222222222│
  877. │222222222222222222│
  878. │222222222222222222│
  879. │222222222222222222│
  880. │222222222222222222│
  881. └──────────────────┘";
  882. TestHelpers.AssertDriverContentsAre (looksLike, output);
  883. tileView.Tiles.ElementAt (0).View.Visible = false;
  884. tileView.Tiles.ElementAt (1).View.Visible = false;
  885. tileView.Tiles.ElementAt (2).View.Visible = true;
  886. tileView.LayoutSubviews ();
  887. tileView.Redraw (tileView.Bounds);
  888. looksLike =
  889. @"
  890. ┌──────────────────┐
  891. │333333333333333333│
  892. │333333333333333333│
  893. │333333333333333333│
  894. │333333333333333333│
  895. ├──────────────────┤
  896. │444444444444444444│
  897. │444444444444444444│
  898. │444444444444444444│
  899. └──────────────────┘";
  900. TestHelpers.AssertDriverContentsAre (looksLike, output);
  901. TestHelpers.AssertDriverContentsAre (looksLike, output);
  902. tileView.Tiles.ElementAt (0).View.Visible = false;
  903. tileView.Tiles.ElementAt (1).View.Visible = false;
  904. tileView.Tiles.ElementAt (2).View.Visible = false;
  905. tileView.LayoutSubviews ();
  906. tileView.Redraw (tileView.Bounds);
  907. looksLike =
  908. @"
  909. ┌──────────────────┐
  910. │ │
  911. │ │
  912. │ │
  913. │ │
  914. │ │
  915. │ │
  916. │ │
  917. │ │
  918. └──────────────────┘";
  919. TestHelpers.AssertDriverContentsAre (looksLike, output);
  920. }
  921. [Fact, AutoInitShutdown]
  922. public void TestNestedContainer3RightAnd1Down_TileVisibility_WithoutBorder ()
  923. {
  924. var tileView = GetNestedContainer3Right1Down (false);
  925. tileView.Redraw (tileView.Bounds);
  926. string looksLike =
  927. @"
  928. 111111│222222│333333
  929. 111111│222222│333333
  930. 111111│222222│333333
  931. 111111│222222│333333
  932. 111111│222222│333333
  933. 111111│222222├──────
  934. 111111│222222│444444
  935. 111111│222222│444444
  936. 111111│222222│444444
  937. 111111│222222│444444";
  938. TestHelpers.AssertDriverContentsAre (looksLike, output);
  939. tileView.Tiles.ElementAt (0).View.Visible = false;
  940. tileView.Tiles.ElementAt (1).View.Visible = true;
  941. tileView.Tiles.ElementAt (2).View.Visible = true;
  942. tileView.LayoutSubviews ();
  943. tileView.Redraw (tileView.Bounds);
  944. looksLike =
  945. @"
  946. 2222222222222│333333
  947. 2222222222222│333333
  948. 2222222222222│333333
  949. 2222222222222│333333
  950. 2222222222222│333333
  951. 2222222222222├──────
  952. 2222222222222│444444
  953. 2222222222222│444444
  954. 2222222222222│444444
  955. 2222222222222│444444";
  956. TestHelpers.AssertDriverContentsAre (looksLike, output);
  957. tileView.Tiles.ElementAt (0).View.Visible = true;
  958. tileView.Tiles.ElementAt (1).View.Visible = false;
  959. tileView.Tiles.ElementAt (2).View.Visible = true;
  960. tileView.LayoutSubviews ();
  961. tileView.Redraw (tileView.Bounds);
  962. looksLike =
  963. @"
  964. 1111111111111│333333
  965. 1111111111111│333333
  966. 1111111111111│333333
  967. 1111111111111│333333
  968. 1111111111111│333333
  969. 1111111111111├──────
  970. 1111111111111│444444
  971. 1111111111111│444444
  972. 1111111111111│444444
  973. 1111111111111│444444";
  974. TestHelpers.AssertDriverContentsAre (looksLike, output);
  975. tileView.Tiles.ElementAt (0).View.Visible = true;
  976. tileView.Tiles.ElementAt (1).View.Visible = true;
  977. tileView.Tiles.ElementAt (2).View.Visible = false;
  978. tileView.LayoutSubviews ();
  979. tileView.Redraw (tileView.Bounds);
  980. looksLike =
  981. @"
  982. 111111│2222222222222
  983. 111111│2222222222222
  984. 111111│2222222222222
  985. 111111│2222222222222
  986. 111111│2222222222222
  987. 111111│2222222222222
  988. 111111│2222222222222
  989. 111111│2222222222222
  990. 111111│2222222222222
  991. 111111│2222222222222";
  992. TestHelpers.AssertDriverContentsAre (looksLike, output);
  993. tileView.Tiles.ElementAt (0).View.Visible = true;
  994. tileView.Tiles.ElementAt (1).View.Visible = false;
  995. tileView.Tiles.ElementAt (2).View.Visible = false;
  996. tileView.LayoutSubviews ();
  997. tileView.Redraw (tileView.Bounds);
  998. looksLike =
  999. @"
  1000. 11111111111111111111
  1001. 11111111111111111111
  1002. 11111111111111111111
  1003. 11111111111111111111
  1004. 11111111111111111111
  1005. 11111111111111111111
  1006. 11111111111111111111
  1007. 11111111111111111111
  1008. 11111111111111111111
  1009. 11111111111111111111";
  1010. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1011. tileView.Tiles.ElementAt (0).View.Visible = false;
  1012. tileView.Tiles.ElementAt (1).View.Visible = true;
  1013. tileView.Tiles.ElementAt (2).View.Visible = false;
  1014. tileView.LayoutSubviews ();
  1015. tileView.Redraw (tileView.Bounds);
  1016. looksLike =
  1017. @"
  1018. 22222222222222222222
  1019. 22222222222222222222
  1020. 22222222222222222222
  1021. 22222222222222222222
  1022. 22222222222222222222
  1023. 22222222222222222222
  1024. 22222222222222222222
  1025. 22222222222222222222
  1026. 22222222222222222222
  1027. 22222222222222222222";
  1028. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1029. tileView.Tiles.ElementAt (0).View.Visible = false;
  1030. tileView.Tiles.ElementAt (1).View.Visible = false;
  1031. tileView.Tiles.ElementAt (2).View.Visible = true;
  1032. tileView.LayoutSubviews ();
  1033. tileView.Redraw (tileView.Bounds);
  1034. looksLike =
  1035. @"
  1036. 33333333333333333333
  1037. 33333333333333333333
  1038. 33333333333333333333
  1039. 33333333333333333333
  1040. 33333333333333333333
  1041. ────────────────────
  1042. 44444444444444444444
  1043. 44444444444444444444
  1044. 44444444444444444444
  1045. 44444444444444444444";
  1046. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1047. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1048. tileView.Tiles.ElementAt (0).View.Visible = false;
  1049. tileView.Tiles.ElementAt (1).View.Visible = false;
  1050. tileView.Tiles.ElementAt (2).View.Visible = false;
  1051. tileView.LayoutSubviews ();
  1052. tileView.Redraw (tileView.Bounds);
  1053. looksLike =
  1054. @"
  1055. ";
  1056. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1057. }
  1058. /// <summary>
  1059. /// Creates a vertical orientation root container with left pane split into
  1060. /// two (with horizontal splitter line).
  1061. /// </summary>
  1062. /// <param name="withBorder"></param>
  1063. /// <returns></returns>
  1064. private TileView GetNestedContainer2Left1Right (bool withBorder)
  1065. {
  1066. var container = GetTileView (20, 10, withBorder);
  1067. Assert.True (container.TrySplitTile (0, 2, out var newContainer));
  1068. newContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
  1069. newContainer.ColorScheme = new ColorScheme ();
  1070. container.ColorScheme = new ColorScheme ();
  1071. container.LayoutSubviews ();
  1072. return container;
  1073. }
  1074. /// <summary>
  1075. /// Creates a vertical orientation root container with 3 tiles.
  1076. /// The rightmost is split horizontally
  1077. /// </summary>
  1078. /// <param name="withBorder"></param>
  1079. /// <returns></returns>
  1080. private TileView GetNestedContainer3Right1Down (bool withBorder, bool withTitles = false)
  1081. {
  1082. var container =
  1083. new TileView (3) {
  1084. Width = 20,
  1085. Height = 10,
  1086. IntegratedBorder = withBorder ? BorderStyle.Single : BorderStyle.None
  1087. };
  1088. Assert.True (container.TrySplitTile (2, 2, out var newContainer));
  1089. newContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
  1090. int i = 0;
  1091. foreach (var tile in container.Tiles.Take (2).Union (newContainer.Tiles)) {
  1092. i++;
  1093. if (withTitles) {
  1094. tile.Title = "T" + i;
  1095. }
  1096. tile.View.Add (new TextView {
  1097. Width = Dim.Fill (),
  1098. Height = Dim.Fill (),
  1099. Text =
  1100. string.Join ('\n',
  1101. Enumerable.Repeat (
  1102. new string (i.ToString () [0], 100)
  1103. , 10).ToArray ()),
  1104. WordWrap = false
  1105. });
  1106. }
  1107. newContainer.ColorScheme = new ColorScheme ();
  1108. container.ColorScheme = new ColorScheme ();
  1109. container.LayoutSubviews ();
  1110. return container;
  1111. }
  1112. private LineView GetLine (TileView tileView)
  1113. {
  1114. return tileView.Subviews.OfType<LineView> ().Single ();
  1115. }
  1116. private void SetInputFocusLine (TileView tileView)
  1117. {
  1118. var line = GetLine (tileView);
  1119. line.SetFocus ();
  1120. Assert.True (line.HasFocus);
  1121. }
  1122. private TileView Get11By3TileView (out LineView line, bool withBorder = false)
  1123. {
  1124. var split = Get11By3TileView (withBorder);
  1125. line = GetLine (split);
  1126. return split;
  1127. }
  1128. private TileView Get11By3TileView (bool withBorder = false)
  1129. {
  1130. return GetTileView (11, 3, withBorder);
  1131. }
  1132. private TileView GetTileView (int width, int height, bool withBorder = false)
  1133. {
  1134. var container = new TileView () {
  1135. Width = width,
  1136. Height = height,
  1137. };
  1138. container.IntegratedBorder = withBorder ? BorderStyle.Single : BorderStyle.None;
  1139. container.Tiles.ElementAt (0).View.Add (new Label (new string ('1', 100)) { Width = Dim.Fill (), Height = 1, AutoSize = false });
  1140. container.Tiles.ElementAt (0).View.Add (new Label (new string ('1', 100)) { Width = Dim.Fill (), Height = 1, AutoSize = false, Y = 1 });
  1141. container.Tiles.ElementAt (1).View.Add (new Label (new string ('2', 100)) { Width = Dim.Fill (), Height = 1, AutoSize = false });
  1142. container.Tiles.ElementAt (1).View.Add (new Label (new string ('2', 100)) { Width = Dim.Fill (), Height = 1, AutoSize = false, Y = 1 });
  1143. container.Tiles.ElementAt (0).MinSize = 0;
  1144. container.Tiles.ElementAt (1).MinSize = 0;
  1145. Application.Top.Add (container);
  1146. container.ColorScheme = new ColorScheme ();
  1147. container.LayoutSubviews ();
  1148. container.BeginInit ();
  1149. container.EndInit ();
  1150. return container;
  1151. }
  1152. }
  1153. }