TileViewTests.cs 64 KB

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