TileViewTests.cs 63 KB

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