TileViewTests.cs 66 KB

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