TileViewTests.cs 67 KB

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