TileViewTests.cs 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326
  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 Terminal.Gui.ViewTests {
  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).ContentView.Frame.Width);
  444. Assert.Equal (9, tileView.Tiles.ElementAt (1).ContentView.Frame.Width);
  445. Assert.IsType<TileView> (tileView.Tiles.ElementAt (0).ContentView);
  446. var left = (TileView)tileView.Tiles.ElementAt (0).ContentView;
  447. Assert.Same (left.SuperView, tileView);
  448. Assert.Equal (2, left.Tiles.ElementAt (0).ContentView.Subviews.Count);
  449. Assert.IsType<Label> (left.Tiles.ElementAt (0).ContentView.Subviews [0]);
  450. Assert.IsType<Label> (left.Tiles.ElementAt (0).ContentView.Subviews [1]);
  451. var onesTop = (Label)left.Tiles.ElementAt (0).ContentView.Subviews [0];
  452. var onesBottom = (Label)left.Tiles.ElementAt (0).ContentView.Subviews [1];
  453. Assert.Same (left.Tiles.ElementAt (0).ContentView, onesTop.SuperView);
  454. Assert.Same (left.Tiles.ElementAt (0).ContentView, onesBottom.SuperView);
  455. Assert.Equal (10, onesTop.Frame.Width);
  456. Assert.Equal (10, onesBottom.Frame.Width);
  457. tileView.Redraw (tileView.Bounds);
  458. string looksLike =
  459. @"
  460. 1111111111│222222222
  461. 1111111111│222222222
  462. ──────────┤
  463. │";
  464. TestHelpers.AssertDriverContentsAre (looksLike, output);
  465. }
  466. [Fact, AutoInitShutdown]
  467. public void TestNestedContainer3RightAnd1Down_RendersNicely ()
  468. {
  469. var tileView = GetNestedContainer3Right1Down (false);
  470. tileView.Redraw (tileView.Bounds);
  471. string looksLike =
  472. @"
  473. 111111│222222│333333
  474. 111111│222222│333333
  475. 111111│222222│333333
  476. 111111│222222│333333
  477. 111111│222222│333333
  478. 111111│222222├──────
  479. 111111│222222│444444
  480. 111111│222222│444444
  481. 111111│222222│444444
  482. 111111│222222│444444
  483. ";
  484. TestHelpers.AssertDriverContentsAre (looksLike, output);
  485. // It looks good but lets double check the measurements incase
  486. // anything is sticking out but drawn over
  487. // 3 panels + 2 splitters
  488. Assert.Equal (5, tileView.Subviews.Count);
  489. // Check X and Widths of Tiles
  490. Assert.Equal (0, tileView.Tiles.ElementAt (0).ContentView.Frame.X);
  491. Assert.Equal (6, tileView.Tiles.ElementAt (0).ContentView.Frame.Width);
  492. Assert.Equal (7, tileView.Tiles.ElementAt (1).ContentView.Frame.X);
  493. Assert.Equal (6, tileView.Tiles.ElementAt (1).ContentView.Frame.Width);
  494. Assert.Equal (14, tileView.Tiles.ElementAt (2).ContentView.Frame.X);
  495. Assert.Equal (6, tileView.Tiles.ElementAt (2).ContentView.Frame.Width);
  496. // Check Y and Heights of Tiles
  497. Assert.Equal (0, tileView.Tiles.ElementAt (0).ContentView.Frame.Y);
  498. Assert.Equal (10, tileView.Tiles.ElementAt (0).ContentView.Frame.Height);
  499. Assert.Equal (0, tileView.Tiles.ElementAt (1).ContentView.Frame.Y);
  500. Assert.Equal (10, tileView.Tiles.ElementAt (1).ContentView.Frame.Height);
  501. Assert.Equal (0, tileView.Tiles.ElementAt (2).ContentView.Frame.Y);
  502. Assert.Equal (10, tileView.Tiles.ElementAt (2).ContentView.Frame.Height);
  503. // Check Sub containers in last panel
  504. var subSplit = (TileView)tileView.Tiles.ElementAt (2).ContentView;
  505. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.X);
  506. Assert.Equal (6, subSplit.Tiles.ElementAt (0).ContentView.Frame.Width);
  507. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.Y);
  508. Assert.Equal (5, subSplit.Tiles.ElementAt (0).ContentView.Frame.Height);
  509. Assert.IsType<TextView> (subSplit.Tiles.ElementAt (0).ContentView.Subviews.Single ());
  510. Assert.Equal (0, subSplit.Tiles.ElementAt (1).ContentView.Frame.X);
  511. Assert.Equal (6, subSplit.Tiles.ElementAt (1).ContentView.Frame.Width);
  512. Assert.Equal (6, subSplit.Tiles.ElementAt (1).ContentView.Frame.Y);
  513. Assert.Equal (4, subSplit.Tiles.ElementAt (1).ContentView.Frame.Height);
  514. Assert.IsType<TextView> (subSplit.Tiles.ElementAt (1).ContentView.Subviews.Single ());
  515. }
  516. [Fact, AutoInitShutdown]
  517. public void TestNestedContainer3RightAnd1Down_WithBorder_RendersNicely ()
  518. {
  519. var tileView = GetNestedContainer3Right1Down (true);
  520. tileView.Redraw (tileView.Bounds);
  521. string looksLike =
  522. @"
  523. ┌─────┬──────┬─────┐
  524. │11111│222222│33333│
  525. │11111│222222│33333│
  526. │11111│222222│33333│
  527. │11111│222222│33333│
  528. │11111│222222├─────┤
  529. │11111│222222│44444│
  530. │11111│222222│44444│
  531. │11111│222222│44444│
  532. └─────┴──────┴─────┘";
  533. TestHelpers.AssertDriverContentsAre (looksLike, output);
  534. // It looks good but lets double check the measurements incase
  535. // anything is sticking out but drawn over
  536. // 3 panels + 2 splitters
  537. Assert.Equal (5, tileView.Subviews.Count);
  538. // Check X and Widths of Tiles
  539. Assert.Equal (1, tileView.Tiles.ElementAt (0).ContentView.Frame.X);
  540. Assert.Equal (5, tileView.Tiles.ElementAt (0).ContentView.Frame.Width);
  541. Assert.Equal (7, tileView.Tiles.ElementAt (1).ContentView.Frame.X);
  542. Assert.Equal (6, tileView.Tiles.ElementAt (1).ContentView.Frame.Width);
  543. Assert.Equal (14, tileView.Tiles.ElementAt (2).ContentView.Frame.X);
  544. Assert.Equal (5, tileView.Tiles.ElementAt (2).ContentView.Frame.Width);
  545. // Check Y and Heights of Tiles
  546. Assert.Equal (1, tileView.Tiles.ElementAt (0).ContentView.Frame.Y);
  547. Assert.Equal (8, tileView.Tiles.ElementAt (0).ContentView.Frame.Height);
  548. Assert.Equal (1, tileView.Tiles.ElementAt (1).ContentView.Frame.Y);
  549. Assert.Equal (8, tileView.Tiles.ElementAt (1).ContentView.Frame.Height);
  550. Assert.Equal (1, tileView.Tiles.ElementAt (2).ContentView.Frame.Y);
  551. Assert.Equal (8, tileView.Tiles.ElementAt (2).ContentView.Frame.Height);
  552. // Check Sub containers in last panel
  553. var subSplit = (TileView)tileView.Tiles.ElementAt (2).ContentView;
  554. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.X);
  555. Assert.Equal (5, subSplit.Tiles.ElementAt (0).ContentView.Frame.Width);
  556. Assert.Equal (0, subSplit.Tiles.ElementAt (0).ContentView.Frame.Y);
  557. Assert.Equal (4, subSplit.Tiles.ElementAt (0).ContentView.Frame.Height);
  558. Assert.IsType<TextView> (subSplit.Tiles.ElementAt (0).ContentView.Subviews.Single ());
  559. Assert.Equal (0, subSplit.Tiles.ElementAt (1).ContentView.Frame.X);
  560. Assert.Equal (5, subSplit.Tiles.ElementAt (1).ContentView.Frame.Width);
  561. Assert.Equal (5, subSplit.Tiles.ElementAt (1).ContentView.Frame.Y);
  562. Assert.Equal (3, subSplit.Tiles.ElementAt (1).ContentView.Frame.Height);
  563. Assert.IsType<TextView> (subSplit.Tiles.ElementAt (1).ContentView.Subviews.Single ());
  564. }
  565. [Fact, AutoInitShutdown]
  566. public void TestNestedContainer3RightAnd1Down_WithTitledBorder_RendersNicely ()
  567. {
  568. var tileView = GetNestedContainer3Right1Down (true, true);
  569. tileView.Redraw (tileView.Bounds);
  570. string looksLike =
  571. @"
  572. ┌ T1 ─┬ T2 ──┬ T3 ─┐
  573. │11111│222222│33333│
  574. │11111│222222│33333│
  575. │11111│222222│33333│
  576. │11111│222222│33333│
  577. │11111│222222├ T4 ─┤
  578. │11111│222222│44444│
  579. │11111│222222│44444│
  580. │11111│222222│44444│
  581. └─────┴──────┴─────┘";
  582. TestHelpers.AssertDriverContentsAre (looksLike, output);
  583. }
  584. [Fact, AutoInitShutdown]
  585. public void TestNestedContainer3RightAnd1Down_WithBorder_RemovingTiles ()
  586. {
  587. var tileView = GetNestedContainer3Right1Down (true);
  588. tileView.Redraw (tileView.Bounds);
  589. string looksLike =
  590. @"
  591. ┌─────┬──────┬─────┐
  592. │11111│222222│33333│
  593. │11111│222222│33333│
  594. │11111│222222│33333│
  595. │11111│222222│33333│
  596. │11111│222222├─────┤
  597. │11111│222222│44444│
  598. │11111│222222│44444│
  599. │11111│222222│44444│
  600. └─────┴──────┴─────┘";
  601. TestHelpers.AssertDriverContentsAre (looksLike, output);
  602. var toRemove = tileView.Tiles.ElementAt (1);
  603. var removed = tileView.RemoveTile (1);
  604. Assert.Same (toRemove, removed);
  605. Assert.DoesNotContain (removed, tileView.Tiles);
  606. tileView.Redraw (tileView.Bounds);
  607. looksLike =
  608. @"
  609. ┌─────────┬────────┐
  610. │111111111│33333333│
  611. │111111111│33333333│
  612. │111111111│33333333│
  613. │111111111│33333333│
  614. │111111111├────────┤
  615. │111111111│44444444│
  616. │111111111│44444444│
  617. │111111111│44444444│
  618. └─────────┴────────┘";
  619. TestHelpers.AssertDriverContentsAre (looksLike, output);
  620. // cannot remove at this index because there is only one horizontal tile left
  621. Assert.Null (tileView.RemoveTile (2));
  622. tileView.RemoveTile (0);
  623. tileView.Redraw (tileView.Bounds);
  624. looksLike =
  625. @"
  626. ┌──────────────────┐
  627. │333333333333333333│
  628. │333333333333333333│
  629. │333333333333333333│
  630. │333333333333333333│
  631. ├──────────────────┤
  632. │444444444444444444│
  633. │444444444444444444│
  634. │444444444444444444│
  635. └──────────────────┘";
  636. TestHelpers.AssertDriverContentsAre (looksLike, output);
  637. Assert.NotNull (tileView.RemoveTile (0));
  638. tileView.Redraw (tileView.Bounds);
  639. looksLike =
  640. @"
  641. ┌──────────────────┐
  642. │ │
  643. │ │
  644. │ │
  645. │ │
  646. │ │
  647. │ │
  648. │ │
  649. │ │
  650. └──────────────────┘";
  651. TestHelpers.AssertDriverContentsAre (looksLike, output);
  652. // cannot remove
  653. Assert.Null (tileView.RemoveTile (0));
  654. }
  655. [Theory, AutoInitShutdown]
  656. [InlineData (true)]
  657. [InlineData (false)]
  658. public void TestTileView_IndexOf (bool recursive)
  659. {
  660. var tv = new TileView ();
  661. var lbl1 = new Label ();
  662. var lbl2 = new Label ();
  663. var frame = new FrameView ();
  664. var sub = new Label ();
  665. frame.Add (sub);
  666. // IndexOf returns -1 when view not found
  667. Assert.Equal (-1, tv.IndexOf (lbl1, recursive));
  668. Assert.Equal (-1, tv.IndexOf (lbl2, recursive));
  669. // IndexOf supports looking for Tile.View
  670. Assert.Equal (0, tv.IndexOf (tv.Tiles.ElementAt (0).ContentView, recursive));
  671. Assert.Equal (1, tv.IndexOf (tv.Tiles.ElementAt (1).ContentView, recursive));
  672. // IndexOf supports looking for Tile.View.Subviews
  673. tv.Tiles.ElementAt (0).ContentView.Add (lbl1);
  674. Assert.Equal (0, tv.IndexOf (lbl1, recursive));
  675. tv.Tiles.ElementAt (1).ContentView.Add (lbl2);
  676. Assert.Equal (1, tv.IndexOf (lbl2, recursive));
  677. // IndexOf supports looking deep into subviews only when
  678. // the recursive true value is passed
  679. tv.Tiles.ElementAt (1).ContentView.Add (frame);
  680. if (recursive) {
  681. Assert.Equal (1, tv.IndexOf (sub, recursive));
  682. } else {
  683. Assert.Equal (-1, tv.IndexOf (sub, recursive));
  684. }
  685. }
  686. [Fact, AutoInitShutdown]
  687. public void TestNestedRoots_BothRoots_BothCanHaveBorders ()
  688. {
  689. var tv = new TileView {
  690. Width = 10,
  691. Height = 5,
  692. ColorScheme = new ColorScheme (),
  693. Border = new Border () { BorderStyle = BorderStyle.Single }
  694. };
  695. var tv2 = new TileView {
  696. Width = Dim.Fill (),
  697. Height = Dim.Fill (),
  698. ColorScheme = new ColorScheme (),
  699. Border = new Border () { BorderStyle = BorderStyle.Single },
  700. Orientation = Orientation.Horizontal
  701. };
  702. Assert.True (tv.IsRootTileView ());
  703. tv.Tiles.ElementAt (1).ContentView.Add (tv2);
  704. Application.Top.Add (tv);
  705. tv.BeginInit ();
  706. tv.EndInit ();
  707. tv.LayoutSubviews ();
  708. tv.LayoutSubviews ();
  709. tv.Tiles.ElementAt (1).ContentView.LayoutSubviews ();
  710. tv2.LayoutSubviews ();
  711. // tv2 is still considered a root because
  712. // it was manually created by API user. That
  713. // means it will not have its lines joined to
  714. // parents and it is permitted to have a border
  715. Assert.True (tv2.IsRootTileView ());
  716. tv.Redraw (tv.Bounds);
  717. var looksLike =
  718. @"
  719. ┌────┬───┐
  720. │ │┌─┐│
  721. │ │├─┤│
  722. │ │└─┘│
  723. └────┴───┘
  724. ";
  725. TestHelpers.AssertDriverContentsAre (looksLike, output);
  726. }
  727. [Fact, AutoInitShutdown]
  728. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter1 ()
  729. {
  730. var tv = Get5x1TilesView ();
  731. tv.Tiles.ElementAt (0).MinSize = int.MaxValue;
  732. tv.Redraw (tv.Bounds);
  733. var looksLike =
  734. @"
  735. ┌────┬────┬────┬────┬───┐
  736. │1111│2222│3333│4444│555│
  737. │ │ │ │ │ │
  738. └────┴────┴────┴────┴───┘
  739. ";
  740. TestHelpers.AssertDriverContentsAre (looksLike, output);
  741. for (int x = 0; x <= 5; x++) {
  742. // All these values would result in tile 0 getting smaller
  743. // so are not allowed (tile[0] has a min size of Int.Max)
  744. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  745. }
  746. for (int x = 6; x < 10; x++) {
  747. // All these values would result in tile 0 getting bigger
  748. // so are allowed
  749. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  750. }
  751. for (int x = 10; x < 100; x++) {
  752. // These values would result in the first splitter moving past
  753. // the second splitter so are not allowed
  754. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  755. }
  756. tv.SetNeedsDisplay();
  757. tv.Redraw (tv.Bounds);
  758. looksLike =
  759. @"
  760. ┌────────┬┬────┬────┬───┐
  761. │11111111││3333│4444│555│
  762. │ ││ │ │ │
  763. └────────┴┴────┴────┴───┘
  764. ";
  765. TestHelpers.AssertDriverContentsAre (looksLike, output);
  766. }
  767. [Fact, AutoInitShutdown]
  768. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter1_NoBorder ()
  769. {
  770. var tv = Get5x1TilesView (false);
  771. tv.Tiles.ElementAt (0).MinSize = int.MaxValue;
  772. tv.Redraw (tv.Bounds);
  773. var looksLike =
  774. @"
  775. 11111│2222│3333│4444│5555
  776. │ │ │ │
  777. │ │ │ │
  778. │ │ │ │
  779. ";
  780. TestHelpers.AssertDriverContentsAre (looksLike, output);
  781. for (int x = 0; x <= 5; x++) {
  782. // All these values would result in tile 0 getting smaller
  783. // so are not allowed (tile[0] has a min size of Int.Max)
  784. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  785. }
  786. for (int x = 6; x < 10; x++) {
  787. // All these values would result in tile 0 getting bigger
  788. // so are allowed
  789. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  790. }
  791. for (int x = 10; x < 100; x++) {
  792. // These values would result in the first splitter moving past
  793. // the second splitter so are not allowed
  794. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  795. }
  796. tv.SetNeedsDisplay();
  797. tv.Redraw (tv.Bounds);
  798. looksLike =
  799. @"
  800. 111111111││3333│4444│5555
  801. ││ │ │
  802. ││ │ │
  803. ││ │ │
  804. ";
  805. TestHelpers.AssertDriverContentsAre (looksLike, output);
  806. }
  807. [Fact, AutoInitShutdown]
  808. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossBorder ()
  809. {
  810. var tv = Get5x1TilesView ();
  811. tv.Redraw (tv.Bounds);
  812. var looksLike =
  813. @"
  814. ┌────┬────┬────┬────┬───┐
  815. │1111│2222│3333│4444│555│
  816. │ │ │ │ │ │
  817. └────┴────┴────┴────┴───┘
  818. ";
  819. TestHelpers.AssertDriverContentsAre (looksLike, output);
  820. for (int x = 5; x > 0; x--) {
  821. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  822. }
  823. Assert.False (tv.SetSplitterPos (0, 0));
  824. tv.SetNeedsDisplay();
  825. tv.Redraw (tv.Bounds);
  826. looksLike =
  827. @"
  828. ┌┬────────┬────┬────┬───┐
  829. ││22222222│3333│4444│555│
  830. ││ │ │ │ │
  831. └┴────────┴────┴────┴───┘
  832. ";
  833. TestHelpers.AssertDriverContentsAre (looksLike, output);
  834. for (int x = 6; x < 10; x++) {
  835. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  836. }
  837. for (int x = 10; x < 100; x++) {
  838. // These values would result in the first splitter moving past
  839. // the second splitter so are not allowed
  840. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  841. }
  842. tv.SetNeedsDisplay();
  843. tv.Redraw (tv.Bounds);
  844. looksLike =
  845. @"
  846. ┌────────┬┬────┬────┬───┐
  847. │11111111││3333│4444│555│
  848. │ ││ │ │ │
  849. └────────┴┴────┴────┴───┘
  850. ";
  851. TestHelpers.AssertDriverContentsAre (looksLike, output);
  852. }
  853. [Fact, AutoInitShutdown]
  854. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter1_CannotCrossBorder_NoBorder ()
  855. {
  856. var tv = Get5x1TilesView (false);
  857. tv.Redraw (tv.Bounds);
  858. var looksLike =
  859. @"
  860. 11111│2222│3333│4444│5555
  861. │ │ │ │
  862. │ │ │ │
  863. │ │ │ │
  864. ";
  865. TestHelpers.AssertDriverContentsAre (looksLike, output);
  866. for (int x = 5; x >= 0; x--) {
  867. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  868. }
  869. tv.SetNeedsDisplay();
  870. tv.Redraw (tv.Bounds);
  871. looksLike =
  872. @"
  873. │222222222│3333│4444│5555
  874. │ │ │ │
  875. │ │ │ │
  876. │ │ │ │
  877. ";
  878. TestHelpers.AssertDriverContentsAre (looksLike, output);
  879. for (int x = 6; x < 10; x++) {
  880. Assert.True (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  881. }
  882. for (int x = 10; x < 100; x++) {
  883. // These values would result in the first splitter moving past
  884. // the second splitter so are not allowed
  885. Assert.False (tv.SetSplitterPos (0, x), $"Assert failed for x={x}");
  886. }
  887. tv.SetNeedsDisplay();
  888. tv.Redraw (tv.Bounds);
  889. looksLike =
  890. @"
  891. 111111111││3333│4444│5555
  892. ││ │ │
  893. ││ │ │
  894. ││ │ │
  895. ";
  896. TestHelpers.AssertDriverContentsAre (looksLike, output);
  897. }
  898. [Fact, AutoInitShutdown]
  899. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOverNeighbours ()
  900. {
  901. var tv = Get5x1TilesView ();
  902. tv.Redraw (tv.Bounds);
  903. var looksLike =
  904. @"
  905. ┌────┬────┬────┬────┬───┐
  906. │1111│2222│3333│4444│555│
  907. │ │ │ │ │ │
  908. └────┴────┴────┴────┴───┘
  909. ";
  910. TestHelpers.AssertDriverContentsAre (looksLike, output);
  911. for (int x = 10; x > 5; x--) {
  912. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  913. }
  914. for (int x = 5; x > 0; x--) {
  915. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  916. }
  917. tv.SetNeedsDisplay();
  918. tv.Redraw (tv.Bounds);
  919. looksLike =
  920. @"
  921. ┌────┬┬────────┬────┬───┐
  922. │1111││33333333│4444│555│
  923. │ ││ │ │ │
  924. └────┴┴────────┴────┴───┘
  925. ";
  926. TestHelpers.AssertDriverContentsAre (looksLike, output);
  927. for (int x = 10; x < 15; x++) {
  928. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  929. }
  930. for (int x = 15; x < 25; x++) {
  931. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  932. }
  933. tv.SetNeedsDisplay();
  934. tv.Redraw (tv.Bounds);
  935. looksLike =
  936. @"
  937. ┌────┬────────┬┬────┬───┐
  938. │1111│22222222││4444│555│
  939. │ │ ││ │ │
  940. └────┴────────┴┴────┴───┘
  941. ";
  942. TestHelpers.AssertDriverContentsAre (looksLike, output);
  943. }
  944. [Fact, AutoInitShutdown]
  945. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter2_CannotMoveOverNeighbours_NoBorder ()
  946. {
  947. var tv = Get5x1TilesView (false);
  948. tv.Redraw (tv.Bounds);
  949. var looksLike =
  950. @"
  951. 11111│2222│3333│4444│5555
  952. │ │ │ │
  953. │ │ │ │
  954. │ │ │ │
  955. ";
  956. TestHelpers.AssertDriverContentsAre (looksLike, output);
  957. for (int x = 10; x > 5; x--) {
  958. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  959. }
  960. for (int x = 5; x > 0; x--) {
  961. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  962. }
  963. tv.SetNeedsDisplay();
  964. tv.Redraw (tv.Bounds);
  965. looksLike =
  966. @"
  967. 11111││33333333│4444│5555
  968. ││ │ │
  969. ││ │ │
  970. ││ │ │
  971. ";
  972. TestHelpers.AssertDriverContentsAre (looksLike, output);
  973. for (int x = 10; x < 15; x++) {
  974. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  975. }
  976. for (int x = 15; x < 25; x++) {
  977. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  978. }
  979. tv.SetNeedsDisplay();
  980. tv.Redraw (tv.Bounds);
  981. looksLike =
  982. @"
  983. 11111│22222222││4444│5555
  984. │ ││ │
  985. │ ││ │
  986. │ ││ │
  987. ";
  988. TestHelpers.AssertDriverContentsAre (looksLike, output);
  989. }
  990. [Fact, AutoInitShutdown]
  991. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2 ()
  992. {
  993. var tv = Get5x1TilesView ();
  994. tv.Tiles.ElementAt (1).MinSize = 2;
  995. tv.Tiles.ElementAt (2).MinSize = 3;
  996. tv.Redraw (tv.Bounds);
  997. var looksLike =
  998. @"
  999. ┌────┬────┬────┬────┬───┐
  1000. │1111│2222│3333│4444│555│
  1001. │ │ │ │ │ │
  1002. └────┴────┴────┴────┴───┘
  1003. ";
  1004. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1005. for (int x = 10; x > 7; x--) {
  1006. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  1007. }
  1008. for (int x = 7; x > 0; x--) {
  1009. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  1010. }
  1011. tv.SetNeedsDisplay();
  1012. tv.Redraw (tv.Bounds);
  1013. looksLike =
  1014. @"
  1015. ┌────┬──┬──────┬────┬───┐
  1016. │1111│22│333333│4444│555│
  1017. │ │ │ │ │ │
  1018. └────┴──┴──────┴────┴───┘
  1019. ";
  1020. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1021. for (int x = 10; x < 12; x++) {
  1022. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  1023. }
  1024. for (int x = 12; x < 25; x++) {
  1025. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  1026. }
  1027. tv.SetNeedsDisplay();
  1028. tv.Redraw (tv.Bounds);
  1029. looksLike =
  1030. @"
  1031. ┌────┬─────┬───┬────┬───┐
  1032. │1111│22222│333│4444│555│
  1033. │ │ │ │ │ │
  1034. └────┴─────┴───┴────┴───┘
  1035. ";
  1036. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1037. }
  1038. [Fact, AutoInitShutdown]
  1039. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter2_NoBorder ()
  1040. {
  1041. var tv = Get5x1TilesView (false);
  1042. tv.Tiles.ElementAt (1).MinSize = 2;
  1043. tv.Tiles.ElementAt (2).MinSize = 3;
  1044. tv.Redraw (tv.Bounds);
  1045. var looksLike =
  1046. @"
  1047. 11111│2222│3333│4444│5555
  1048. │ │ │ │
  1049. │ │ │ │
  1050. │ │ │ │
  1051. ";
  1052. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1053. for (int x = 10; x > 7; x--) {
  1054. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  1055. }
  1056. for (int x = 7; x > 0; x--) {
  1057. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  1058. }
  1059. tv.SetNeedsDisplay();
  1060. tv.Redraw (tv.Bounds);
  1061. looksLike =
  1062. @"
  1063. 11111│22│333333│4444│5555
  1064. │ │ │ │
  1065. │ │ │ │
  1066. │ │ │ │
  1067. ";
  1068. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1069. for (int x = 10; x < 12; x++) {
  1070. Assert.True (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  1071. }
  1072. for (int x = 12; x < 25; x++) {
  1073. Assert.False (tv.SetSplitterPos (1, x), $"Assert failed for x={x}");
  1074. }
  1075. tv.SetNeedsDisplay();
  1076. tv.Redraw (tv.Bounds);
  1077. looksLike =
  1078. @"
  1079. 11111│22222│333│4444│5555
  1080. │ │ │ │
  1081. │ │ │ │
  1082. │ │ │ │
  1083. ";
  1084. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1085. }
  1086. [Fact, AutoInitShutdown]
  1087. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOverNeighbours ()
  1088. {
  1089. var tv = Get5x1TilesView ();
  1090. tv.Redraw (tv.Bounds);
  1091. var looksLike =
  1092. @"
  1093. ┌────┬────┬────┬────┬───┐
  1094. │1111│2222│3333│4444│555│
  1095. │ │ │ │ │ │
  1096. └────┴────┴────┴────┴───┘
  1097. ";
  1098. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1099. for (int x = 20; x > 15; x--) {
  1100. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1101. }
  1102. for (int x = 15; x > 0; x--) {
  1103. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1104. }
  1105. tv.SetNeedsDisplay();
  1106. tv.Redraw (tv.Bounds);
  1107. looksLike =
  1108. @"
  1109. ┌────┬────┬────┬┬───────┐
  1110. │1111│2222│3333││5555555│
  1111. │ │ │ ││ │
  1112. └────┴────┴────┴┴───────┘
  1113. ";
  1114. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1115. for (int x = 20; x < 24; x++) {
  1116. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1117. }
  1118. for (int x = 24; x < 100; x++) {
  1119. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1120. }
  1121. tv.SetNeedsDisplay();
  1122. tv.Redraw (tv.Bounds);
  1123. looksLike =
  1124. @"
  1125. ┌────┬────┬────┬───────┬┐
  1126. │1111│2222│3333│4444444││
  1127. │ │ │ │ ││
  1128. └────┴────┴────┴───────┴┘
  1129. ";
  1130. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1131. }
  1132. [Fact, AutoInitShutdown]
  1133. public void Test5Panel_NoMinSizes_VerticalSplitters_ResizeSplitter4_CannotMoveOverNeighbours_NoBorder ()
  1134. {
  1135. var tv = Get5x1TilesView (false);
  1136. tv.Redraw (tv.Bounds);
  1137. var looksLike =
  1138. @"
  1139. 11111│2222│3333│4444│5555
  1140. │ │ │ │
  1141. │ │ │ │
  1142. │ │ │ │
  1143. ";
  1144. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1145. for (int x = 20; x > 15; x--) {
  1146. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1147. }
  1148. for (int x = 15; x > 0; x--) {
  1149. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1150. }
  1151. tv.SetNeedsDisplay();
  1152. tv.Redraw (tv.Bounds);
  1153. looksLike =
  1154. @"
  1155. 11111│2222│3333││55555555
  1156. │ │ ││
  1157. │ │ ││
  1158. │ │ ││
  1159. ";
  1160. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1161. for (int x = 20; x < 25; x++) {
  1162. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1163. }
  1164. for (int x = 25; x < 100; x++) {
  1165. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1166. }
  1167. tv.SetNeedsDisplay();
  1168. tv.Redraw (tv.Bounds);
  1169. looksLike =
  1170. @"
  1171. 11111│2222│3333│44444444│
  1172. │ │ │ │
  1173. │ │ │ │
  1174. │ │ │ │
  1175. ";
  1176. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1177. }
  1178. [Fact, AutoInitShutdown]
  1179. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4 ()
  1180. {
  1181. var tv = Get5x1TilesView ();
  1182. tv.Tiles.ElementAt (3).MinSize = 2;
  1183. tv.Tiles.ElementAt (4).MinSize = 1;
  1184. tv.Redraw (tv.Bounds);
  1185. var looksLike =
  1186. @"
  1187. ┌────┬────┬────┬────┬───┐
  1188. │1111│2222│3333│4444│555│
  1189. │ │ │ │ │ │
  1190. └────┴────┴────┴────┴───┘
  1191. ";
  1192. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1193. for (int x = 20; x > 17; x--) {
  1194. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1195. }
  1196. for (int x = 17; x > 0; x--) {
  1197. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1198. }
  1199. tv.SetNeedsDisplay();
  1200. tv.Redraw (tv.Bounds);
  1201. looksLike =
  1202. @"
  1203. ┌────┬────┬────┬──┬─────┐
  1204. │1111│2222│3333│44│55555│
  1205. │ │ │ │ │ │
  1206. └────┴────┴────┴──┴─────┘
  1207. ";
  1208. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1209. for (int x = 20; x < 23; x++) {
  1210. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1211. }
  1212. for (int x = 23; x < 100; x++) {
  1213. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1214. }
  1215. tv.SetNeedsDisplay();
  1216. tv.Redraw (tv.Bounds);
  1217. looksLike =
  1218. @"
  1219. ┌────┬────┬────┬──────┬─┐
  1220. │1111│2222│3333│444444│5│
  1221. │ │ │ │ │ │
  1222. └────┴────┴────┴──────┴─┘
  1223. ";
  1224. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1225. }
  1226. [Fact, AutoInitShutdown]
  1227. public void Test5Panel_MinSizes_VerticalSplitters_ResizeSplitter4_NoBorder ()
  1228. {
  1229. var tv = Get5x1TilesView (false);
  1230. tv.Tiles.ElementAt (3).MinSize = 2;
  1231. tv.Tiles.ElementAt (4).MinSize = 1;
  1232. tv.Redraw (tv.Bounds);
  1233. var looksLike =
  1234. @"
  1235. 11111│2222│3333│4444│5555
  1236. │ │ │ │
  1237. │ │ │ │
  1238. │ │ │ │
  1239. ";
  1240. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1241. for (int x = 20; x > 17; x--) {
  1242. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1243. }
  1244. for (int x = 17; x > 0; x--) {
  1245. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1246. }
  1247. tv.SetNeedsDisplay();
  1248. tv.Redraw (tv.Bounds);
  1249. looksLike =
  1250. @"
  1251. 11111│2222│3333│44│555555
  1252. │ │ │ │
  1253. │ │ │ │
  1254. │ │ │ │
  1255. ";
  1256. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1257. for (int x = 20; x < 24; x++) {
  1258. Assert.True (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1259. }
  1260. for (int x = 24; x < 100; x++) {
  1261. Assert.False (tv.SetSplitterPos (3, x), $"Assert failed for x={x}");
  1262. }
  1263. tv.SetNeedsDisplay();
  1264. tv.Redraw (tv.Bounds);
  1265. looksLike =
  1266. @"
  1267. 11111│2222│3333│4444444│5
  1268. │ │ │ │
  1269. │ │ │ │
  1270. │ │ │ │
  1271. ";
  1272. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1273. }
  1274. [Fact, AutoInitShutdown]
  1275. public void TestNestedNonRoots_OnlyOneRoot_OnlyRootCanHaveBorders ()
  1276. {
  1277. var tv = new TileView { Width = 10, Height = 5, ColorScheme = new ColorScheme (),
  1278. Border = new Border () { BorderStyle = BorderStyle.Single }
  1279. };
  1280. tv.TrySplitTile (1, 2, out var tv2);
  1281. tv2.ColorScheme = new ColorScheme ();
  1282. tv2.Border.BorderStyle = BorderStyle.Single;
  1283. tv2.Orientation = Orientation.Horizontal;
  1284. Assert.True (tv.IsRootTileView ());
  1285. Application.Top.Add (tv);
  1286. tv.BeginInit ();
  1287. tv.EndInit ();
  1288. tv.LayoutSubviews ();
  1289. tv.LayoutSubviews ();
  1290. tv.Tiles.ElementAt (1).ContentView.LayoutSubviews ();
  1291. tv2.LayoutSubviews ();
  1292. // tv2 is not considered a root because
  1293. // it was created via TrySplitTile so it
  1294. // will have its lines joined to
  1295. // parent and cannot have its own border
  1296. Assert.False (tv2.IsRootTileView ());
  1297. tv.Redraw (tv.Bounds);
  1298. var looksLike =
  1299. @"
  1300. ┌────┬───┐
  1301. │ │ │
  1302. │ ├───┤
  1303. │ │ │
  1304. └────┴───┘
  1305. ";
  1306. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1307. }
  1308. [Fact, AutoInitShutdown]
  1309. public void TestTrySplit_ShouldRetainTitle ()
  1310. {
  1311. var tv = new TileView ();
  1312. tv.Tiles.ElementAt (0).Title = "flibble";
  1313. tv.TrySplitTile (0, 2, out var subTileView);
  1314. // We moved the content so the title should also have been moved
  1315. Assert.Equal ("flibble", subTileView.Tiles.ElementAt (0).Title);
  1316. // Secondly we should have cleared the old title (it should have been moved not copied)
  1317. Assert.Empty (tv.Tiles.ElementAt (0).Title);
  1318. }
  1319. [Fact, AutoInitShutdown]
  1320. public void TestNestedContainer3RightAnd1Down_TileVisibility_WithBorder ()
  1321. {
  1322. var tileView = GetNestedContainer3Right1Down (true);
  1323. tileView.Redraw (tileView.Bounds);
  1324. string looksLike =
  1325. @"
  1326. ┌─────┬──────┬─────┐
  1327. │11111│222222│33333│
  1328. │11111│222222│33333│
  1329. │11111│222222│33333│
  1330. │11111│222222│33333│
  1331. │11111│222222├─────┤
  1332. │11111│222222│44444│
  1333. │11111│222222│44444│
  1334. │11111│222222│44444│
  1335. └─────┴──────┴─────┘";
  1336. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1337. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1338. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  1339. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  1340. tileView.LayoutSubviews ();
  1341. tileView.Redraw (tileView.Bounds);
  1342. looksLike =
  1343. @"
  1344. ┌────────────┬─────┐
  1345. │222222222222│33333│
  1346. │222222222222│33333│
  1347. │222222222222│33333│
  1348. │222222222222│33333│
  1349. │222222222222├─────┤
  1350. │222222222222│44444│
  1351. │222222222222│44444│
  1352. │222222222222│44444│
  1353. └────────────┴─────┘";
  1354. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1355. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  1356. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  1357. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  1358. tileView.LayoutSubviews ();
  1359. tileView.Redraw (tileView.Bounds);
  1360. looksLike =
  1361. @"
  1362. ┌────────────┬─────┐
  1363. │111111111111│33333│
  1364. │111111111111│33333│
  1365. │111111111111│33333│
  1366. │111111111111│33333│
  1367. │111111111111├─────┤
  1368. │111111111111│44444│
  1369. │111111111111│44444│
  1370. │111111111111│44444│
  1371. └────────────┴─────┘";
  1372. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1373. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  1374. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  1375. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  1376. tileView.LayoutSubviews ();
  1377. tileView.Redraw (tileView.Bounds);
  1378. looksLike =
  1379. @"
  1380. ┌─────┬────────────┐
  1381. │11111│222222222222│
  1382. │11111│222222222222│
  1383. │11111│222222222222│
  1384. │11111│222222222222│
  1385. │11111│222222222222│
  1386. │11111│222222222222│
  1387. │11111│222222222222│
  1388. │11111│222222222222│
  1389. └─────┴────────────┘";
  1390. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1391. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  1392. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  1393. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  1394. tileView.LayoutSubviews ();
  1395. tileView.Redraw (tileView.Bounds);
  1396. looksLike =
  1397. @"
  1398. ┌──────────────────┐
  1399. │111111111111111111│
  1400. │111111111111111111│
  1401. │111111111111111111│
  1402. │111111111111111111│
  1403. │111111111111111111│
  1404. │111111111111111111│
  1405. │111111111111111111│
  1406. │111111111111111111│
  1407. └──────────────────┘";
  1408. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1409. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1410. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  1411. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  1412. tileView.LayoutSubviews ();
  1413. tileView.Redraw (tileView.Bounds);
  1414. looksLike =
  1415. @"
  1416. ┌──────────────────┐
  1417. │222222222222222222│
  1418. │222222222222222222│
  1419. │222222222222222222│
  1420. │222222222222222222│
  1421. │222222222222222222│
  1422. │222222222222222222│
  1423. │222222222222222222│
  1424. │222222222222222222│
  1425. └──────────────────┘";
  1426. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1427. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1428. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  1429. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  1430. tileView.LayoutSubviews ();
  1431. tileView.Redraw (tileView.Bounds);
  1432. looksLike =
  1433. @"
  1434. ┌──────────────────┐
  1435. │333333333333333333│
  1436. │333333333333333333│
  1437. │333333333333333333│
  1438. │333333333333333333│
  1439. ├──────────────────┤
  1440. │444444444444444444│
  1441. │444444444444444444│
  1442. │444444444444444444│
  1443. └──────────────────┘";
  1444. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1445. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1446. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1447. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  1448. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  1449. tileView.LayoutSubviews ();
  1450. tileView.Redraw (tileView.Bounds);
  1451. looksLike =
  1452. @"
  1453. ┌──────────────────┐
  1454. │ │
  1455. │ │
  1456. │ │
  1457. │ │
  1458. │ │
  1459. │ │
  1460. │ │
  1461. │ │
  1462. └──────────────────┘";
  1463. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1464. }
  1465. [Fact, AutoInitShutdown]
  1466. public void TestNestedContainer3RightAnd1Down_TileVisibility_WithoutBorder ()
  1467. {
  1468. var tileView = GetNestedContainer3Right1Down (false);
  1469. tileView.Redraw (tileView.Bounds);
  1470. string looksLike =
  1471. @"
  1472. 111111│222222│333333
  1473. 111111│222222│333333
  1474. 111111│222222│333333
  1475. 111111│222222│333333
  1476. 111111│222222│333333
  1477. 111111│222222├──────
  1478. 111111│222222│444444
  1479. 111111│222222│444444
  1480. 111111│222222│444444
  1481. 111111│222222│444444";
  1482. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1483. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1484. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  1485. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  1486. tileView.LayoutSubviews ();
  1487. tileView.Redraw (tileView.Bounds);
  1488. looksLike =
  1489. @"
  1490. 2222222222222│333333
  1491. 2222222222222│333333
  1492. 2222222222222│333333
  1493. 2222222222222│333333
  1494. 2222222222222│333333
  1495. 2222222222222├──────
  1496. 2222222222222│444444
  1497. 2222222222222│444444
  1498. 2222222222222│444444
  1499. 2222222222222│444444";
  1500. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1501. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  1502. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  1503. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  1504. tileView.LayoutSubviews ();
  1505. tileView.Redraw (tileView.Bounds);
  1506. looksLike =
  1507. @"
  1508. 1111111111111│333333
  1509. 1111111111111│333333
  1510. 1111111111111│333333
  1511. 1111111111111│333333
  1512. 1111111111111│333333
  1513. 1111111111111├──────
  1514. 1111111111111│444444
  1515. 1111111111111│444444
  1516. 1111111111111│444444
  1517. 1111111111111│444444";
  1518. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1519. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  1520. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  1521. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  1522. tileView.LayoutSubviews ();
  1523. tileView.Redraw (tileView.Bounds);
  1524. looksLike =
  1525. @"
  1526. 111111│2222222222222
  1527. 111111│2222222222222
  1528. 111111│2222222222222
  1529. 111111│2222222222222
  1530. 111111│2222222222222
  1531. 111111│2222222222222
  1532. 111111│2222222222222
  1533. 111111│2222222222222
  1534. 111111│2222222222222
  1535. 111111│2222222222222";
  1536. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1537. tileView.Tiles.ElementAt (0).ContentView.Visible = true;
  1538. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  1539. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  1540. tileView.LayoutSubviews ();
  1541. tileView.Redraw (tileView.Bounds);
  1542. looksLike =
  1543. @"
  1544. 11111111111111111111
  1545. 11111111111111111111
  1546. 11111111111111111111
  1547. 11111111111111111111
  1548. 11111111111111111111
  1549. 11111111111111111111
  1550. 11111111111111111111
  1551. 11111111111111111111
  1552. 11111111111111111111
  1553. 11111111111111111111";
  1554. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1555. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1556. tileView.Tiles.ElementAt (1).ContentView.Visible = true;
  1557. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  1558. tileView.LayoutSubviews ();
  1559. tileView.Redraw (tileView.Bounds);
  1560. looksLike =
  1561. @"
  1562. 22222222222222222222
  1563. 22222222222222222222
  1564. 22222222222222222222
  1565. 22222222222222222222
  1566. 22222222222222222222
  1567. 22222222222222222222
  1568. 22222222222222222222
  1569. 22222222222222222222
  1570. 22222222222222222222
  1571. 22222222222222222222";
  1572. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1573. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1574. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  1575. tileView.Tiles.ElementAt (2).ContentView.Visible = true;
  1576. tileView.LayoutSubviews ();
  1577. tileView.Redraw (tileView.Bounds);
  1578. looksLike =
  1579. @"
  1580. 33333333333333333333
  1581. 33333333333333333333
  1582. 33333333333333333333
  1583. 33333333333333333333
  1584. 33333333333333333333
  1585. ────────────────────
  1586. 44444444444444444444
  1587. 44444444444444444444
  1588. 44444444444444444444
  1589. 44444444444444444444";
  1590. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1591. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1592. tileView.Tiles.ElementAt (0).ContentView.Visible = false;
  1593. tileView.Tiles.ElementAt (1).ContentView.Visible = false;
  1594. tileView.Tiles.ElementAt (2).ContentView.Visible = false;
  1595. tileView.LayoutSubviews ();
  1596. tileView.Redraw (tileView.Bounds);
  1597. looksLike =
  1598. @"
  1599. ";
  1600. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1601. }
  1602. [Fact, AutoInitShutdown]
  1603. public void TestNestedContainer3RightAnd1Down_TitleDoesNotOverspill()
  1604. {
  1605. var tileView = GetNestedContainer3Right1Down (true,true,1);
  1606. tileView.Redraw (tileView.Bounds);
  1607. string looksLike =
  1608. @"
  1609. ┌ T1 ─┬ T3 ──┬ T2 ─┐
  1610. │11111│333333│22222│
  1611. │11111│333333│22222│
  1612. │11111│333333│22222│
  1613. │11111│333333│22222│
  1614. │11111├ T4 ──┤22222│
  1615. │11111│444444│22222│
  1616. │11111│444444│22222│
  1617. │11111│444444│22222│
  1618. └─────┴──────┴─────┘";
  1619. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1620. }
  1621. [Fact, AutoInitShutdown]
  1622. public void TestNestedContainer3RightAnd1Down_TitleTriesToOverspill ()
  1623. {
  1624. var tileView = GetNestedContainer3Right1Down (true, true, 1);
  1625. tileView.Tiles.ElementAt (0).Title = new string ('x', 100);
  1626. ((TileView)tileView.Tiles.ElementAt (1).ContentView)
  1627. .Tiles.ElementAt(1).Title = new string ('y', 100);
  1628. tileView.Redraw (tileView.Bounds);
  1629. string looksLike =
  1630. @"
  1631. ┌ xxxx┬ T3 ──┬ T2 ─┐
  1632. │11111│333333│22222│
  1633. │11111│333333│22222│
  1634. │11111│333333│22222│
  1635. │11111│333333│22222│
  1636. │11111├ yyyyy┤22222│
  1637. │11111│444444│22222│
  1638. │11111│444444│22222│
  1639. │11111│444444│22222│
  1640. └─────┴──────┴─────┘";
  1641. TestHelpers.AssertDriverContentsAre (looksLike, output);
  1642. }
  1643. [Fact,AutoInitShutdown]
  1644. public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringRebuildForTileCount ()
  1645. {
  1646. var tv = GetTileView (20,10);
  1647. var myReusableView = new DisposeCounter ();
  1648. // I want my view in the first tile
  1649. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  1650. Assert.Equal (0, myReusableView.DisposalCount);
  1651. // I've changed my mind, I want 3 tiles now
  1652. tv.RebuildForTileCount (3);
  1653. // but I still want my view in the first tile
  1654. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  1655. Assert.Multiple (
  1656. ()=>Assert.Equal (0, myReusableView.DisposalCount)
  1657. ,()=> {
  1658. tv.Dispose ();
  1659. Assert.Equal (1, myReusableView.DisposalCount);
  1660. });
  1661. }
  1662. [Fact, AutoInitShutdown]
  1663. public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringInsertTile ()
  1664. {
  1665. var tv = GetTileView (20, 10);
  1666. var myReusableView = new DisposeCounter ();
  1667. // I want my view in the first tile
  1668. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  1669. Assert.Equal (0, myReusableView.DisposalCount);
  1670. // I've changed my mind, I want 3 tiles now
  1671. tv.InsertTile (0);
  1672. tv.InsertTile (2);
  1673. // but I still want my view in the first tile
  1674. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  1675. Assert.Multiple (
  1676. () => Assert.Equal (0, myReusableView.DisposalCount)
  1677. , () => {
  1678. tv.Dispose ();
  1679. // TODO seems to be double disposed ?!
  1680. Assert.True (myReusableView.DisposalCount >= 1);
  1681. });
  1682. }
  1683. [Theory, AutoInitShutdown]
  1684. [InlineData(0)]
  1685. [InlineData (1)]
  1686. public void TestDisposal_NoEarlyDisposalsOfUsersViews_DuringRemoveTile(int idx)
  1687. {
  1688. var tv = GetTileView (20, 10);
  1689. var myReusableView = new DisposeCounter ();
  1690. // I want my view in the first tile
  1691. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  1692. Assert.Equal (0, myReusableView.DisposalCount);
  1693. tv.RemoveTile (idx);
  1694. // but I still want my view in the first tile
  1695. tv.Tiles.ElementAt (0).ContentView.Add (myReusableView);
  1696. Assert.Multiple (
  1697. () => Assert.Equal (0, myReusableView.DisposalCount)
  1698. , () => {
  1699. tv.Dispose ();
  1700. // TODO seems to be double disposed ?!
  1701. Assert.True (myReusableView.DisposalCount >= 1);
  1702. });
  1703. }
  1704. private class DisposeCounter : View
  1705. {
  1706. public int DisposalCount;
  1707. protected override void Dispose (bool disposing)
  1708. {
  1709. DisposalCount++;
  1710. base.Dispose (disposing);
  1711. }
  1712. }
  1713. /// <summary>
  1714. /// Creates a vertical orientation root container with left pane split into
  1715. /// two (with horizontal splitter line).
  1716. /// </summary>
  1717. /// <param name="withBorder"></param>
  1718. /// <returns></returns>
  1719. private TileView GetNestedContainer2Left1Right (bool withBorder)
  1720. {
  1721. var container = GetTileView (20, 10, withBorder);
  1722. Assert.True (container.TrySplitTile (0, 2, out var newContainer));
  1723. newContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
  1724. newContainer.ColorScheme = new ColorScheme ();
  1725. container.ColorScheme = new ColorScheme ();
  1726. container.LayoutSubviews ();
  1727. return container;
  1728. }
  1729. /// <summary>
  1730. /// Creates a vertical orientation root container with 3 tiles.
  1731. /// The rightmost is split horizontally
  1732. /// </summary>
  1733. /// <param name="withBorder"></param>
  1734. /// <returns></returns>
  1735. private TileView GetNestedContainer3Right1Down (bool withBorder, bool withTitles = false, int split = 2)
  1736. {
  1737. var container = new TileView (3) {
  1738. Width = 20,
  1739. Height = 10
  1740. };
  1741. container.Border.BorderStyle = withBorder ? BorderStyle.Single : BorderStyle.None;
  1742. Assert.True (container.TrySplitTile (split, 2, out var newContainer));
  1743. newContainer.Orientation = Terminal.Gui.Graphs.Orientation.Horizontal;
  1744. int i = 0;
  1745. foreach (var tile in container.Tiles.Union (newContainer.Tiles)) {
  1746. if(tile.ContentView is TileView) {
  1747. continue;
  1748. }
  1749. i++;
  1750. if (withTitles) {
  1751. tile.Title = "T" + i;
  1752. }
  1753. tile.ContentView.Add (new TextView {
  1754. Width = Dim.Fill (),
  1755. Height = Dim.Fill (),
  1756. Text =
  1757. string.Join ('\n',
  1758. Enumerable.Repeat (
  1759. new string (i.ToString () [0], 100)
  1760. , 10).ToArray ()),
  1761. WordWrap = false
  1762. });
  1763. }
  1764. newContainer.ColorScheme = new ColorScheme ();
  1765. container.ColorScheme = new ColorScheme ();
  1766. container.LayoutSubviews ();
  1767. return container;
  1768. }
  1769. private LineView GetLine (TileView tileView)
  1770. {
  1771. return tileView.Subviews.OfType<LineView> ().Single ();
  1772. }
  1773. private void SetInputFocusLine (TileView tileView)
  1774. {
  1775. var line = GetLine (tileView);
  1776. line.SetFocus ();
  1777. Assert.True (line.HasFocus);
  1778. }
  1779. private TileView Get5x1TilesView (bool border = true)
  1780. {
  1781. var tv = new TileView (5) { Width = 25, Height = 4, ColorScheme = new ColorScheme (),
  1782. Border = new Border () { BorderStyle = BorderStyle.Single }
  1783. };
  1784. if (!border) {
  1785. tv.Border.BorderStyle = BorderStyle.None;
  1786. }
  1787. tv.Tiles.ElementAt (0).ContentView.Add (new Label (new string ('1', 100)) { AutoSize = false, Width = Dim.Fill (), Height = 1 });
  1788. tv.Tiles.ElementAt (1).ContentView.Add (new Label (new string ('2', 100)) { AutoSize = false, Width = Dim.Fill (), Height = 1 });
  1789. tv.Tiles.ElementAt (2).ContentView.Add (new Label (new string ('3', 100)) { AutoSize = false, Width = Dim.Fill (), Height = 1 });
  1790. tv.Tiles.ElementAt (3).ContentView.Add (new Label (new string ('4', 100)) { AutoSize = false, Width = Dim.Fill (), Height = 1 });
  1791. tv.Tiles.ElementAt (4).ContentView.Add (new Label (new string ('5', 100)) { AutoSize = false, Width = Dim.Fill (), Height = 1 });
  1792. Application.Top.Add (tv);
  1793. tv.BeginInit ();
  1794. tv.EndInit ();
  1795. tv.LayoutSubviews ();
  1796. return tv;
  1797. }
  1798. private TileView Get11By3TileView (out LineView line, bool withBorder = false)
  1799. {
  1800. var split = Get11By3TileView (withBorder);
  1801. line = GetLine (split);
  1802. return split;
  1803. }
  1804. private TileView Get11By3TileView (bool withBorder = false)
  1805. {
  1806. return GetTileView (11, 3, withBorder);
  1807. }
  1808. private TileView GetTileView (int width, int height, bool withBorder = false)
  1809. {
  1810. var container = new TileView () {
  1811. Width = width,
  1812. Height = height,
  1813. };
  1814. container.Border.BorderStyle = withBorder ? BorderStyle.Single : BorderStyle.None;
  1815. container.Tiles.ElementAt (0).ContentView.Add (new Label (new string ('1', 100)) { Width = Dim.Fill (), Height = 1, AutoSize = false });
  1816. container.Tiles.ElementAt (0).ContentView.Add (new Label (new string ('1', 100)) { Width = Dim.Fill (), Height = 1, AutoSize = false, Y = 1 });
  1817. container.Tiles.ElementAt (1).ContentView.Add (new Label (new string ('2', 100)) { Width = Dim.Fill (), Height = 1, AutoSize = false });
  1818. container.Tiles.ElementAt (1).ContentView.Add (new Label (new string ('2', 100)) { Width = Dim.Fill (), Height = 1, AutoSize = false, Y = 1 });
  1819. container.Tiles.ElementAt (0).MinSize = 0;
  1820. container.Tiles.ElementAt (1).MinSize = 0;
  1821. Application.Top.Add (container);
  1822. container.ColorScheme = new ColorScheme ();
  1823. container.LayoutSubviews ();
  1824. container.BeginInit ();
  1825. container.EndInit ();
  1826. return container;
  1827. }
  1828. }
  1829. }