TileViewTests.cs 59 KB

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