LayoutTests.cs 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965
  1. using System;
  2. using System.Text;
  3. using Xunit;
  4. using Xunit.Abstractions;
  5. // Alias Console to MockConsole so we don't accidentally use Console
  6. using Console = Terminal.Gui.FakeConsole;
  7. namespace Terminal.Gui.ViewTests {
  8. public class LayoutTests {
  9. readonly ITestOutputHelper output;
  10. public LayoutTests (ITestOutputHelper output)
  11. {
  12. this.output = output;
  13. }
  14. [Fact]
  15. public void TopologicalSort_Missing_Add ()
  16. {
  17. var root = new View ();
  18. var sub1 = new View ();
  19. root.Add (sub1);
  20. var sub2 = new View ();
  21. sub1.Width = Dim.Width (sub2);
  22. Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
  23. sub2.Width = Dim.Width (sub1);
  24. Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
  25. root.Dispose ();
  26. sub1.Dispose ();
  27. sub2.Dispose ();
  28. }
  29. [Fact]
  30. public void TopologicalSort_Recursive_Ref ()
  31. {
  32. var root = new View ();
  33. var sub1 = new View ();
  34. root.Add (sub1);
  35. var sub2 = new View ();
  36. root.Add (sub2);
  37. sub2.Width = Dim.Width (sub2);
  38. var exception = Record.Exception (root.LayoutSubviews);
  39. Assert.Null (exception);
  40. root.Dispose ();
  41. sub1.Dispose ();
  42. sub2.Dispose ();
  43. }
  44. [Fact]
  45. public void LayoutSubviews_No_SuperView ()
  46. {
  47. var root = new View ();
  48. var first = new View () { Id = "first", X = 1, Y = 2, Height = 3, Width = 4 };
  49. root.Add (first);
  50. var second = new View () { Id = "second" };
  51. root.Add (second);
  52. second.X = Pos.Right (first) + 1;
  53. root.LayoutSubviews ();
  54. Assert.Equal (6, second.Frame.X);
  55. root.Dispose ();
  56. first.Dispose ();
  57. second.Dispose ();
  58. }
  59. [Fact]
  60. public void LayoutSubviews_RootHas_SuperView ()
  61. {
  62. var top = new View ();
  63. var root = new View ();
  64. top.Add (root);
  65. var first = new View () { Id = "first", X = 1, Y = 2, Height = 3, Width = 4 };
  66. root.Add (first);
  67. var second = new View () { Id = "second" };
  68. root.Add (second);
  69. second.X = Pos.Right (first) + 1;
  70. root.LayoutSubviews ();
  71. Assert.Equal (6, second.Frame.X);
  72. root.Dispose ();
  73. top.Dispose ();
  74. first.Dispose ();
  75. second.Dispose ();
  76. }
  77. [Fact]
  78. public void LayoutSubviews_ViewThatRefsSubView_Throws ()
  79. {
  80. var root = new View ();
  81. var super = new View ();
  82. root.Add (super);
  83. var sub = new View ();
  84. super.Add (sub);
  85. super.Width = Dim.Width (sub);
  86. Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
  87. root.Dispose ();
  88. super.Dispose ();
  89. }
  90. [Fact, AutoInitShutdown]
  91. public void TrySetWidth_ForceValidatePosDim ()
  92. {
  93. var top = new View () {
  94. X = 0,
  95. Y = 0,
  96. Width = 80,
  97. };
  98. var v = new View () {
  99. Width = Dim.Fill (),
  100. ValidatePosDim = true
  101. };
  102. top.Add (v);
  103. Assert.False (v.TrySetWidth (70, out int rWidth));
  104. Assert.Equal (70, rWidth);
  105. v.Width = Dim.Fill (1);
  106. Assert.False (v.TrySetWidth (70, out rWidth));
  107. Assert.Equal (69, rWidth);
  108. v.Width = null;
  109. Assert.True (v.TrySetWidth (70, out rWidth));
  110. Assert.Equal (70, rWidth);
  111. Assert.False (v.IsInitialized);
  112. Application.Top.Add (top);
  113. Application.Begin (Application.Top);
  114. Assert.True (v.IsInitialized);
  115. v.Width = Dim.Fill (1);
  116. Assert.Throws<ArgumentException> (() => v.Width = 75);
  117. v.LayoutStyle = LayoutStyle.Absolute;
  118. v.Width = 75;
  119. Assert.True (v.TrySetWidth (60, out rWidth));
  120. Assert.Equal (60, rWidth);
  121. }
  122. [Fact, AutoInitShutdown]
  123. public void TrySetHeight_ForceValidatePosDim ()
  124. {
  125. var top = new View () {
  126. X = 0,
  127. Y = 0,
  128. Height = 20
  129. };
  130. var v = new View () {
  131. Height = Dim.Fill (),
  132. ValidatePosDim = true
  133. };
  134. top.Add (v);
  135. Assert.False (v.TrySetHeight (10, out int rHeight));
  136. Assert.Equal (10, rHeight);
  137. v.Height = Dim.Fill (1);
  138. Assert.False (v.TrySetHeight (10, out rHeight));
  139. Assert.Equal (9, rHeight);
  140. v.Height = null;
  141. Assert.True (v.TrySetHeight (10, out rHeight));
  142. Assert.Equal (10, rHeight);
  143. Assert.False (v.IsInitialized);
  144. Application.Top.Add (top);
  145. Application.Begin (Application.Top);
  146. Assert.True (v.IsInitialized);
  147. v.Height = Dim.Fill (1);
  148. Assert.Throws<ArgumentException> (() => v.Height = 15);
  149. v.LayoutStyle = LayoutStyle.Absolute;
  150. v.Height = 15;
  151. Assert.True (v.TrySetHeight (5, out rHeight));
  152. Assert.Equal (5, rHeight);
  153. }
  154. [Fact, TestRespondersDisposed]
  155. public void GetCurrentWidth_TrySetWidth ()
  156. {
  157. var top = new View () {
  158. X = 0,
  159. Y = 0,
  160. Width = 80,
  161. };
  162. var v = new View () {
  163. Width = Dim.Fill ()
  164. };
  165. top.Add (v);
  166. top.BeginInit ();
  167. top.EndInit ();
  168. top.LayoutSubviews ();
  169. Assert.False (v.AutoSize);
  170. Assert.True (v.TrySetWidth (0, out _));
  171. Assert.Equal (80, v.Frame.Width);
  172. v.Width = Dim.Fill (1);
  173. top.LayoutSubviews ();
  174. Assert.True (v.TrySetWidth (0, out _));
  175. Assert.Equal (79, v.Frame.Width);
  176. v.AutoSize = true;
  177. top.LayoutSubviews ();
  178. Assert.True (v.TrySetWidth (0, out _));
  179. top.Dispose ();
  180. }
  181. [Fact]
  182. public void GetCurrentHeight_TrySetHeight ()
  183. {
  184. var top = new View () {
  185. X = 0,
  186. Y = 0,
  187. Height = 20
  188. };
  189. var v = new View () {
  190. Height = Dim.Fill ()
  191. };
  192. top.Add (v);
  193. top.BeginInit ();
  194. top.EndInit ();
  195. top.LayoutSubviews ();
  196. Assert.False (v.AutoSize);
  197. Assert.True (v.TrySetHeight (0, out _));
  198. Assert.Equal (20, v.Frame.Height);
  199. v.Height = Dim.Fill (1);
  200. top.LayoutSubviews ();
  201. Assert.True (v.TrySetHeight (0, out _));
  202. Assert.Equal (19, v.Frame.Height);
  203. v.AutoSize = true;
  204. top.LayoutSubviews ();
  205. Assert.True (v.TrySetHeight (0, out _));
  206. top.Dispose ();
  207. }
  208. [Fact]
  209. public void AutoSize_False_If_Text_Emmpty ()
  210. {
  211. var view1 = new View ();
  212. var view2 = new View ("");
  213. var view3 = new View () { Text = "" };
  214. Assert.False (view1.AutoSize);
  215. Assert.False (view2.AutoSize);
  216. Assert.False (view3.AutoSize);
  217. view1.Dispose ();
  218. view2.Dispose ();
  219. view3.Dispose ();
  220. }
  221. [Fact]
  222. public void AutoSize_False_If_Text_Is_Not_Emmpty ()
  223. {
  224. var view1 = new View ();
  225. view1.Text = "Hello World";
  226. var view2 = new View ("Hello World");
  227. var view3 = new View () { Text = "Hello World" };
  228. Assert.False (view1.AutoSize);
  229. Assert.False (view2.AutoSize);
  230. Assert.False (view3.AutoSize);
  231. view1.Dispose ();
  232. view2.Dispose ();
  233. view3.Dispose ();
  234. }
  235. [Fact]
  236. public void AutoSize_True_Label_If_Text_Emmpty ()
  237. {
  238. var label1 = new Label ();
  239. var label2 = new Label ("");
  240. var label3 = new Label () { Text = "" };
  241. Assert.True (label1.AutoSize);
  242. Assert.True (label2.AutoSize);
  243. Assert.True (label3.AutoSize);
  244. label1.Dispose ();
  245. label2.Dispose ();
  246. label3.Dispose ();
  247. }
  248. [Fact]
  249. public void AutoSize_True_Label_If_Text_Is_Not_Emmpty ()
  250. {
  251. var label1 = new Label ();
  252. label1.Text = "Hello World";
  253. var label2 = new Label ("Hello World");
  254. var label3 = new Label () { Text = "Hello World" };
  255. Assert.True (label1.AutoSize);
  256. Assert.True (label2.AutoSize);
  257. Assert.True (label3.AutoSize);
  258. label1.Dispose ();
  259. label2.Dispose ();
  260. label3.Dispose ();
  261. }
  262. [Fact]
  263. public void AutoSize_False_ResizeView_Is_Always_False ()
  264. {
  265. var super = new View ();
  266. var label = new Label () { AutoSize = false };
  267. super.Add (label);
  268. label.Text = "New text";
  269. super.LayoutSubviews ();
  270. Assert.False (label.AutoSize);
  271. Assert.Equal ("(0,0,0,1)", label.Bounds.ToString ());
  272. super.Dispose ();
  273. }
  274. [Fact]
  275. public void AutoSize_True_ResizeView_With_Dim_Absolute ()
  276. {
  277. var super = new View ();
  278. var label = new Label ();
  279. label.Text = "New text";
  280. // BUGBUG: v2 - label was never added to super, so it was never laid out.
  281. super.Add (label);
  282. super.LayoutSubviews ();
  283. Assert.True (label.AutoSize);
  284. Assert.Equal ("(0,0,8,1)", label.Bounds.ToString ());
  285. super.Dispose ();
  286. }
  287. [Fact, AutoInitShutdown]
  288. public void AutoSize_False_ResizeView_With_Dim_Fill_After_IsInitialized ()
  289. {
  290. var win = new Window (new Rect (0, 0, 30, 80));
  291. var label = new Label () { AutoSize = false, Width = Dim.Fill (), Height = Dim.Fill () };
  292. win.Add (label);
  293. Application.Top.Add (win);
  294. // Text is empty but height=1 by default, see Label view
  295. Assert.False (label.AutoSize);
  296. Assert.Equal ("(0,0,0,1)", label.Bounds.ToString ());
  297. label.Text = "New text\nNew line";
  298. Application.Top.LayoutSubviews ();
  299. Assert.False (label.AutoSize);
  300. Assert.Equal ("(0,0,28,78)", label.Bounds.ToString ());
  301. Assert.False (label.IsInitialized);
  302. var rs = Application.Begin (Application.Top);
  303. Assert.True (label.IsInitialized);
  304. Assert.False (label.AutoSize);
  305. Assert.Equal ("(0,0,28,78)", label.Bounds.ToString ());
  306. Application.End (rs);
  307. }
  308. [Fact, AutoInitShutdown]
  309. public void AutoSize_False_SetWidthHeight_With_Dim_Fill_And_Dim_Absolute_After_IsAdded_And_IsInitialized ()
  310. {
  311. var win = new Window (new Rect (0, 0, 30, 80));
  312. var label = new Label () { Width = Dim.Fill () };
  313. win.Add (label);
  314. Application.Top.Add (win);
  315. Assert.True (label.IsAdded);
  316. // Text is empty but height=1 by default, see Label view
  317. Assert.True (label.AutoSize);
  318. // BUGBUG: LayoutSubviews has not been called, so this test is not really valid (pos/dim are indeterminate, not 0)
  319. // Not really a bug because View call OnResizeNeeded method on the SetInitialProperties method
  320. Assert.Equal ("(0,0,0,1)", label.Bounds.ToString ());
  321. label.Text = "First line\nSecond line";
  322. Application.Top.LayoutSubviews ();
  323. Assert.True (label.AutoSize);
  324. // BUGBUG: This test is bogus: label has not been initialized. pos/dim is indeterminate!
  325. Assert.Equal ("(0,0,28,2)", label.Bounds.ToString ());
  326. Assert.False (label.IsInitialized);
  327. var rs = Application.Begin (Application.Top);
  328. Assert.True (label.AutoSize);
  329. Assert.Equal ("(0,0,28,2)", label.Bounds.ToString ());
  330. Assert.True (label.IsInitialized);
  331. label.AutoSize = false;
  332. Application.Refresh ();
  333. Assert.False (label.AutoSize);
  334. Assert.Equal ("(0,0,28,1)", label.Bounds.ToString ());
  335. Application.End (rs);
  336. }
  337. [Fact, AutoInitShutdown]
  338. public void AutoSize_False_SetWidthHeight_With_Dim_Fill_And_Dim_Absolute_With_Initialization ()
  339. {
  340. var win = new Window (new Rect (0, 0, 30, 80));
  341. var label = new Label () { Width = Dim.Fill () };
  342. win.Add (label);
  343. Application.Top.Add (win);
  344. // Text is empty but height=1 by default, see Label view
  345. Assert.True (label.AutoSize);
  346. Assert.Equal ("(0,0,0,1)", label.Bounds.ToString ());
  347. var rs = Application.Begin (Application.Top);
  348. Assert.True (label.AutoSize);
  349. // Here the AutoSize ensuring the right size with width 28 (Dim.Fill)
  350. // and height 0 because wasn't set and the text is empty
  351. // BUGBUG: Because of #2450, this test is bogus: pos/dim is indeterminate!
  352. //Assert.Equal ("(0,0,28,0)", label.Bounds.ToString ());
  353. label.Text = "First line\nSecond line";
  354. Application.Refresh ();
  355. // Here the AutoSize ensuring the right size with width 28 (Dim.Fill)
  356. // and height 2 because wasn't set and the text has 2 lines
  357. Assert.True (label.AutoSize);
  358. Assert.Equal ("(0,0,28,2)", label.Bounds.ToString ());
  359. label.AutoSize = false;
  360. Application.Refresh ();
  361. // Here the SetMinWidthHeight ensuring the minimum height
  362. Assert.False (label.AutoSize);
  363. Assert.Equal ("(0,0,28,1)", label.Bounds.ToString ());
  364. label.Text = "First changed line\nSecond changed line\nNew line";
  365. Application.Refresh ();
  366. // Here the AutoSize is false and the width 28 (Dim.Fill) and
  367. // height 1 because wasn't set and SetMinWidthHeight ensuring the minimum height
  368. Assert.False (label.AutoSize);
  369. Assert.Equal ("(0,0,28,1)", label.Bounds.ToString ());
  370. label.AutoSize = true;
  371. Application.Refresh ();
  372. // Here the AutoSize ensuring the right size with width 28 (Dim.Fill)
  373. // and height 3 because wasn't set and the text has 3 lines
  374. Assert.True (label.AutoSize);
  375. // BUGBUG: v2 - AutoSize is broken - temporarily disabling test See #2432
  376. //Assert.Equal ("(0,0,28,3)", label.Bounds.ToString ());
  377. Application.End (rs);
  378. }
  379. [Fact, AutoInitShutdown]
  380. public void AutoSize_True_Setting_With_Height_Horizontal ()
  381. {
  382. var label = new Label ("Hello") { Width = 10, Height = 2 };
  383. var viewX = new View ("X") { X = Pos.Right (label) };
  384. var viewY = new View ("Y") { Y = Pos.Bottom (label) };
  385. Application.Top.Add (label, viewX, viewY);
  386. var rs = Application.Begin (Application.Top);
  387. Assert.True (label.AutoSize);
  388. Assert.Equal (new Rect (0, 0, 10, 2), label.Frame);
  389. var expected = @"
  390. Hello X
  391. Y
  392. ";
  393. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  394. Assert.Equal (new Rect (0, 0, 11, 3), pos);
  395. label.AutoSize = false;
  396. Application.Refresh ();
  397. Assert.False (label.AutoSize);
  398. Assert.Equal (new Rect (0, 0, 10, 2), label.Frame);
  399. expected = @"
  400. Hello X
  401. Y
  402. ";
  403. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  404. Assert.Equal (new Rect (0, 0, 11, 3), pos);
  405. Application.End (rs);
  406. }
  407. [Fact, AutoInitShutdown]
  408. public void AutoSize_True_Setting_With_Height_Vertical ()
  409. {
  410. var label = new Label ("Hello") { Width = 2, Height = 10, TextDirection = TextDirection.TopBottom_LeftRight };
  411. var viewX = new View ("X") { X = Pos.Right (label) };
  412. var viewY = new View ("Y") { Y = Pos.Bottom (label) };
  413. Application.Top.Add (label, viewX, viewY);
  414. var rs = Application.Begin (Application.Top);
  415. Assert.True (label.AutoSize);
  416. Assert.Equal (new Rect (0, 0, 2, 10), label.Frame);
  417. var expected = @"
  418. H X
  419. e
  420. l
  421. l
  422. o
  423. Y
  424. ";
  425. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  426. Assert.Equal (new Rect (0, 0, 3, 11), pos);
  427. label.AutoSize = false;
  428. Application.Refresh ();
  429. Assert.False (label.AutoSize);
  430. Assert.Equal (new Rect (0, 0, 2, 10), label.Frame);
  431. expected = @"
  432. H X
  433. e
  434. l
  435. l
  436. o
  437. Y
  438. ";
  439. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  440. Assert.Equal (new Rect (0, 0, 3, 11), pos);
  441. Application.End (rs);
  442. }
  443. [Fact]
  444. [AutoInitShutdown]
  445. public void Excess_Text_Is_Erased_When_The_Width_Is_Reduced ()
  446. {
  447. var lbl = new Label ("123");
  448. Application.Top.Add (lbl);
  449. var rs = Application.Begin (Application.Top);
  450. Assert.True (lbl.AutoSize);
  451. Assert.Equal ("123 ", GetContents ());
  452. lbl.Text = "12";
  453. // Here the AutoSize ensuring the right size with width 3 (Dim.Absolute)
  454. // that was set on the OnAdded method with the text length of 3
  455. // and height 1 because wasn't set and the text has 1 line
  456. Assert.Equal (new Rect (0, 0, 3, 1), lbl.Frame);
  457. Assert.Equal (new Rect (0, 0, 3, 1), lbl._needsDisplayRect);
  458. Assert.Equal (new Rect (0, 0, 0, 0), lbl.SuperView._needsDisplayRect);
  459. Assert.True (lbl.SuperView.LayoutNeeded);
  460. lbl.SuperView.Draw ();
  461. Assert.Equal ("12 ", GetContents ());
  462. string GetContents ()
  463. {
  464. var text = "";
  465. for (int i = 0; i < 4; i++) {
  466. text += Application.Driver.Contents [0, i].Rune;
  467. }
  468. return text;
  469. }
  470. Application.End (rs);
  471. }
  472. [Fact, AutoInitShutdown]
  473. public void Width_Height_SetMinWidthHeight_Narrow_Wide_Runes ()
  474. {
  475. var text = $"First line{Environment.NewLine}Second line";
  476. var horizontalView = new View () {
  477. Width = 20,
  478. Height = 1,
  479. Text = text
  480. };
  481. var verticalView = new View () {
  482. Y = 3,
  483. Height = 20,
  484. Width = 1,
  485. Text = text,
  486. TextDirection = TextDirection.TopBottom_LeftRight
  487. };
  488. var win = new Window () {
  489. Width = Dim.Fill (),
  490. Height = Dim.Fill (),
  491. Text = "Window"
  492. };
  493. win.Add (horizontalView, verticalView);
  494. Application.Top.Add (win);
  495. var rs = Application.Begin (Application.Top);
  496. ((FakeDriver)Application.Driver).SetBufferSize (32, 32);
  497. Assert.False (horizontalView.AutoSize);
  498. Assert.False (verticalView.AutoSize);
  499. Assert.Equal (new Rect (0, 0, 20, 1), horizontalView.Frame);
  500. Assert.Equal (new Rect (0, 3, 1, 20), verticalView.Frame);
  501. var expected = @"
  502. ┌──────────────────────────────┐
  503. │First line Second li │
  504. │ │
  505. │ │
  506. │F │
  507. │i │
  508. │r │
  509. │s │
  510. │t │
  511. │ │
  512. │l │
  513. │i │
  514. │n │
  515. │e │
  516. │ │
  517. │S │
  518. │e │
  519. │c │
  520. │o │
  521. │n │
  522. │d │
  523. │ │
  524. │l │
  525. │i │
  526. │ │
  527. │ │
  528. │ │
  529. │ │
  530. │ │
  531. │ │
  532. │ │
  533. └──────────────────────────────┘
  534. ";
  535. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  536. Assert.Equal (new Rect (0, 0, 32, 32), pos);
  537. verticalView.Text = $"最初の行{Environment.NewLine}二行目";
  538. Application.Top.Draw ();
  539. Assert.Equal (new Rect (0, 3, 2, 20), verticalView.Frame);
  540. expected = @"
  541. ┌──────────────────────────────┐
  542. │First line Second li │
  543. │ │
  544. │ │
  545. │最 │
  546. │初 │
  547. │の │
  548. │行 │
  549. │ │
  550. │二 │
  551. │行 │
  552. │目 │
  553. │ │
  554. │ │
  555. │ │
  556. │ │
  557. │ │
  558. │ │
  559. │ │
  560. │ │
  561. │ │
  562. │ │
  563. │ │
  564. │ │
  565. │ │
  566. │ │
  567. │ │
  568. │ │
  569. │ │
  570. │ │
  571. │ │
  572. └──────────────────────────────┘
  573. ";
  574. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  575. Assert.Equal (new Rect (0, 0, 32, 32), pos);
  576. Application.End (rs);
  577. }
  578. [Fact, AutoInitShutdown]
  579. public void TextDirection_Toggle ()
  580. {
  581. var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
  582. var view = new View ();
  583. win.Add (view);
  584. Application.Top.Add (win);
  585. var rs = Application.Begin (Application.Top);
  586. ((FakeDriver)Application.Driver).SetBufferSize (22, 22);
  587. Assert.Equal (new Rect (0, 0, 22, 22), win.Frame);
  588. Assert.Equal (new Rect (0, 0, 22, 22), win.Margin.Frame);
  589. Assert.Equal (new Rect (0, 0, 22, 22), win.Border.Frame);
  590. Assert.Equal (new Rect (1, 1, 20, 20), win.Padding.Frame);
  591. Assert.False (view.AutoSize);
  592. Assert.Equal (TextDirection.LeftRight_TopBottom, view.TextDirection);
  593. Assert.Equal (Rect.Empty, view.Frame);
  594. Assert.Equal ("Absolute(0)", view.X.ToString ());
  595. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  596. Assert.Equal ("Absolute(0)", view.Width.ToString ());
  597. Assert.Equal ("Absolute(0)", view.Height.ToString ());
  598. var expected = @"
  599. ┌────────────────────┐
  600. │ │
  601. │ │
  602. │ │
  603. │ │
  604. │ │
  605. │ │
  606. │ │
  607. │ │
  608. │ │
  609. │ │
  610. │ │
  611. │ │
  612. │ │
  613. │ │
  614. │ │
  615. │ │
  616. │ │
  617. │ │
  618. │ │
  619. │ │
  620. └────────────────────┘
  621. ";
  622. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  623. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  624. view.Text = "Hello World";
  625. view.Width = 11;
  626. view.Height = 1;
  627. win.LayoutSubviews ();
  628. Application.Refresh ();
  629. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  630. Assert.Equal ("Absolute(0)", view.X.ToString ());
  631. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  632. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  633. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  634. expected = @"
  635. ┌────────────────────┐
  636. │Hello World │
  637. │ │
  638. │ │
  639. │ │
  640. │ │
  641. │ │
  642. │ │
  643. │ │
  644. │ │
  645. │ │
  646. │ │
  647. │ │
  648. │ │
  649. │ │
  650. │ │
  651. │ │
  652. │ │
  653. │ │
  654. │ │
  655. │ │
  656. └────────────────────┘
  657. ";
  658. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  659. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  660. view.AutoSize = true;
  661. view.Text = "Hello Worlds";
  662. Application.Refresh ();
  663. Assert.Equal (new Rect (0, 0, 12, 1), view.Frame);
  664. Assert.Equal ("Absolute(0)", view.X.ToString ());
  665. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  666. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  667. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  668. expected = @"
  669. ┌────────────────────┐
  670. │Hello Worlds │
  671. │ │
  672. │ │
  673. │ │
  674. │ │
  675. │ │
  676. │ │
  677. │ │
  678. │ │
  679. │ │
  680. │ │
  681. │ │
  682. │ │
  683. │ │
  684. │ │
  685. │ │
  686. │ │
  687. │ │
  688. │ │
  689. │ │
  690. └────────────────────┘
  691. ";
  692. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  693. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  694. view.TextDirection = TextDirection.TopBottom_LeftRight;
  695. Application.Refresh ();
  696. Assert.Equal (new Rect (0, 0, 11, 12), view.Frame);
  697. Assert.Equal ("Absolute(0)", view.X.ToString ());
  698. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  699. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  700. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  701. expected = @"
  702. ┌────────────────────┐
  703. │H │
  704. │e │
  705. │l │
  706. │l │
  707. │o │
  708. │ │
  709. │W │
  710. │o │
  711. │r │
  712. │l │
  713. │d │
  714. │s │
  715. │ │
  716. │ │
  717. │ │
  718. │ │
  719. │ │
  720. │ │
  721. │ │
  722. │ │
  723. └────────────────────┘
  724. ";
  725. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  726. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  727. view.AutoSize = false;
  728. view.Height = 1;
  729. Application.Refresh ();
  730. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  731. Assert.Equal ("Absolute(0)", view.X.ToString ());
  732. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  733. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  734. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  735. expected = @"
  736. ┌────────────────────┐
  737. │HelloWorlds │
  738. │ │
  739. │ │
  740. │ │
  741. │ │
  742. │ │
  743. │ │
  744. │ │
  745. │ │
  746. │ │
  747. │ │
  748. │ │
  749. │ │
  750. │ │
  751. │ │
  752. │ │
  753. │ │
  754. │ │
  755. │ │
  756. │ │
  757. └────────────────────┘
  758. ";
  759. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  760. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  761. view.PreserveTrailingSpaces = true;
  762. Application.Refresh ();
  763. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  764. Assert.Equal ("Absolute(0)", view.X.ToString ());
  765. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  766. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  767. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  768. expected = @"
  769. ┌────────────────────┐
  770. │Hello World │
  771. │ │
  772. │ │
  773. │ │
  774. │ │
  775. │ │
  776. │ │
  777. │ │
  778. │ │
  779. │ │
  780. │ │
  781. │ │
  782. │ │
  783. │ │
  784. │ │
  785. │ │
  786. │ │
  787. │ │
  788. │ │
  789. │ │
  790. └────────────────────┘
  791. ";
  792. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  793. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  794. view.PreserveTrailingSpaces = false;
  795. var f = view.Frame;
  796. view.Width = f.Height;
  797. view.Height = f.Width;
  798. view.TextDirection = TextDirection.TopBottom_LeftRight;
  799. Application.Refresh ();
  800. Assert.Equal (new Rect (0, 0, 1, 11), view.Frame);
  801. Assert.Equal ("Absolute(0)", view.X.ToString ());
  802. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  803. Assert.Equal ("Absolute(1)", view.Width.ToString ());
  804. Assert.Equal ("Absolute(11)", view.Height.ToString ());
  805. expected = @"
  806. ┌────────────────────┐
  807. │H │
  808. │e │
  809. │l │
  810. │l │
  811. │o │
  812. │ │
  813. │W │
  814. │o │
  815. │r │
  816. │l │
  817. │d │
  818. │ │
  819. │ │
  820. │ │
  821. │ │
  822. │ │
  823. │ │
  824. │ │
  825. │ │
  826. │ │
  827. └────────────────────┘
  828. ";
  829. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  830. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  831. view.AutoSize = true;
  832. Application.Refresh ();
  833. Assert.Equal (new Rect (0, 0, 1, 12), view.Frame);
  834. Assert.Equal ("Absolute(0)", view.X.ToString ());
  835. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  836. Assert.Equal ("Absolute(1)", view.Width.ToString ());
  837. Assert.Equal ("Absolute(12)", view.Height.ToString ());
  838. expected = @"
  839. ┌────────────────────┐
  840. │H │
  841. │e │
  842. │l │
  843. │l │
  844. │o │
  845. │ │
  846. │W │
  847. │o │
  848. │r │
  849. │l │
  850. │d │
  851. │s │
  852. │ │
  853. │ │
  854. │ │
  855. │ │
  856. │ │
  857. │ │
  858. │ │
  859. │ │
  860. └────────────────────┘
  861. ";
  862. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  863. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  864. Application.End (rs);
  865. }
  866. [Fact, AutoInitShutdown]
  867. public void Width_Height_AutoSize_True_Stay_True_If_TextFormatter_Size_Fit ()
  868. {
  869. var text = $"Fi_nish 終";
  870. var horizontalView = new View () {
  871. Id = "horizontalView",
  872. AutoSize = true,
  873. HotKeySpecifier = (Rune)'_',
  874. Text = text
  875. };
  876. var verticalView = new View () {
  877. Id = "verticalView",
  878. Y = 3,
  879. AutoSize = true,
  880. HotKeySpecifier = (Rune)'_',
  881. Text = text,
  882. TextDirection = TextDirection.TopBottom_LeftRight
  883. };
  884. var win = new Window () {
  885. Id = "win",
  886. Width = Dim.Fill (),
  887. Height = Dim.Fill (),
  888. Text = "Window"
  889. };
  890. win.Add (horizontalView, verticalView);
  891. Application.Top.Add (win);
  892. var rs = Application.Begin (Application.Top);
  893. ((FakeDriver)Application.Driver).SetBufferSize (22, 22);
  894. Assert.True (horizontalView.AutoSize);
  895. Assert.True (verticalView.AutoSize);
  896. Assert.Equal (new Size (10, 1), horizontalView.TextFormatter.Size);
  897. Assert.Equal (new Size (2, 9), verticalView.TextFormatter.Size);
  898. Assert.Equal (new Rect (0, 0, 9, 1), horizontalView.Frame);
  899. Assert.Equal ("Absolute(0)", horizontalView.X.ToString ());
  900. Assert.Equal ("Absolute(0)", horizontalView.Y.ToString ());
  901. // BUGBUG - v2 - With v1 AutoSize = true Width/Height should always grow or keep initial value,
  902. // but in v2, autosize will be replaced by Dim.Fit. Disabling test for now.
  903. Assert.Equal ("Absolute(9)", horizontalView.Width.ToString ());
  904. Assert.Equal ("Absolute(1)", horizontalView.Height.ToString ());
  905. Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame);
  906. Assert.Equal ("Absolute(0)", verticalView.X.ToString ());
  907. Assert.Equal ("Absolute(3)", verticalView.Y.ToString ());
  908. Assert.Equal ("Absolute(2)", verticalView.Width.ToString ());
  909. Assert.Equal ("Absolute(8)", verticalView.Height.ToString ());
  910. var expected = @"
  911. ┌────────────────────┐
  912. │Finish 終 │
  913. │ │
  914. │ │
  915. │F │
  916. │i │
  917. │n │
  918. │i │
  919. │s │
  920. │h │
  921. │ │
  922. │終 │
  923. │ │
  924. │ │
  925. │ │
  926. │ │
  927. │ │
  928. │ │
  929. │ │
  930. │ │
  931. │ │
  932. └────────────────────┘
  933. ";
  934. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  935. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  936. verticalView.Text = $"最初_の行二行目";
  937. Application.Top.Draw ();
  938. Assert.True (horizontalView.AutoSize);
  939. Assert.True (verticalView.AutoSize);
  940. // height was initialized with 8 and can only grow or keep initial value
  941. Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame);
  942. Assert.Equal ("Absolute(0)", verticalView.X.ToString ());
  943. Assert.Equal ("Absolute(3)", verticalView.Y.ToString ());
  944. Assert.Equal ("Absolute(2)", verticalView.Width.ToString ());
  945. Assert.Equal ("Absolute(8)", verticalView.Height.ToString ());
  946. expected = @"
  947. ┌────────────────────┐
  948. │Finish 終 │
  949. │ │
  950. │ │
  951. │最 │
  952. │初 │
  953. │の │
  954. │行 │
  955. │二 │
  956. │行 │
  957. │目 │
  958. │ │
  959. │ │
  960. │ │
  961. │ │
  962. │ │
  963. │ │
  964. │ │
  965. │ │
  966. │ │
  967. │ │
  968. └────────────────────┘
  969. ";
  970. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  971. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  972. Application.End (rs);
  973. }
  974. [Fact, AutoInitShutdown]
  975. public void AutoSize_Stays_True_Center_HotKeySpecifier ()
  976. {
  977. var label = new Label () {
  978. X = Pos.Center (),
  979. Y = Pos.Center (),
  980. Text = "Say Hello 你"
  981. };
  982. var win = new Window () {
  983. Width = Dim.Fill (),
  984. Height = Dim.Fill (),
  985. Title = "Test Demo 你"
  986. };
  987. win.Add (label);
  988. Application.Top.Add (win);
  989. Assert.True (label.AutoSize);
  990. var rs = Application.Begin (Application.Top);
  991. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  992. var expected = @$"
  993. ┌┤Test Demo 你├──────────────┐
  994. │ │
  995. │ Say Hello 你 │
  996. │ │
  997. └────────────────────────────┘
  998. ";
  999. TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  1000. Assert.True (label.AutoSize);
  1001. label.Text = "Say Hello 你 changed";
  1002. Assert.True (label.AutoSize);
  1003. Application.Refresh ();
  1004. expected = @"
  1005. ┌┤Test Demo 你├──────────────┐
  1006. │ │
  1007. │ Say Hello 你 changed │
  1008. │ │
  1009. └────────────────────────────┘
  1010. ";
  1011. TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  1012. Application.End (rs);
  1013. }
  1014. [Fact, AutoInitShutdown]
  1015. public void AutoSize_False_Equal_Before_And_After_IsInitialized_With_Differents_Orders ()
  1016. {
  1017. var view1 = new View () { Text = "Say Hello view1 你", AutoSize = false, Width = 10, Height = 5 };
  1018. var view2 = new View () { Text = "Say Hello view2 你", Width = 10, Height = 5, AutoSize = false };
  1019. var view3 = new View () { AutoSize = false, Width = 10, Height = 5, Text = "Say Hello view3 你" };
  1020. var view4 = new View () {
  1021. Text = "Say Hello view4 你",
  1022. AutoSize = false,
  1023. Width = 10,
  1024. Height = 5,
  1025. TextDirection = TextDirection.TopBottom_LeftRight
  1026. };
  1027. var view5 = new View () {
  1028. Text = "Say Hello view5 你",
  1029. Width = 10,
  1030. Height = 5,
  1031. AutoSize = false,
  1032. TextDirection = TextDirection.TopBottom_LeftRight
  1033. };
  1034. var view6 = new View () {
  1035. AutoSize = false,
  1036. Width = 10,
  1037. Height = 5,
  1038. TextDirection = TextDirection.TopBottom_LeftRight,
  1039. Text = "Say Hello view6 你",
  1040. };
  1041. Application.Top.Add (view1, view2, view3, view4, view5, view6);
  1042. Assert.False (view1.IsInitialized);
  1043. Assert.False (view2.IsInitialized);
  1044. Assert.False (view3.IsInitialized);
  1045. Assert.False (view4.IsInitialized);
  1046. Assert.False (view5.IsInitialized);
  1047. Assert.False (view1.AutoSize);
  1048. Assert.Equal (new Rect (0, 0, 10, 5), view1.Frame);
  1049. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1050. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1051. Assert.False (view2.AutoSize);
  1052. Assert.Equal (new Rect (0, 0, 10, 5), view2.Frame);
  1053. Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1054. Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1055. Assert.False (view3.AutoSize);
  1056. Assert.Equal (new Rect (0, 0, 10, 5), view3.Frame);
  1057. Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1058. Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1059. Assert.False (view4.AutoSize);
  1060. Assert.Equal (new Rect (0, 0, 10, 5), view4.Frame);
  1061. Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1062. Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1063. Assert.False (view5.AutoSize);
  1064. Assert.Equal (new Rect (0, 0, 10, 5), view5.Frame);
  1065. Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1066. Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1067. Assert.False (view6.AutoSize);
  1068. Assert.Equal (new Rect (0, 0, 10, 5), view6.Frame);
  1069. Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1070. Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1071. var rs = Application.Begin (Application.Top);
  1072. Assert.True (view1.IsInitialized);
  1073. Assert.True (view2.IsInitialized);
  1074. Assert.True (view3.IsInitialized);
  1075. Assert.True (view4.IsInitialized);
  1076. Assert.True (view5.IsInitialized);
  1077. Assert.False (view1.AutoSize);
  1078. Assert.Equal (new Rect (0, 0, 10, 5), view1.Frame);
  1079. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1080. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1081. Assert.False (view2.AutoSize);
  1082. Assert.Equal (new Rect (0, 0, 10, 5), view2.Frame);
  1083. Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1084. Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1085. Assert.False (view3.AutoSize);
  1086. Assert.Equal (new Rect (0, 0, 10, 5), view3.Frame);
  1087. Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1088. Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1089. Assert.False (view4.AutoSize);
  1090. Assert.Equal (new Rect (0, 0, 10, 5), view4.Frame);
  1091. Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1092. Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1093. Assert.False (view5.AutoSize);
  1094. Assert.Equal (new Rect (0, 0, 10, 5), view5.Frame);
  1095. Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1096. Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1097. Assert.False (view6.AutoSize);
  1098. Assert.Equal (new Rect (0, 0, 10, 5), view6.Frame);
  1099. Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1100. Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1101. Application.End (rs);
  1102. }
  1103. [Fact, AutoInitShutdown]
  1104. public void AutoSize_True_Equal_Before_And_After_IsInitialized_With_Different_Orders ()
  1105. {
  1106. var view1 = new View () { Text = "Say Hello view1 你", AutoSize = true, Width = 10, Height = 5 };
  1107. var view2 = new View () { Text = "Say Hello view2 你", Width = 10, Height = 5, AutoSize = true };
  1108. var view3 = new View () { AutoSize = true, Width = 10, Height = 5, Text = "Say Hello view3 你" };
  1109. var view4 = new View () {
  1110. Text = "Say Hello view4 你",
  1111. AutoSize = true,
  1112. Width = 10,
  1113. Height = 5,
  1114. TextDirection = TextDirection.TopBottom_LeftRight
  1115. };
  1116. var view5 = new View () {
  1117. Text = "Say Hello view5 你",
  1118. Width = 10,
  1119. Height = 5,
  1120. AutoSize = true,
  1121. TextDirection = TextDirection.TopBottom_LeftRight
  1122. };
  1123. var view6 = new View () {
  1124. AutoSize = true,
  1125. Width = 10,
  1126. Height = 5,
  1127. TextDirection = TextDirection.TopBottom_LeftRight,
  1128. Text = "Say Hello view6 你",
  1129. };
  1130. Application.Top.Add (view1, view2, view3, view4, view5, view6);
  1131. Assert.False (view1.IsInitialized);
  1132. Assert.False (view2.IsInitialized);
  1133. Assert.False (view3.IsInitialized);
  1134. Assert.False (view4.IsInitialized);
  1135. Assert.False (view5.IsInitialized);
  1136. Assert.True (view1.AutoSize);
  1137. Assert.Equal (new Rect (0, 0, 18, 5), view1.Frame);
  1138. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1139. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1140. Assert.True (view2.AutoSize);
  1141. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  1142. //Assert.Equal (new Rect (0, 0, 18, 5), view2.Frame);
  1143. //Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1144. //Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1145. //Assert.True (view3.AutoSize);
  1146. //Assert.Equal (new Rect (0, 0, 18, 5), view3.Frame);
  1147. //Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1148. //Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1149. //Assert.True (view4.AutoSize);
  1150. //Assert.Equal (new Rect (0, 0, 10, 17), view4.Frame);
  1151. //Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1152. //Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1153. //Assert.True (view5.AutoSize);
  1154. //Assert.Equal (new Rect (0, 0, 10, 17), view5.Frame);
  1155. //Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1156. //Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1157. //Assert.True (view6.AutoSize);
  1158. //Assert.Equal (new Rect (0, 0, 10, 17), view6.Frame);
  1159. //Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1160. //Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1161. var rs = Application.Begin (Application.Top);
  1162. Assert.True (view1.IsInitialized);
  1163. Assert.True (view2.IsInitialized);
  1164. Assert.True (view3.IsInitialized);
  1165. Assert.True (view4.IsInitialized);
  1166. Assert.True (view5.IsInitialized);
  1167. Assert.True (view1.AutoSize);
  1168. Assert.Equal (new Rect (0, 0, 18, 5), view1.Frame);
  1169. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1170. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1171. Assert.True (view2.AutoSize);
  1172. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  1173. //Assert.Equal (new Rect (0, 0, 18, 5), view2.Frame);
  1174. //Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1175. //Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1176. //Assert.True (view3.AutoSize);
  1177. //Assert.Equal (new Rect (0, 0, 18, 5), view3.Frame);
  1178. //Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1179. //Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1180. //Assert.True (view4.AutoSize);
  1181. //Assert.Equal (new Rect (0, 0, 10, 17), view4.Frame);
  1182. //Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1183. //Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1184. //Assert.True (view5.AutoSize);
  1185. //Assert.Equal (new Rect (0, 0, 10, 17), view5.Frame);
  1186. //Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1187. //Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1188. //Assert.True (view6.AutoSize);
  1189. //Assert.Equal (new Rect (0, 0, 10, 17), view6.Frame);
  1190. //Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1191. //Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1192. Application.End (rs);
  1193. }
  1194. [Fact, AutoInitShutdown]
  1195. public void Setting_Frame_Dont_Respect_AutoSize_True_On_Layout_Absolute ()
  1196. {
  1197. var view1 = new View (new Rect (0, 0, 10, 0)) { Text = "Say Hello view1 你", AutoSize = true };
  1198. var view2 = new View (new Rect (0, 0, 0, 10)) {
  1199. Text = "Say Hello view2 你",
  1200. AutoSize = true,
  1201. TextDirection = TextDirection.TopBottom_LeftRight
  1202. };
  1203. Application.Top.Add (view1, view2);
  1204. var rs = Application.Begin (Application.Top);
  1205. Assert.True (view1.AutoSize);
  1206. Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle);
  1207. Assert.Equal (new Rect (0, 0, 18, 1), view1.Frame);
  1208. Assert.Equal ("Absolute(0)", view1.X.ToString ());
  1209. Assert.Equal ("Absolute(0)", view1.Y.ToString ());
  1210. Assert.Equal ("Absolute(18)", view1.Width.ToString ());
  1211. Assert.Equal ("Absolute(1)", view1.Height.ToString ());
  1212. Assert.True (view2.AutoSize);
  1213. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  1214. //Assert.Equal (LayoutStyle.Absolute, view2.LayoutStyle);
  1215. //Assert.Equal (new Rect (0, 0, 2, 17), view2.Frame);
  1216. //Assert.Equal ("Absolute(0)", view2.X.ToString ());
  1217. //Assert.Equal ("Absolute(0)", view2.Y.ToString ());
  1218. //Assert.Equal ("Absolute(2)", view2.Width.ToString ());
  1219. //Assert.Equal ("Absolute(17)", view2.Height.ToString ());
  1220. view1.Frame = new Rect (0, 0, 25, 4);
  1221. bool firstIteration = false;
  1222. Application.RunIteration (ref rs, ref firstIteration);
  1223. Assert.True (view1.AutoSize);
  1224. Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle);
  1225. Assert.Equal (new Rect (0, 0, 25, 4), view1.Frame);
  1226. Assert.Equal ("Absolute(0)", view1.X.ToString ());
  1227. Assert.Equal ("Absolute(0)", view1.Y.ToString ());
  1228. Assert.Equal ("Absolute(18)", view1.Width.ToString ());
  1229. Assert.Equal ("Absolute(1)", view1.Height.ToString ());
  1230. view2.Frame = new Rect (0, 0, 1, 25);
  1231. Application.RunIteration (ref rs, ref firstIteration);
  1232. Assert.True (view2.AutoSize);
  1233. Assert.Equal (LayoutStyle.Absolute, view2.LayoutStyle);
  1234. Assert.Equal (new Rect (0, 0, 1, 25), view2.Frame);
  1235. Assert.Equal ("Absolute(0)", view2.X.ToString ());
  1236. Assert.Equal ("Absolute(0)", view2.Y.ToString ());
  1237. // BUGBUG: v2 - Autosize is broken when setting Width/Height AutoSize. Disabling test for now.
  1238. //Assert.Equal ("Absolute(2)", view2.Width.ToString ());
  1239. //Assert.Equal ("Absolute(17)", view2.Height.ToString ());
  1240. Application.End (rs);
  1241. }
  1242. [Fact, AutoInitShutdown]
  1243. public void Pos_Dim_Are_Null_If_Not_Initialized_On_Constructor_IsAdded_False ()
  1244. {
  1245. var top = Application.Top;
  1246. var view1 = new View ();
  1247. Assert.False (view1.IsAdded);
  1248. Assert.Null (view1.X);
  1249. Assert.Null (view1.Y);
  1250. Assert.Null (view1.Width);
  1251. Assert.Null (view1.Height);
  1252. top.Add (view1);
  1253. Assert.True (view1.IsAdded);
  1254. Assert.Equal ("Absolute(0)", view1.X.ToString ());
  1255. Assert.Equal ("Absolute(0)", view1.Y.ToString ());
  1256. Assert.Equal ("Absolute(0)", view1.Width.ToString ());
  1257. Assert.Equal ("Absolute(0)", view1.Height.ToString ());
  1258. var view2 = new View () {
  1259. X = Pos.Center (),
  1260. Y = Pos.Center (),
  1261. Width = Dim.Fill (),
  1262. Height = Dim.Fill ()
  1263. };
  1264. Assert.False (view2.IsAdded);
  1265. Assert.Equal ("Center", view2.X.ToString ());
  1266. Assert.Equal ("Center", view2.Y.ToString ());
  1267. Assert.Equal ("Fill(0)", view2.Width.ToString ());
  1268. Assert.Equal ("Fill(0)", view2.Height.ToString ());
  1269. top.Add (view2);
  1270. Assert.True (view2.IsAdded);
  1271. Assert.Equal ("Center", view2.X.ToString ());
  1272. Assert.Equal ("Center", view2.Y.ToString ());
  1273. Assert.Equal ("Fill(0)", view2.Width.ToString ());
  1274. Assert.Equal ("Fill(0)", view2.Height.ToString ());
  1275. }
  1276. [Fact, TestRespondersDisposed]
  1277. public void SetRelativeLayout_PosCombine_Center_Plus_Absolute ()
  1278. {
  1279. var superView = new View () {
  1280. AutoSize = false,
  1281. Width = 10,
  1282. Height = 10
  1283. };
  1284. var testView = new View () {
  1285. AutoSize = false,
  1286. X = Pos.Center (),
  1287. Y = Pos.Center (),
  1288. Width = 1,
  1289. Height = 1
  1290. };
  1291. superView.Add (testView);
  1292. testView.SetRelativeLayout (superView.Frame);
  1293. Assert.Equal (4, testView.Frame.X);
  1294. Assert.Equal (4, testView.Frame.Y);
  1295. testView = new View () {
  1296. AutoSize = false,
  1297. X = Pos.Center () + 1,
  1298. Y = Pos.Center () + 1,
  1299. Width = 1,
  1300. Height = 1
  1301. };
  1302. superView.Add (testView);
  1303. testView.SetRelativeLayout (superView.Frame);
  1304. Assert.Equal (5, testView.Frame.X);
  1305. Assert.Equal (5, testView.Frame.Y);
  1306. testView = new View () {
  1307. AutoSize = false,
  1308. X = 1 + Pos.Center (),
  1309. Y = 1 + Pos.Center (),
  1310. Width = 1,
  1311. Height = 1
  1312. };
  1313. superView.Add (testView);
  1314. testView.SetRelativeLayout (superView.Frame);
  1315. Assert.Equal (5, testView.Frame.X);
  1316. Assert.Equal (5, testView.Frame.Y);
  1317. testView = new View () {
  1318. AutoSize = false,
  1319. X = 1 + Pos.Percent (50),
  1320. Y = Pos.Percent (50) + 1,
  1321. Width = 1,
  1322. Height = 1
  1323. };
  1324. superView.Add (testView);
  1325. testView.SetRelativeLayout (superView.Frame);
  1326. Assert.Equal (6, testView.Frame.X);
  1327. Assert.Equal (6, testView.Frame.Y);
  1328. testView = new View () {
  1329. AutoSize = false,
  1330. X = Pos.Percent (10) + Pos.Percent (40),
  1331. Y = Pos.Percent (10) + Pos.Percent (40),
  1332. Width = 1,
  1333. Height = 1
  1334. };
  1335. superView.Add (testView);
  1336. testView.SetRelativeLayout (superView.Frame);
  1337. Assert.Equal (5, testView.Frame.X);
  1338. Assert.Equal (5, testView.Frame.Y);
  1339. testView = new View () {
  1340. AutoSize = false,
  1341. X = 1 + Pos.Percent (10) + Pos.Percent (40) - 1,
  1342. Y = 5 + Pos.Percent (10) + Pos.Percent (40) - 5,
  1343. Width = 1,
  1344. Height = 1
  1345. };
  1346. superView.Add (testView);
  1347. testView.SetRelativeLayout (superView.Frame);
  1348. Assert.Equal (5, testView.Frame.X);
  1349. Assert.Equal (5, testView.Frame.Y);
  1350. testView = new View () {
  1351. AutoSize = false,
  1352. X = Pos.Left (testView),
  1353. Y = Pos.Left (testView),
  1354. Width = 1,
  1355. Height = 1
  1356. };
  1357. superView.Add (testView);
  1358. testView.SetRelativeLayout (superView.Frame);
  1359. Assert.Equal (5, testView.Frame.X);
  1360. Assert.Equal (5, testView.Frame.Y);
  1361. testView = new View () {
  1362. AutoSize = false,
  1363. X = 1 + Pos.Left (testView),
  1364. Y = Pos.Top (testView) + 1,
  1365. Width = 1,
  1366. Height = 1
  1367. };
  1368. superView.Add (testView);
  1369. testView.SetRelativeLayout (superView.Frame);
  1370. Assert.Equal (6, testView.Frame.X);
  1371. Assert.Equal (6, testView.Frame.Y);
  1372. superView.Dispose ();
  1373. }
  1374. [Theory, AutoInitShutdown]
  1375. [InlineData (1)]
  1376. [InlineData (2)]
  1377. [InlineData (3)]
  1378. [InlineData (4)]
  1379. [InlineData (5)]
  1380. [InlineData (6)]
  1381. [InlineData (7)]
  1382. [InlineData (8)]
  1383. [InlineData (9)]
  1384. [InlineData (10)]
  1385. public void Dim_CenteredSubView_85_Percent_Height (int height)
  1386. {
  1387. var win = new Window () {
  1388. Width = Dim.Fill (),
  1389. Height = Dim.Fill ()
  1390. };
  1391. var subview = new Window () {
  1392. X = Pos.Center (),
  1393. Y = Pos.Center (),
  1394. Width = Dim.Percent (85),
  1395. Height = Dim.Percent (85)
  1396. };
  1397. win.Add (subview);
  1398. var rs = Application.Begin (win);
  1399. bool firstIteration = false;
  1400. ((FakeDriver)Application.Driver).SetBufferSize (20, height);
  1401. Application.RunIteration (ref rs, ref firstIteration);
  1402. var expected = string.Empty;
  1403. switch (height) {
  1404. case 1:
  1405. //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
  1406. expected = @"
  1407. ────────────────────";
  1408. break;
  1409. case 2:
  1410. //Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame);
  1411. expected = @"
  1412. ┌──────────────────┐
  1413. └──────────────────┘
  1414. ";
  1415. break;
  1416. case 3:
  1417. //Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame);
  1418. expected = @"
  1419. ┌──────────────────┐
  1420. │ │
  1421. └──────────────────┘
  1422. ";
  1423. break;
  1424. case 4:
  1425. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1426. expected = @"
  1427. ┌──────────────────┐
  1428. │ ─────────────── │
  1429. │ │
  1430. └──────────────────┘";
  1431. break;
  1432. case 5:
  1433. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1434. expected = @"
  1435. ┌──────────────────┐
  1436. │ ┌─────────────┐ │
  1437. │ └─────────────┘ │
  1438. │ │
  1439. └──────────────────┘";
  1440. break;
  1441. case 6:
  1442. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1443. expected = @"
  1444. ┌──────────────────┐
  1445. │ ┌─────────────┐ │
  1446. │ │ │ │
  1447. │ └─────────────┘ │
  1448. │ │
  1449. └──────────────────┘";
  1450. break;
  1451. case 7:
  1452. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1453. expected = @"
  1454. ┌──────────────────┐
  1455. │ ┌─────────────┐ │
  1456. │ │ │ │
  1457. │ │ │ │
  1458. │ └─────────────┘ │
  1459. │ │
  1460. └──────────────────┘";
  1461. break;
  1462. case 8:
  1463. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1464. expected = @"
  1465. ┌──────────────────┐
  1466. │ ┌─────────────┐ │
  1467. │ │ │ │
  1468. │ │ │ │
  1469. │ │ │ │
  1470. │ └─────────────┘ │
  1471. │ │
  1472. └──────────────────┘";
  1473. break;
  1474. case 9:
  1475. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1476. expected = @"
  1477. ┌──────────────────┐
  1478. │ │
  1479. │ ┌─────────────┐ │
  1480. │ │ │ │
  1481. │ │ │ │
  1482. │ │ │ │
  1483. │ └─────────────┘ │
  1484. │ │
  1485. └──────────────────┘";
  1486. break;
  1487. case 10:
  1488. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  1489. expected = @"
  1490. ┌──────────────────┐
  1491. │ │
  1492. │ ┌─────────────┐ │
  1493. │ │ │ │
  1494. │ │ │ │
  1495. │ │ │ │
  1496. │ │ │ │
  1497. │ └─────────────┘ │
  1498. │ │
  1499. └──────────────────┘";
  1500. break;
  1501. }
  1502. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  1503. Application.End (rs);
  1504. }
  1505. [Theory, AutoInitShutdown]
  1506. [InlineData (1)]
  1507. [InlineData (2)]
  1508. [InlineData (3)]
  1509. [InlineData (4)]
  1510. [InlineData (5)]
  1511. [InlineData (6)]
  1512. [InlineData (7)]
  1513. [InlineData (8)]
  1514. [InlineData (9)]
  1515. [InlineData (10)]
  1516. public void Dim_CenteredSubView_85_Percent_Width (int width)
  1517. {
  1518. var win = new Window () {
  1519. Width = Dim.Fill (),
  1520. Height = Dim.Fill ()
  1521. };
  1522. var subview = new Window () {
  1523. X = Pos.Center (),
  1524. Y = Pos.Center (),
  1525. Width = Dim.Percent (85),
  1526. Height = Dim.Percent (85)
  1527. };
  1528. win.Add (subview);
  1529. var rs = Application.Begin (win);
  1530. bool firstIteration = false;
  1531. ((FakeDriver)Application.Driver).SetBufferSize (width, 7);
  1532. Application.RunIteration (ref rs, ref firstIteration);
  1533. var expected = string.Empty;
  1534. switch (width) {
  1535. case 1:
  1536. Assert.Equal (new Rect (0, 0, 0, 4), subview.Frame);
  1537. expected = @"
  1538. │";
  1539. break;
  1540. case 2:
  1541. Assert.Equal (new Rect (0, 0, 0, 4), subview.Frame);
  1542. expected = @"
  1543. ┌┐
  1544. ││
  1545. ││
  1546. ││
  1547. ││
  1548. ││
  1549. └┘";
  1550. break;
  1551. case 3:
  1552. Assert.Equal (new Rect (0, 0, 0, 4), subview.Frame);
  1553. expected = @"
  1554. ┌─┐
  1555. │ │
  1556. │ │
  1557. │ │
  1558. │ │
  1559. │ │
  1560. └─┘";
  1561. break;
  1562. case 4:
  1563. Assert.Equal (new Rect (0, 0, 1, 4), subview.Frame);
  1564. expected = @"
  1565. ┌──┐
  1566. ││ │
  1567. ││ │
  1568. ││ │
  1569. ││ │
  1570. │ │
  1571. └──┘";
  1572. break;
  1573. case 5:
  1574. Assert.Equal (new Rect (0, 0, 2, 4), subview.Frame);
  1575. expected = @"
  1576. ┌───┐
  1577. │┌┐ │
  1578. │││ │
  1579. │││ │
  1580. │└┘ │
  1581. │ │
  1582. └───┘";
  1583. break;
  1584. case 6:
  1585. Assert.Equal (new Rect (0, 0, 3, 4), subview.Frame);
  1586. expected = @"
  1587. ┌────┐
  1588. │┌─┐ │
  1589. ││ │ │
  1590. ││ │ │
  1591. │└─┘ │
  1592. │ │
  1593. └────┘";
  1594. break;
  1595. case 7:
  1596. Assert.Equal (new Rect (0, 0, 4, 4), subview.Frame);
  1597. expected = @"
  1598. ┌─────┐
  1599. │┌──┐ │
  1600. ││ │ │
  1601. ││ │ │
  1602. │└──┘ │
  1603. │ │
  1604. └─────┘";
  1605. break;
  1606. case 8:
  1607. Assert.Equal (new Rect (0, 0, 5, 4), subview.Frame);
  1608. expected = @"
  1609. ┌──────┐
  1610. │┌───┐ │
  1611. ││ │ │
  1612. ││ │ │
  1613. │└───┘ │
  1614. │ │
  1615. └──────┘";
  1616. break;
  1617. case 9:
  1618. Assert.Equal (new Rect (1, 0, 5, 4), subview.Frame);
  1619. expected = @"
  1620. ┌───────┐
  1621. │ ┌───┐ │
  1622. │ │ │ │
  1623. │ │ │ │
  1624. │ └───┘ │
  1625. │ │
  1626. └───────┘";
  1627. break;
  1628. case 10:
  1629. Assert.Equal (new Rect (1, 0, 6, 4), subview.Frame);
  1630. expected = @"
  1631. ┌────────┐
  1632. │ ┌────┐ │
  1633. │ │ │ │
  1634. │ │ │ │
  1635. │ └────┘ │
  1636. │ │
  1637. └────────┘";
  1638. break;
  1639. }
  1640. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  1641. Application.End (rs);
  1642. }
  1643. [Fact, AutoInitShutdown]
  1644. public void PosCombine_DimCombine_View_With_SubViews ()
  1645. {
  1646. var clicked = false;
  1647. var top = Application.Top;
  1648. var win1 = new Window () { Id = "win1", Width = 20, Height = 10 };
  1649. var label = new Label ("[ ok ]");
  1650. var win2 = new Window () { Id = "win2", Y = Pos.Bottom (label) + 1, Width = 10, Height = 3 };
  1651. var view1 = new View () { Id = "view1", Width = Dim.Fill (), Height = 1, CanFocus = true };
  1652. view1.MouseClick += (sender, e) => clicked = true;
  1653. var view2 = new View () { Id = "view2", Width = Dim.Fill (1), Height = 1, CanFocus = true };
  1654. view1.Add (view2);
  1655. win2.Add (view1);
  1656. win1.Add (label, win2);
  1657. top.Add (win1);
  1658. var rs = Application.Begin (top);
  1659. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1660. ┌──────────────────┐
  1661. │[ ok ] │
  1662. │ │
  1663. │┌────────┐ │
  1664. ││ │ │
  1665. │└────────┘ │
  1666. │ │
  1667. │ │
  1668. │ │
  1669. └──────────────────┘", output);
  1670. Assert.Equal (new Rect (0, 0, 80, 25), top.Frame);
  1671. Assert.Equal (new Rect (0, 0, 6, 1), label.Frame);
  1672. Assert.Equal (new Rect (0, 0, 20, 10), win1.Frame);
  1673. Assert.Equal (new Rect (0, 2, 10, 3), win2.Frame);
  1674. Assert.Equal (new Rect (0, 0, 8, 1), view1.Frame);
  1675. Assert.Equal (new Rect (0, 0, 7, 1), view2.Frame);
  1676. var foundView = View.FindDeepestView (top, 9, 4, out int rx, out int ry);
  1677. Assert.Equal (foundView, view1);
  1678. Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () {
  1679. X = 9,
  1680. Y = 4,
  1681. Flags = MouseFlags.Button1Clicked
  1682. }));
  1683. Assert.True (clicked);
  1684. Application.End (rs);
  1685. }
  1686. [Fact, TestRespondersDisposed]
  1687. public void Draw_Vertical_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
  1688. {
  1689. Application.Init (new FakeDriver ());
  1690. var top = Application.Top;
  1691. var view = new View ("view") {
  1692. Y = -2,
  1693. Height = 10,
  1694. TextDirection = TextDirection.TopBottom_LeftRight
  1695. };
  1696. top.Add (view);
  1697. Application.Iteration += (s, a) => {
  1698. Assert.Equal (-2, view.Y);
  1699. Application.RequestStop ();
  1700. };
  1701. try {
  1702. Application.Run ();
  1703. } catch (IndexOutOfRangeException ex) {
  1704. // After the fix this exception will not be caught.
  1705. Assert.IsType<IndexOutOfRangeException> (ex);
  1706. }
  1707. // Shutdown must be called to safely clean up Application if Init has been called
  1708. Application.Shutdown ();
  1709. }
  1710. [Fact, TestRespondersDisposed]
  1711. public void Draw_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
  1712. {
  1713. Application.Init (new FakeDriver ());
  1714. var top = Application.Top;
  1715. var view = new View ("view") { X = -2 };
  1716. top.Add (view);
  1717. Application.Iteration += (s, a) => {
  1718. Assert.Equal (-2, view.X);
  1719. Application.RequestStop ();
  1720. };
  1721. try {
  1722. Application.Run ();
  1723. } catch (IndexOutOfRangeException ex) {
  1724. // After the fix this exception will not be caught.
  1725. Assert.IsType<IndexOutOfRangeException> (ex);
  1726. }
  1727. // Shutdown must be called to safely clean up Application if Init has been called
  1728. Application.Shutdown ();
  1729. }
  1730. }
  1731. }