TileViewTests.cs 67 KB

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