TileViewTests.cs 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481
  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 = Get5x1TilesView();
  723. tv.Tiles.ElementAt(0).MinSize = int.MaxValue;
  724. tv.SetNeedsDisplay();
  725. tv.LayoutSubviews();
  726. Assert.True(tv.IsInitialized);
  727. tv.Redraw (tv.Bounds);
  728. var looksLike =
  729. @"
  730. ┌───────────────────────┐
  731. │11111111111111111111111│
  732. │ │
  733. └───────────────────────┘
  734. ";
  735. TestHelpers.AssertDriverContentsAre (looksLike, output);
  736. }
  737. [Fact, AutoInitShutdown]
  738. public void TestNestedNonRoots_OnlyOneRoot_OnlyRootCanHaveBorders ()
  739. {
  740. var tv = new TileView { Width = 10, Height = 5, ColorScheme = new ColorScheme (), IntegratedBorder = BorderStyle.Single };
  741. tv.TrySplitTile (1, 2, out var tv2);
  742. tv2.ColorScheme = new ColorScheme ();
  743. tv2.IntegratedBorder = BorderStyle.Single; // will not be respected
  744. tv2.Orientation = Orientation.Horizontal;
  745. Assert.True (tv.IsRootTileView ());
  746. Application.Top.Add (tv);
  747. tv.BeginInit ();
  748. tv.EndInit ();
  749. tv.LayoutSubviews ();
  750. tv.LayoutSubviews ();
  751. tv.Tiles.ElementAt (1).View.LayoutSubviews ();
  752. tv2.LayoutSubviews ();
  753. // tv2 is not considered a root because
  754. // it was created via TrySplitTile so it
  755. // will have its lines joined to
  756. // parent and cannot have its own border
  757. Assert.False (tv2.IsRootTileView ());
  758. tv.Redraw (tv.Bounds);
  759. var looksLike =
  760. @"
  761. ┌────┬───┐
  762. │ │ │
  763. │ ├───┤
  764. │ │ │
  765. └────┴───┘
  766. ";
  767. TestHelpers.AssertDriverContentsAre (looksLike, output);
  768. }
  769. [Fact, AutoInitShutdown]
  770. public void TestNestedContainer3RightAnd1Down_TileVisibility_WithBorder ()
  771. {
  772. var tileView = GetNestedContainer3Right1Down (true);
  773. tileView.Redraw (tileView.Bounds);
  774. string looksLike =
  775. @"
  776. ┌─────┬──────┬─────┐
  777. │11111│222222│33333│
  778. │11111│222222│33333│
  779. │11111│222222│33333│
  780. │11111│222222│33333│
  781. │11111│222222├─────┤
  782. │11111│222222│44444│
  783. │11111│222222│44444│
  784. │11111│222222│44444│
  785. └─────┴──────┴─────┘";
  786. TestHelpers.AssertDriverContentsAre (looksLike, output);
  787. tileView.Tiles.ElementAt (0).View.Visible = false;
  788. tileView.Tiles.ElementAt (1).View.Visible = true;
  789. tileView.Tiles.ElementAt (2).View.Visible = true;
  790. tileView.LayoutSubviews ();
  791. tileView.Redraw (tileView.Bounds);
  792. looksLike =
  793. @"
  794. ┌────────────┬─────┐
  795. │222222222222│33333│
  796. │222222222222│33333│
  797. │222222222222│33333│
  798. │222222222222│33333│
  799. │222222222222├─────┤
  800. │222222222222│44444│
  801. │222222222222│44444│
  802. │222222222222│44444│
  803. └────────────┴─────┘";
  804. TestHelpers.AssertDriverContentsAre (looksLike, output);
  805. tileView.Tiles.ElementAt (0).View.Visible = true;
  806. tileView.Tiles.ElementAt (1).View.Visible = false;
  807. tileView.Tiles.ElementAt (2).View.Visible = true;
  808. tileView.LayoutSubviews ();
  809. tileView.Redraw (tileView.Bounds);
  810. looksLike =
  811. @"
  812. ┌────────────┬─────┐
  813. │111111111111│33333│
  814. │111111111111│33333│
  815. │111111111111│33333│
  816. │111111111111│33333│
  817. │111111111111├─────┤
  818. │111111111111│44444│
  819. │111111111111│44444│
  820. │111111111111│44444│
  821. └────────────┴─────┘";
  822. TestHelpers.AssertDriverContentsAre (looksLike, output);
  823. tileView.Tiles.ElementAt (0).View.Visible = true;
  824. tileView.Tiles.ElementAt (1).View.Visible = true;
  825. tileView.Tiles.ElementAt (2).View.Visible = false;
  826. tileView.LayoutSubviews ();
  827. tileView.Redraw (tileView.Bounds);
  828. looksLike =
  829. @"
  830. ┌─────┬────────────┐
  831. │11111│222222222222│
  832. │11111│222222222222│
  833. │11111│222222222222│
  834. │11111│222222222222│
  835. │11111│222222222222│
  836. │11111│222222222222│
  837. │11111│222222222222│
  838. │11111│222222222222│
  839. └─────┴────────────┘";
  840. TestHelpers.AssertDriverContentsAre (looksLike, output);
  841. tileView.Tiles.ElementAt (0).View.Visible = true;
  842. tileView.Tiles.ElementAt (1).View.Visible = false;
  843. tileView.Tiles.ElementAt (2).View.Visible = false;
  844. tileView.LayoutSubviews ();
  845. tileView.Redraw (tileView.Bounds);
  846. looksLike =
  847. @"
  848. ┌──────────────────┐
  849. │111111111111111111│
  850. │111111111111111111│
  851. │111111111111111111│
  852. │111111111111111111│
  853. │111111111111111111│
  854. │111111111111111111│
  855. │111111111111111111│
  856. │111111111111111111│
  857. └──────────────────┘";
  858. TestHelpers.AssertDriverContentsAre (looksLike, output);
  859. tileView.Tiles.ElementAt (0).View.Visible = false;
  860. tileView.Tiles.ElementAt (1).View.Visible = true;
  861. tileView.Tiles.ElementAt (2).View.Visible = false;
  862. tileView.LayoutSubviews ();
  863. tileView.Redraw (tileView.Bounds);
  864. looksLike =
  865. @"
  866. ┌──────────────────┐
  867. │222222222222222222│
  868. │222222222222222222│
  869. │222222222222222222│
  870. │222222222222222222│
  871. │222222222222222222│
  872. │222222222222222222│
  873. │222222222222222222│
  874. │222222222222222222│
  875. └──────────────────┘";
  876. TestHelpers.AssertDriverContentsAre (looksLike, output);
  877. tileView.Tiles.ElementAt (0).View.Visible = false;
  878. tileView.Tiles.ElementAt (1).View.Visible = false;
  879. tileView.Tiles.ElementAt (2).View.Visible = true;
  880. tileView.LayoutSubviews ();
  881. tileView.Redraw (tileView.Bounds);
  882. looksLike =
  883. @"
  884. ┌──────────────────┐
  885. │333333333333333333│
  886. │333333333333333333│
  887. │333333333333333333│
  888. │333333333333333333│
  889. ├──────────────────┤
  890. │444444444444444444│
  891. │444444444444444444│
  892. │444444444444444444│
  893. └──────────────────┘";
  894. TestHelpers.AssertDriverContentsAre (looksLike, output);
  895. TestHelpers.AssertDriverContentsAre (looksLike, output);
  896. tileView.Tiles.ElementAt (0).View.Visible = false;
  897. tileView.Tiles.ElementAt (1).View.Visible = false;
  898. tileView.Tiles.ElementAt (2).View.Visible = false;
  899. tileView.LayoutSubviews ();
  900. tileView.Redraw (tileView.Bounds);
  901. looksLike =
  902. @"
  903. ┌──────────────────┐
  904. │ │
  905. │ │
  906. │ │
  907. │ │
  908. │ │
  909. │ │
  910. │ │
  911. │ │
  912. └──────────────────┘";
  913. TestHelpers.AssertDriverContentsAre (looksLike, output);
  914. }
  915. [Fact, AutoInitShutdown]
  916. public void TestNestedContainer3RightAnd1Down_TileVisibility_WithoutBorder ()
  917. {
  918. var tileView = GetNestedContainer3Right1Down (false);
  919. tileView.Redraw (tileView.Bounds);
  920. string looksLike =
  921. @"
  922. 111111│222222│333333
  923. 111111│222222│333333
  924. 111111│222222│333333
  925. 111111│222222│333333
  926. 111111│222222│333333
  927. 111111│222222├──────
  928. 111111│222222│444444
  929. 111111│222222│444444
  930. 111111│222222│444444
  931. 111111│222222│444444";
  932. TestHelpers.AssertDriverContentsAre (looksLike, output);
  933. tileView.Tiles.ElementAt (0).View.Visible = false;
  934. tileView.Tiles.ElementAt (1).View.Visible = true;
  935. tileView.Tiles.ElementAt (2).View.Visible = true;
  936. tileView.LayoutSubviews ();
  937. tileView.Redraw (tileView.Bounds);
  938. looksLike =
  939. @"
  940. 2222222222222│333333
  941. 2222222222222│333333
  942. 2222222222222│333333
  943. 2222222222222│333333
  944. 2222222222222│333333
  945. 2222222222222├──────
  946. 2222222222222│444444
  947. 2222222222222│444444
  948. 2222222222222│444444
  949. 2222222222222│444444";
  950. TestHelpers.AssertDriverContentsAre (looksLike, output);
  951. tileView.Tiles.ElementAt (0).View.Visible = true;
  952. tileView.Tiles.ElementAt (1).View.Visible = false;
  953. tileView.Tiles.ElementAt (2).View.Visible = true;
  954. tileView.LayoutSubviews ();
  955. tileView.Redraw (tileView.Bounds);
  956. looksLike =
  957. @"
  958. 1111111111111│333333
  959. 1111111111111│333333
  960. 1111111111111│333333
  961. 1111111111111│333333
  962. 1111111111111│333333
  963. 1111111111111├──────
  964. 1111111111111│444444
  965. 1111111111111│444444
  966. 1111111111111│444444
  967. 1111111111111│444444";
  968. TestHelpers.AssertDriverContentsAre (looksLike, output);
  969. tileView.Tiles.ElementAt (0).View.Visible = true;
  970. tileView.Tiles.ElementAt (1).View.Visible = true;
  971. tileView.Tiles.ElementAt (2).View.Visible = false;
  972. tileView.LayoutSubviews ();
  973. tileView.Redraw (tileView.Bounds);
  974. looksLike =
  975. @"
  976. 111111│2222222222222
  977. 111111│2222222222222
  978. 111111│2222222222222
  979. 111111│2222222222222
  980. 111111│2222222222222
  981. 111111│2222222222222
  982. 111111│2222222222222
  983. 111111│2222222222222
  984. 111111│2222222222222
  985. 111111│2222222222222";
  986. TestHelpers.AssertDriverContentsAre (looksLike, output);
  987. tileView.Tiles.ElementAt (0).View.Visible = true;
  988. tileView.Tiles.ElementAt (1).View.Visible = false;
  989. tileView.Tiles.ElementAt (2).View.Visible = false;
  990. tileView.LayoutSubviews ();
  991. tileView.Redraw (tileView.Bounds);
  992. looksLike =
  993. @"
  994. 11111111111111111111
  995. 11111111111111111111
  996. 11111111111111111111
  997. 11111111111111111111
  998. 11111111111111111111
  999. 11111111111111111111
  1000. 11111111111111111111
  1001. 11111111111111111111
  1002. 11111111111111111111
  1003. 11111111111111111111";
  1004. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1005. tileView.Tiles.ElementAt (0).View.Visible = false;
  1006. tileView.Tiles.ElementAt (1).View.Visible = true;
  1007. tileView.Tiles.ElementAt (2).View.Visible = false;
  1008. tileView.LayoutSubviews ();
  1009. tileView.Redraw (tileView.Bounds);
  1010. looksLike =
  1011. @"
  1012. 22222222222222222222
  1013. 22222222222222222222
  1014. 22222222222222222222
  1015. 22222222222222222222
  1016. 22222222222222222222
  1017. 22222222222222222222
  1018. 22222222222222222222
  1019. 22222222222222222222
  1020. 22222222222222222222
  1021. 22222222222222222222";
  1022. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1023. tileView.Tiles.ElementAt (0).View.Visible = false;
  1024. tileView.Tiles.ElementAt (1).View.Visible = false;
  1025. tileView.Tiles.ElementAt (2).View.Visible = true;
  1026. tileView.LayoutSubviews ();
  1027. tileView.Redraw (tileView.Bounds);
  1028. looksLike =
  1029. @"
  1030. 33333333333333333333
  1031. 33333333333333333333
  1032. 33333333333333333333
  1033. 33333333333333333333
  1034. 33333333333333333333
  1035. ────────────────────
  1036. 44444444444444444444
  1037. 44444444444444444444
  1038. 44444444444444444444
  1039. 44444444444444444444";
  1040. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1041. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1042. tileView.Tiles.ElementAt (0).View.Visible = false;
  1043. tileView.Tiles.ElementAt (1).View.Visible = false;
  1044. tileView.Tiles.ElementAt (2).View.Visible = false;
  1045. tileView.LayoutSubviews ();
  1046. tileView.Redraw (tileView.Bounds);
  1047. looksLike =
  1048. @"
  1049. ";
  1050. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1051. }
  1052. /// <summary>
  1053. /// Creates a vertical orientation root container with left pane split into
  1054. /// two (with horizontal splitter line).
  1055. /// </summary>
  1056. /// <param name="withBorder"></param>
  1057. /// <returns></returns>
  1058. private TileView GetNestedContainer2Left1Right (bool withBorder)
  1059. {
  1060. var container = GetTileView (20, 10, withBorder);
  1061. Assert.True (container.TrySplitTile (0, 2, out var newContainer));
  1062. newContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
  1063. newContainer.ColorScheme = new ColorScheme ();
  1064. container.ColorScheme = new ColorScheme ();
  1065. container.LayoutSubviews ();
  1066. return container;
  1067. }
  1068. /// <summary>
  1069. /// Creates a vertical orientation root container with 3 tiles.
  1070. /// The rightmost is split horizontally
  1071. /// </summary>
  1072. /// <param name="withBorder"></param>
  1073. /// <returns></returns>
  1074. private TileView GetNestedContainer3Right1Down (bool withBorder, bool withTitles = false)
  1075. {
  1076. var container =
  1077. new TileView (3) {
  1078. Width = 20,
  1079. Height = 10,
  1080. IntegratedBorder = withBorder ? BorderStyle.Single : BorderStyle.None
  1081. };
  1082. Assert.True (container.TrySplitTile (2, 2, out var newContainer));
  1083. newContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
  1084. int i = 0;
  1085. foreach (var tile in container.Tiles.Take (2).Union (newContainer.Tiles)) {
  1086. i++;
  1087. if (withTitles) {
  1088. tile.Title = "T" + i;
  1089. }
  1090. tile.View.Add (new TextView {
  1091. Width = Dim.Fill (),
  1092. Height = Dim.Fill (),
  1093. Text =
  1094. string.Join ('\n',
  1095. Enumerable.Repeat (
  1096. new string (i.ToString () [0], 100)
  1097. , 10).ToArray ()),
  1098. WordWrap = false
  1099. });
  1100. }
  1101. newContainer.ColorScheme = new ColorScheme ();
  1102. container.ColorScheme = new ColorScheme ();
  1103. container.LayoutSubviews ();
  1104. return container;
  1105. }
  1106. private LineView GetLine (TileView tileView)
  1107. {
  1108. return tileView.Subviews.OfType<LineView> ().Single ();
  1109. }
  1110. private void SetInputFocusLine (TileView tileView)
  1111. {
  1112. var line = GetLine (tileView);
  1113. line.SetFocus ();
  1114. Assert.True (line.HasFocus);
  1115. }
  1116. private TileView Get5x1TilesView ()
  1117. {
  1118. var tv = new TileView (5){ Width = 25, Height = 4, ColorScheme = new ColorScheme (), IntegratedBorder = BorderStyle.Single };
  1119. tv.Tiles.ElementAt (0).View.Add (new Label(new string('1',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
  1120. tv.Tiles.ElementAt (1).View.Add (new Label(new string('2',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
  1121. tv.Tiles.ElementAt (2).View.Add (new Label(new string('3',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
  1122. tv.Tiles.ElementAt (3).View.Add (new Label(new string('4',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
  1123. tv.Tiles.ElementAt (4).View.Add (new Label(new string('5',100)){AutoSize=false,Width=Dim.Fill(),Height = 1});
  1124. Application.Top.Add (tv);
  1125. tv.BeginInit ();
  1126. tv.EndInit ();
  1127. tv.LayoutSubviews ();
  1128. tv.Redraw (tv.Bounds);
  1129. var looksLike =
  1130. @"
  1131. ┌────┬────┬────┬────┬───┐
  1132. │1111│2222│3333│4444│555│
  1133. │ │ │ │ │ │
  1134. └────┴────┴────┴────┴───┘
  1135. ";
  1136. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1137. return tv;
  1138. }
  1139. private TileView Get11By3TileView (out LineView line, bool withBorder = false)
  1140. {
  1141. var split = Get11By3TileView (withBorder);
  1142. line = GetLine (split);
  1143. return split;
  1144. }
  1145. private TileView Get11By3TileView (bool withBorder = false)
  1146. {
  1147. return GetTileView (11, 3, withBorder);
  1148. }
  1149. private TileView GetTileView (int width, int height, bool withBorder = false)
  1150. {
  1151. var container = new TileView () {
  1152. Width = width,
  1153. Height = height,
  1154. };
  1155. container.IntegratedBorder = withBorder ? BorderStyle.Single : BorderStyle.None;
  1156. container.Tiles.ElementAt (0).View.Add (new Label (new string ('1', 100)) { Width = Dim.Fill (), Height = 1, AutoSize = false });
  1157. container.Tiles.ElementAt (0).View.Add (new Label (new string ('1', 100)) { Width = Dim.Fill (), Height = 1, AutoSize = false, Y = 1 });
  1158. container.Tiles.ElementAt (1).View.Add (new Label (new string ('2', 100)) { Width = Dim.Fill (), Height = 1, AutoSize = false });
  1159. container.Tiles.ElementAt (1).View.Add (new Label (new string ('2', 100)) { Width = Dim.Fill (), Height = 1, AutoSize = false, Y = 1 });
  1160. container.Tiles.ElementAt (0).MinSize = 0;
  1161. container.Tiles.ElementAt (1).MinSize = 0;
  1162. Application.Top.Add (container);
  1163. container.ColorScheme = new ColorScheme ();
  1164. container.LayoutSubviews ();
  1165. container.BeginInit ();
  1166. container.EndInit ();
  1167. return container;
  1168. }
  1169. }
  1170. }