TileViewTests.cs 77 KB

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