LayoutTests.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413
  1. using NStack;
  2. using System;
  3. using System.Collections.Generic;
  4. using Terminal.Gui.Graphs;
  5. using Xunit;
  6. using Xunit.Abstractions;
  7. //using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
  8. // Alias Console to MockConsole so we don't accidentally use Console
  9. using Console = Terminal.Gui.FakeConsole;
  10. namespace Terminal.Gui.CoreTests {
  11. public class LayoutTests {
  12. readonly ITestOutputHelper output;
  13. public LayoutTests (ITestOutputHelper output)
  14. {
  15. this.output = output;
  16. }
  17. [Fact]
  18. public void View_With_No_Difference_Between_An_Object_Initializer_And_A_Constructor ()
  19. {
  20. // Object Initializer
  21. var view = new View () {
  22. X = 1,
  23. Y = 2,
  24. Width = 3,
  25. Height = 4
  26. };
  27. Assert.Equal (1, view.X);
  28. Assert.Equal (2, view.Y);
  29. Assert.Equal (3, view.Width);
  30. Assert.Equal (4, view.Height);
  31. Assert.False (view.Frame.IsEmpty);
  32. Assert.Equal (new Rect (1, 2, 3, 4), view.Frame);
  33. Assert.False (view.Bounds.IsEmpty);
  34. Assert.Equal (new Rect (0, 0, 3, 4), view.Bounds);
  35. view.LayoutSubviews ();
  36. Assert.Equal (1, view.X);
  37. Assert.Equal (2, view.Y);
  38. Assert.Equal (3, view.Width);
  39. Assert.Equal (4, view.Height);
  40. Assert.False (view.Frame.IsEmpty);
  41. Assert.False (view.Bounds.IsEmpty);
  42. // Default Constructor
  43. view = new View ();
  44. Assert.Null (view.X);
  45. Assert.Null (view.Y);
  46. Assert.Null (view.Width);
  47. Assert.Null (view.Height);
  48. Assert.True (view.Frame.IsEmpty);
  49. Assert.True (view.Bounds.IsEmpty);
  50. // Constructor
  51. view = new View (1, 2, "");
  52. Assert.Null (view.X);
  53. Assert.Null (view.Y);
  54. Assert.Null (view.Width);
  55. Assert.Null (view.Height);
  56. Assert.False (view.Frame.IsEmpty);
  57. Assert.True (view.Bounds.IsEmpty);
  58. // Default Constructor and post assignment equivalent to Object Initializer
  59. view = new View ();
  60. view.X = 1;
  61. view.Y = 2;
  62. view.Width = 3;
  63. view.Height = 4;
  64. Assert.Equal (1, view.X);
  65. Assert.Equal (2, view.Y);
  66. Assert.Equal (3, view.Width);
  67. Assert.Equal (4, view.Height);
  68. Assert.False (view.Frame.IsEmpty);
  69. Assert.Equal (new Rect (1, 2, 3, 4), view.Frame);
  70. Assert.False (view.Bounds.IsEmpty);
  71. Assert.Equal (new Rect (0, 0, 3, 4), view.Bounds);
  72. }
  73. [Fact]
  74. public void FocusNearestView_Ensure_Focus_Ordered ()
  75. {
  76. var top = new Toplevel ();
  77. var win = new Window ();
  78. var winSubview = new View ("WindowSubview") {
  79. CanFocus = true
  80. };
  81. win.Add (winSubview);
  82. top.Add (win);
  83. var frm = new FrameView ();
  84. var frmSubview = new View ("FrameSubview") {
  85. CanFocus = true
  86. };
  87. frm.Add (frmSubview);
  88. top.Add (frm);
  89. top.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  90. Assert.Equal ($"WindowSubview", top.MostFocused.Text);
  91. top.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  92. Assert.Equal ("FrameSubview", top.MostFocused.Text);
  93. top.ProcessKey (new KeyEvent (Key.Tab, new KeyModifiers ()));
  94. Assert.Equal ($"WindowSubview", top.MostFocused.Text);
  95. top.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  96. Assert.Equal ("FrameSubview", top.MostFocused.Text);
  97. top.ProcessKey (new KeyEvent (Key.BackTab | Key.ShiftMask, new KeyModifiers ()));
  98. Assert.Equal ($"WindowSubview", top.MostFocused.Text);
  99. }
  100. [Fact]
  101. public void KeyPress_Handled_To_True_Prevents_Changes ()
  102. {
  103. Application.Init (new FakeDriver ());
  104. Console.MockKeyPresses.Push (new ConsoleKeyInfo ('N', ConsoleKey.N, false, false, false));
  105. var top = Application.Top;
  106. var text = new TextField ("");
  107. text.KeyPress += (e) => {
  108. e.Handled = true;
  109. Assert.True (e.Handled);
  110. Assert.Equal (Key.N, e.KeyEvent.Key);
  111. };
  112. top.Add (text);
  113. Application.Iteration += () => {
  114. Console.MockKeyPresses.Push (new ConsoleKeyInfo ('N', ConsoleKey.N, false, false, false));
  115. Assert.Equal ("", text.Text);
  116. Application.RequestStop ();
  117. };
  118. Application.Run ();
  119. // Shutdown must be called to safely clean up Application if Init has been called
  120. Application.Shutdown ();
  121. }
  122. [Fact, AutoInitShutdown]
  123. public void SetWidth_CanSetWidth_ForceValidatePosDim ()
  124. {
  125. var top = new View () {
  126. X = 0,
  127. Y = 0,
  128. Width = 80,
  129. };
  130. var v = new View () {
  131. Width = Dim.Fill (),
  132. ForceValidatePosDim = true
  133. };
  134. top.Add (v);
  135. Assert.False (v.SetWidth (70, out int rWidth));
  136. Assert.Equal (70, rWidth);
  137. v.Width = Dim.Fill (1);
  138. Assert.False (v.SetWidth (70, out rWidth));
  139. Assert.Equal (69, rWidth);
  140. v.Width = null;
  141. Assert.True (v.SetWidth (70, out rWidth));
  142. Assert.Equal (70, rWidth);
  143. Assert.False (v.IsInitialized);
  144. Application.Top.Add (top);
  145. Application.Begin (Application.Top);
  146. Assert.True (v.IsInitialized);
  147. v.Width = Dim.Fill (1);
  148. Assert.Throws<ArgumentException> (() => v.Width = 75);
  149. v.LayoutStyle = LayoutStyle.Absolute;
  150. v.Width = 75;
  151. Assert.True (v.SetWidth (60, out rWidth));
  152. Assert.Equal (60, rWidth);
  153. }
  154. [Fact, AutoInitShutdown]
  155. public void SetHeight_CanSetHeight_ForceValidatePosDim ()
  156. {
  157. var top = new View () {
  158. X = 0,
  159. Y = 0,
  160. Height = 20
  161. };
  162. var v = new View () {
  163. Height = Dim.Fill (),
  164. ForceValidatePosDim = true
  165. };
  166. top.Add (v);
  167. Assert.False (v.SetHeight (10, out int rHeight));
  168. Assert.Equal (10, rHeight);
  169. v.Height = Dim.Fill (1);
  170. Assert.False (v.SetHeight (10, out rHeight));
  171. Assert.Equal (9, rHeight);
  172. v.Height = null;
  173. Assert.True (v.SetHeight (10, out rHeight));
  174. Assert.Equal (10, rHeight);
  175. Assert.False (v.IsInitialized);
  176. Application.Top.Add (top);
  177. Application.Begin (Application.Top);
  178. Assert.True (v.IsInitialized);
  179. v.Height = Dim.Fill (1);
  180. Assert.Throws<ArgumentException> (() => v.Height = 15);
  181. v.LayoutStyle = LayoutStyle.Absolute;
  182. v.Height = 15;
  183. Assert.True (v.SetHeight (5, out rHeight));
  184. Assert.Equal (5, rHeight);
  185. }
  186. [Fact]
  187. public void GetCurrentWidth_CanSetWidth ()
  188. {
  189. var top = new View () {
  190. X = 0,
  191. Y = 0,
  192. Width = 80,
  193. };
  194. var v = new View () {
  195. Width = Dim.Fill ()
  196. };
  197. top.Add (v);
  198. Assert.False (v.AutoSize);
  199. Assert.True (v.GetCurrentWidth (out int cWidth));
  200. Assert.Equal (80, cWidth);
  201. v.Width = Dim.Fill (1);
  202. Assert.True (v.GetCurrentWidth (out cWidth));
  203. Assert.Equal (79, cWidth);
  204. v.AutoSize = true;
  205. Assert.True (v.GetCurrentWidth (out cWidth));
  206. Assert.Equal (79, cWidth);
  207. }
  208. [Fact]
  209. public void GetCurrentHeight_CanSetHeight ()
  210. {
  211. var top = new View () {
  212. X = 0,
  213. Y = 0,
  214. Height = 20
  215. };
  216. var v = new View () {
  217. Height = Dim.Fill ()
  218. };
  219. top.Add (v);
  220. Assert.False (v.AutoSize);
  221. Assert.True (v.GetCurrentHeight (out int cHeight));
  222. Assert.Equal (20, cHeight);
  223. v.Height = Dim.Fill (1);
  224. Assert.True (v.GetCurrentHeight (out cHeight));
  225. Assert.Equal (19, cHeight);
  226. v.AutoSize = true;
  227. Assert.True (v.GetCurrentHeight (out cHeight));
  228. Assert.Equal (19, cHeight);
  229. }
  230. [Fact]
  231. public void AutoSize_False_If_Text_Emmpty ()
  232. {
  233. var view1 = new View ();
  234. var view2 = new View ("");
  235. var view3 = new View () { Text = "" };
  236. Assert.False (view1.AutoSize);
  237. Assert.False (view2.AutoSize);
  238. Assert.False (view3.AutoSize);
  239. }
  240. [Fact]
  241. public void AutoSize_False_If_Text_Is_Not_Emmpty ()
  242. {
  243. var view1 = new View ();
  244. view1.Text = "Hello World";
  245. var view2 = new View ("Hello World");
  246. var view3 = new View () { Text = "Hello World" };
  247. Assert.False (view1.AutoSize);
  248. Assert.False (view2.AutoSize);
  249. Assert.False (view3.AutoSize);
  250. }
  251. [Fact]
  252. public void AutoSize_True_Label_If_Text_Emmpty ()
  253. {
  254. var label1 = new Label ();
  255. var label2 = new Label ("");
  256. var label3 = new Label () { Text = "" };
  257. Assert.True (label1.AutoSize);
  258. Assert.True (label2.AutoSize);
  259. Assert.True (label3.AutoSize);
  260. }
  261. [Fact]
  262. public void AutoSize_True_Label_If_Text_Is_Not_Emmpty ()
  263. {
  264. var label1 = new Label ();
  265. label1.Text = "Hello World";
  266. var label2 = new Label ("Hello World");
  267. var label3 = new Label () { Text = "Hello World" };
  268. Assert.True (label1.AutoSize);
  269. Assert.True (label2.AutoSize);
  270. Assert.True (label3.AutoSize);
  271. }
  272. [Fact]
  273. public void AutoSize_False_ResizeView_Is_Always_False ()
  274. {
  275. var label = new Label () { AutoSize = false };
  276. label.Text = "New text";
  277. Assert.False (label.AutoSize);
  278. Assert.Equal ("{X=0,Y=0,Width=0,Height=1}", label.Bounds.ToString ());
  279. }
  280. [Fact]
  281. public void AutoSize_True_ResizeView_With_Dim_Absolute ()
  282. {
  283. var label = new Label ();
  284. label.Text = "New text";
  285. Assert.True (label.AutoSize);
  286. Assert.Equal ("{X=0,Y=0,Width=8,Height=1}", label.Bounds.ToString ());
  287. }
  288. [Fact, AutoInitShutdown]
  289. public void AutoSize_False_ResizeView_With_Dim_Fill_After_IsInitialized ()
  290. {
  291. var win = new Window (new Rect (0, 0, 30, 80), "");
  292. var label = new Label () { AutoSize = false, Width = Dim.Fill (), Height = Dim.Fill () };
  293. win.Add (label);
  294. Application.Top.Add (win);
  295. // Text is empty so height=0
  296. Assert.False (label.AutoSize);
  297. Assert.Equal ("{X=0,Y=0,Width=0,Height=0}", label.Bounds.ToString ());
  298. label.Text = "New text\nNew line";
  299. Application.Top.LayoutSubviews ();
  300. Assert.False (label.AutoSize);
  301. Assert.Equal ("{X=0,Y=0,Width=28,Height=78}", label.Bounds.ToString ());
  302. Assert.False (label.IsInitialized);
  303. Application.Begin (Application.Top);
  304. Assert.True (label.IsInitialized);
  305. Assert.False (label.AutoSize);
  306. Assert.Equal ("{X=0,Y=0,Width=28,Height=78}", label.Bounds.ToString ());
  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 so height=0
  317. Assert.True (label.AutoSize);
  318. Assert.Equal ("{X=0,Y=0,Width=0,Height=0}", label.Bounds.ToString ());
  319. label.Text = "First line\nSecond line";
  320. Application.Top.LayoutSubviews ();
  321. Assert.True (label.AutoSize);
  322. Assert.Equal ("{X=0,Y=0,Width=28,Height=2}", label.Bounds.ToString ());
  323. Assert.False (label.IsInitialized);
  324. Application.Begin (Application.Top);
  325. Assert.True (label.AutoSize);
  326. Assert.Equal ("{X=0,Y=0,Width=28,Height=2}", label.Bounds.ToString ());
  327. Assert.True (label.IsInitialized);
  328. label.AutoSize = false;
  329. Application.Refresh ();
  330. Assert.False (label.AutoSize);
  331. Assert.Equal ("{X=0,Y=0,Width=28,Height=1}", label.Bounds.ToString ());
  332. }
  333. [Fact, AutoInitShutdown]
  334. public void AutoSize_False_SetWidthHeight_With_Dim_Fill_And_Dim_Absolute_With_Initialization ()
  335. {
  336. var win = new Window (new Rect (0, 0, 30, 80), "");
  337. var label = new Label () { Width = Dim.Fill () };
  338. win.Add (label);
  339. Application.Top.Add (win);
  340. // Text is empty so height=0
  341. Assert.True (label.AutoSize);
  342. Assert.Equal ("{X=0,Y=0,Width=0,Height=0}", label.Bounds.ToString ());
  343. Application.Begin (Application.Top);
  344. Assert.True (label.AutoSize);
  345. Assert.Equal ("{X=0,Y=0,Width=28,Height=0}", label.Bounds.ToString ());
  346. label.Text = "First line\nSecond line";
  347. Application.Refresh ();
  348. // Here the AutoSize ensuring the right size
  349. Assert.True (label.AutoSize);
  350. Assert.Equal ("{X=0,Y=0,Width=28,Height=2}", label.Bounds.ToString ());
  351. label.AutoSize = false;
  352. Application.Refresh ();
  353. // Here the SetMinWidthHeight ensuring the minimum height
  354. Assert.False (label.AutoSize);
  355. Assert.Equal ("{X=0,Y=0,Width=28,Height=1}", label.Bounds.ToString ());
  356. label.Text = "First changed line\nSecond changed line\nNew line";
  357. Application.Refresh ();
  358. Assert.False (label.AutoSize);
  359. Assert.Equal ("{X=0,Y=0,Width=28,Height=1}", label.Bounds.ToString ());
  360. label.AutoSize = true;
  361. Application.Refresh ();
  362. Assert.True (label.AutoSize);
  363. Assert.Equal ("{X=0,Y=0,Width=28,Height=3}", label.Bounds.ToString ());
  364. }
  365. [Fact, AutoInitShutdown]
  366. public void AutoSize_True_Setting_With_Height_Horizontal ()
  367. {
  368. var label = new Label ("Hello") { Width = 10, Height = 2 };
  369. var viewX = new View ("X") { X = Pos.Right (label) };
  370. var viewY = new View ("Y") { Y = Pos.Bottom (label) };
  371. Application.Top.Add (label, viewX, viewY);
  372. Application.Begin (Application.Top);
  373. Assert.True (label.AutoSize);
  374. Assert.Equal (new Rect (0, 0, 10, 2), label.Frame);
  375. var expected = @"
  376. Hello X
  377. Y
  378. ";
  379. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  380. Assert.Equal (new Rect (0, 0, 11, 3), pos);
  381. label.AutoSize = false;
  382. Application.Refresh ();
  383. Assert.False (label.AutoSize);
  384. Assert.Equal (new Rect (0, 0, 10, 2), label.Frame);
  385. expected = @"
  386. Hello X
  387. Y
  388. ";
  389. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  390. Assert.Equal (new Rect (0, 0, 11, 3), pos);
  391. }
  392. [Fact, AutoInitShutdown]
  393. public void AutoSize_True_Setting_With_Height_Vertical ()
  394. {
  395. var label = new Label ("Hello") { Width = 2, Height = 10, TextDirection = TextDirection.TopBottom_LeftRight };
  396. var viewX = new View ("X") { X = Pos.Right (label) };
  397. var viewY = new View ("Y") { Y = Pos.Bottom (label) };
  398. Application.Top.Add (label, viewX, viewY);
  399. Application.Begin (Application.Top);
  400. Assert.True (label.AutoSize);
  401. Assert.Equal (new Rect (0, 0, 2, 10), label.Frame);
  402. var expected = @"
  403. H X
  404. e
  405. l
  406. l
  407. o
  408. Y
  409. ";
  410. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  411. Assert.Equal (new Rect (0, 0, 3, 11), pos);
  412. label.AutoSize = false;
  413. Application.Refresh ();
  414. Assert.False (label.AutoSize);
  415. Assert.Equal (new Rect (0, 0, 2, 10), label.Frame);
  416. expected = @"
  417. H X
  418. e
  419. l
  420. l
  421. o
  422. Y
  423. ";
  424. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  425. Assert.Equal (new Rect (0, 0, 3, 11), pos);
  426. }
  427. [Fact]
  428. [AutoInitShutdown]
  429. public void Excess_Text_Is_Erased_When_The_Width_Is_Reduced ()
  430. {
  431. var lbl = new Label ("123");
  432. Application.Top.Add (lbl);
  433. Application.Begin (Application.Top);
  434. Assert.True (lbl.AutoSize);
  435. Assert.Equal ("123 ", GetContents ());
  436. lbl.Text = "12";
  437. lbl.SuperView.Redraw (lbl.SuperView.NeedDisplay);
  438. Assert.Equal ("12 ", GetContents ());
  439. string GetContents ()
  440. {
  441. var text = "";
  442. for (int i = 0; i < 4; i++) {
  443. text += (char)Application.Driver.Contents [0, i, 0];
  444. }
  445. return text;
  446. }
  447. }
  448. [Fact, AutoInitShutdown]
  449. public void Width_Height_SetMinWidthHeight_Narrow_Wide_Runes ()
  450. {
  451. var text = $"First line{Environment.NewLine}Second line";
  452. var horizontalView = new View () {
  453. Width = 20,
  454. Text = text
  455. };
  456. var verticalView = new View () {
  457. Y = 3,
  458. Height = 20,
  459. Text = text,
  460. TextDirection = TextDirection.TopBottom_LeftRight
  461. };
  462. var win = new Window () {
  463. Width = Dim.Fill (),
  464. Height = Dim.Fill (),
  465. Text = "Window"
  466. };
  467. win.Add (horizontalView, verticalView);
  468. Application.Top.Add (win);
  469. Application.Begin (Application.Top);
  470. ((FakeDriver)Application.Driver).SetBufferSize (32, 32);
  471. Assert.False (horizontalView.AutoSize);
  472. Assert.False (verticalView.AutoSize);
  473. Assert.Equal (new Rect (0, 0, 20, 1), horizontalView.Frame);
  474. Assert.Equal (new Rect (0, 3, 1, 20), verticalView.Frame);
  475. var expected = @"
  476. ┌──────────────────────────────┐
  477. │First line Second li │
  478. │ │
  479. │ │
  480. │F │
  481. │i │
  482. │r │
  483. │s │
  484. │t │
  485. │ │
  486. │l │
  487. │i │
  488. │n │
  489. │e │
  490. │ │
  491. │S │
  492. │e │
  493. │c │
  494. │o │
  495. │n │
  496. │d │
  497. │ │
  498. │l │
  499. │i │
  500. │ │
  501. │ │
  502. │ │
  503. │ │
  504. │ │
  505. │ │
  506. │ │
  507. └──────────────────────────────┘
  508. ";
  509. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  510. Assert.Equal (new Rect (0, 0, 32, 32), pos);
  511. verticalView.Text = $"最初の行{Environment.NewLine}二行目";
  512. Application.Top.Redraw (Application.Top.Bounds);
  513. Assert.Equal (new Rect (0, 3, 2, 20), verticalView.Frame);
  514. expected = @"
  515. ┌──────────────────────────────┐
  516. │First line Second li │
  517. │ │
  518. │ │
  519. │最 │
  520. │初 │
  521. │の │
  522. │行 │
  523. │ │
  524. │二 │
  525. │行 │
  526. │目 │
  527. │ │
  528. │ │
  529. │ │
  530. │ │
  531. │ │
  532. │ │
  533. │ │
  534. │ │
  535. │ │
  536. │ │
  537. │ │
  538. │ │
  539. │ │
  540. │ │
  541. │ │
  542. │ │
  543. │ │
  544. │ │
  545. │ │
  546. └──────────────────────────────┘
  547. ";
  548. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  549. Assert.Equal (new Rect (0, 0, 32, 32), pos);
  550. }
  551. [Fact, AutoInitShutdown]
  552. public void TextDirection_Toggle ()
  553. {
  554. var view = new View ();
  555. var win = new Window () { Width = Dim.Fill (), Height = Dim.Fill () };
  556. win.Add (view);
  557. Application.Top.Add (win);
  558. Application.Begin (Application.Top);
  559. ((FakeDriver)Application.Driver).SetBufferSize (22, 22);
  560. Assert.False (view.AutoSize);
  561. Assert.Equal (TextDirection.LeftRight_TopBottom, view.TextDirection);
  562. Assert.Equal (Rect.Empty, view.Frame);
  563. Assert.Equal ("Absolute(0)", view.X.ToString ());
  564. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  565. Assert.Equal ("Absolute(0)", view.Width.ToString ());
  566. Assert.Equal ("Absolute(0)", view.Height.ToString ());
  567. var expected = @"
  568. ┌────────────────────┐
  569. │ │
  570. │ │
  571. │ │
  572. │ │
  573. │ │
  574. │ │
  575. │ │
  576. │ │
  577. │ │
  578. │ │
  579. │ │
  580. │ │
  581. │ │
  582. │ │
  583. │ │
  584. │ │
  585. │ │
  586. │ │
  587. │ │
  588. │ │
  589. └────────────────────┘
  590. ";
  591. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  592. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  593. view.Text = "Hello World";
  594. view.Width = 11;
  595. Application.Refresh ();
  596. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  597. Assert.Equal ("Absolute(0)", view.X.ToString ());
  598. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  599. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  600. Assert.Equal ("Absolute(0)", view.Height.ToString ());
  601. expected = @"
  602. ┌────────────────────┐
  603. │Hello World │
  604. │ │
  605. │ │
  606. │ │
  607. │ │
  608. │ │
  609. │ │
  610. │ │
  611. │ │
  612. │ │
  613. │ │
  614. │ │
  615. │ │
  616. │ │
  617. │ │
  618. │ │
  619. │ │
  620. │ │
  621. │ │
  622. │ │
  623. └────────────────────┘
  624. ";
  625. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  626. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  627. view.AutoSize = true;
  628. view.Text = "Hello Worlds";
  629. Application.Refresh ();
  630. Assert.Equal (new Rect (0, 0, 12, 1), view.Frame);
  631. Assert.Equal ("Absolute(0)", view.X.ToString ());
  632. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  633. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  634. Assert.Equal ("Absolute(0)", view.Height.ToString ());
  635. expected = @"
  636. ┌────────────────────┐
  637. │Hello Worlds │
  638. │ │
  639. │ │
  640. │ │
  641. │ │
  642. │ │
  643. │ │
  644. │ │
  645. │ │
  646. │ │
  647. │ │
  648. │ │
  649. │ │
  650. │ │
  651. │ │
  652. │ │
  653. │ │
  654. │ │
  655. │ │
  656. │ │
  657. └────────────────────┘
  658. ";
  659. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  660. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  661. view.TextDirection = TextDirection.TopBottom_LeftRight;
  662. Application.Refresh ();
  663. Assert.Equal (new Rect (0, 0, 11, 12), 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(0)", view.Height.ToString ());
  668. expected = @"
  669. ┌────────────────────┐
  670. │H │
  671. │e │
  672. │l │
  673. │l │
  674. │o │
  675. │ │
  676. │W │
  677. │o │
  678. │r │
  679. │l │
  680. │d │
  681. │s │
  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.AutoSize = false;
  695. view.Height = 1;
  696. Application.Refresh ();
  697. Assert.Equal (new Rect (0, 0, 11, 1), view.Frame);
  698. Assert.Equal ("Absolute(0)", view.X.ToString ());
  699. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  700. Assert.Equal ("Absolute(11)", view.Width.ToString ());
  701. Assert.Equal ("Absolute(1)", view.Height.ToString ());
  702. expected = @"
  703. ┌────────────────────┐
  704. │HelloWorlds │
  705. │ │
  706. │ │
  707. │ │
  708. │ │
  709. │ │
  710. │ │
  711. │ │
  712. │ │
  713. │ │
  714. │ │
  715. │ │
  716. │ │
  717. │ │
  718. │ │
  719. │ │
  720. │ │
  721. │ │
  722. │ │
  723. │ │
  724. └────────────────────┘
  725. ";
  726. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  727. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  728. view.PreserveTrailingSpaces = true;
  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. │Hello World │
  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 = false;
  762. var f = view.Frame;
  763. view.Width = f.Height;
  764. view.Height = f.Width;
  765. view.TextDirection = TextDirection.TopBottom_LeftRight;
  766. Application.Refresh ();
  767. Assert.Equal (new Rect (0, 0, 1, 11), view.Frame);
  768. Assert.Equal ("Absolute(0)", view.X.ToString ());
  769. Assert.Equal ("Absolute(0)", view.Y.ToString ());
  770. Assert.Equal ("Absolute(1)", view.Width.ToString ());
  771. Assert.Equal ("Absolute(11)", view.Height.ToString ());
  772. expected = @"
  773. ┌────────────────────┐
  774. │H │
  775. │e │
  776. │l │
  777. │l │
  778. │o │
  779. │ │
  780. │W │
  781. │o │
  782. │r │
  783. │l │
  784. │d │
  785. │ │
  786. │ │
  787. │ │
  788. │ │
  789. │ │
  790. │ │
  791. │ │
  792. │ │
  793. │ │
  794. └────────────────────┘
  795. ";
  796. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  797. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  798. view.AutoSize = true;
  799. Application.Refresh ();
  800. Assert.Equal (new Rect (0, 0, 1, 12), 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. │s │
  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. }
  832. [Fact, AutoInitShutdown]
  833. public void Width_Height_AutoSize_True_Stay_True_If_TextFormatter_Size_Fit ()
  834. {
  835. var text = $"Fi_nish 終";
  836. var horizontalView = new View () {
  837. AutoSize = true,
  838. HotKeySpecifier = '_',
  839. Text = text
  840. };
  841. var verticalView = new View () {
  842. Y = 3,
  843. AutoSize = true,
  844. HotKeySpecifier = '_',
  845. Text = text,
  846. TextDirection = TextDirection.TopBottom_LeftRight
  847. };
  848. var win = new Window () {
  849. Width = Dim.Fill (),
  850. Height = Dim.Fill (),
  851. Text = "Window"
  852. };
  853. win.Add (horizontalView, verticalView);
  854. Application.Top.Add (win);
  855. Application.Begin (Application.Top);
  856. ((FakeDriver)Application.Driver).SetBufferSize (22, 22);
  857. Assert.True (horizontalView.AutoSize);
  858. Assert.True (verticalView.AutoSize);
  859. Assert.Equal (new Size (10, 1), horizontalView.TextFormatter.Size);
  860. Assert.Equal (new Size (2, 9), verticalView.TextFormatter.Size);
  861. Assert.Equal (new Rect (0, 0, 9, 1), horizontalView.Frame);
  862. Assert.Equal ("Absolute(0)", horizontalView.X.ToString ());
  863. Assert.Equal ("Absolute(0)", horizontalView.Y.ToString ());
  864. Assert.Equal ("Absolute(9)", horizontalView.Width.ToString ());
  865. Assert.Equal ("Absolute(1)", horizontalView.Height.ToString ());
  866. Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame);
  867. Assert.Equal ("Absolute(0)", verticalView.X.ToString ());
  868. Assert.Equal ("Absolute(3)", verticalView.Y.ToString ());
  869. Assert.Equal ("Absolute(2)", verticalView.Width.ToString ());
  870. Assert.Equal ("Absolute(8)", verticalView.Height.ToString ());
  871. var expected = @"
  872. ┌────────────────────┐
  873. │Finish 終 │
  874. │ │
  875. │ │
  876. │F │
  877. │i │
  878. │n │
  879. │i │
  880. │s │
  881. │h │
  882. │ │
  883. │終 │
  884. │ │
  885. │ │
  886. │ │
  887. │ │
  888. │ │
  889. │ │
  890. │ │
  891. │ │
  892. │ │
  893. └────────────────────┘
  894. ";
  895. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  896. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  897. verticalView.Text = $"最初_の行二行目";
  898. Application.Top.Redraw (Application.Top.Bounds);
  899. Assert.True (horizontalView.AutoSize);
  900. Assert.True (verticalView.AutoSize);
  901. // height was initialized with 8 and is kept as minimum
  902. Assert.Equal (new Rect (0, 3, 2, 8), verticalView.Frame);
  903. Assert.Equal ("Absolute(0)", verticalView.X.ToString ());
  904. Assert.Equal ("Absolute(3)", verticalView.Y.ToString ());
  905. Assert.Equal ("Absolute(2)", verticalView.Width.ToString ());
  906. Assert.Equal ("Absolute(8)", verticalView.Height.ToString ());
  907. expected = @"
  908. ┌────────────────────┐
  909. │Finish 終 │
  910. │ │
  911. │ │
  912. │最 │
  913. │初 │
  914. │の │
  915. │行 │
  916. │二 │
  917. │行 │
  918. │目 │
  919. │ │
  920. │ │
  921. │ │
  922. │ │
  923. │ │
  924. │ │
  925. │ │
  926. │ │
  927. │ │
  928. │ │
  929. └────────────────────┘
  930. ";
  931. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  932. Assert.Equal (new Rect (0, 0, 22, 22), pos);
  933. }
  934. [Fact, AutoInitShutdown]
  935. public void AutoSize_Stays_True_Center_HotKeySpecifier ()
  936. {
  937. var btn = new Button () {
  938. X = Pos.Center (),
  939. Y = Pos.Center (),
  940. Text = "Say He_llo 你"
  941. };
  942. var win = new Window () {
  943. Width = Dim.Fill (),
  944. Height = Dim.Fill (),
  945. Title = "Test Demo 你"
  946. };
  947. win.Add (btn);
  948. Application.Top.Add (win);
  949. Assert.True (btn.AutoSize);
  950. Application.Begin (Application.Top);
  951. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  952. var expected = @"
  953. ┌ Test Demo 你 ──────────────┐
  954. │ │
  955. │ [ Say Hello 你 ] │
  956. │ │
  957. └────────────────────────────┘
  958. ";
  959. TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  960. Assert.True (btn.AutoSize);
  961. btn.Text = "Say He_llo 你 changed";
  962. Assert.True (btn.AutoSize);
  963. Application.Refresh ();
  964. expected = @"
  965. ┌ Test Demo 你 ──────────────┐
  966. │ │
  967. │ [ Say Hello 你 changed ] │
  968. │ │
  969. └────────────────────────────┘
  970. ";
  971. TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  972. }
  973. [Fact, AutoInitShutdown]
  974. public void AutoSize_False_Equal_Before_And_After_IsInitialized_With_Differents_Orders ()
  975. {
  976. var view1 = new View () { Text = "Say Hello view1 你", AutoSize = false, Width = 10, Height = 5 };
  977. var view2 = new View () { Text = "Say Hello view2 你", Width = 10, Height = 5, AutoSize = false };
  978. var view3 = new View () { AutoSize = false, Width = 10, Height = 5, Text = "Say Hello view3 你" };
  979. var view4 = new View () {
  980. Text = "Say Hello view4 你",
  981. AutoSize = false,
  982. Width = 10,
  983. Height = 5,
  984. TextDirection = TextDirection.TopBottom_LeftRight
  985. };
  986. var view5 = new View () {
  987. Text = "Say Hello view5 你",
  988. Width = 10,
  989. Height = 5,
  990. AutoSize = false,
  991. TextDirection = TextDirection.TopBottom_LeftRight
  992. };
  993. var view6 = new View () {
  994. AutoSize = false,
  995. Width = 10,
  996. Height = 5,
  997. TextDirection = TextDirection.TopBottom_LeftRight,
  998. Text = "Say Hello view6 你",
  999. };
  1000. Application.Top.Add (view1, view2, view3, view4, view5, view6);
  1001. Assert.False (view1.IsInitialized);
  1002. Assert.False (view2.IsInitialized);
  1003. Assert.False (view3.IsInitialized);
  1004. Assert.False (view4.IsInitialized);
  1005. Assert.False (view5.IsInitialized);
  1006. Assert.False (view1.AutoSize);
  1007. Assert.Equal (new Rect (0, 0, 10, 5), view1.Frame);
  1008. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1009. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1010. Assert.False (view2.AutoSize);
  1011. Assert.Equal (new Rect (0, 0, 10, 5), view2.Frame);
  1012. Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1013. Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1014. Assert.False (view3.AutoSize);
  1015. Assert.Equal (new Rect (0, 0, 10, 5), view3.Frame);
  1016. Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1017. Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1018. Assert.False (view4.AutoSize);
  1019. Assert.Equal (new Rect (0, 0, 10, 5), view4.Frame);
  1020. Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1021. Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1022. Assert.False (view5.AutoSize);
  1023. Assert.Equal (new Rect (0, 0, 10, 5), view5.Frame);
  1024. Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1025. Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1026. Assert.False (view6.AutoSize);
  1027. Assert.Equal (new Rect (0, 0, 10, 5), view6.Frame);
  1028. Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1029. Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1030. Application.Begin (Application.Top);
  1031. Assert.True (view1.IsInitialized);
  1032. Assert.True (view2.IsInitialized);
  1033. Assert.True (view3.IsInitialized);
  1034. Assert.True (view4.IsInitialized);
  1035. Assert.True (view5.IsInitialized);
  1036. Assert.False (view1.AutoSize);
  1037. Assert.Equal (new Rect (0, 0, 10, 5), view1.Frame);
  1038. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1039. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1040. Assert.False (view2.AutoSize);
  1041. Assert.Equal (new Rect (0, 0, 10, 5), view2.Frame);
  1042. Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1043. Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1044. Assert.False (view3.AutoSize);
  1045. Assert.Equal (new Rect (0, 0, 10, 5), view3.Frame);
  1046. Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1047. Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1048. Assert.False (view4.AutoSize);
  1049. Assert.Equal (new Rect (0, 0, 10, 5), view4.Frame);
  1050. Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1051. Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1052. Assert.False (view5.AutoSize);
  1053. Assert.Equal (new Rect (0, 0, 10, 5), view5.Frame);
  1054. Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1055. Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1056. Assert.False (view6.AutoSize);
  1057. Assert.Equal (new Rect (0, 0, 10, 5), view6.Frame);
  1058. Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1059. Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1060. }
  1061. [Fact, AutoInitShutdown]
  1062. public void AutoSize_True_Equal_Before_And_After_IsInitialized_With_Differents_Orders ()
  1063. {
  1064. var view1 = new View () { Text = "Say Hello view1 你", AutoSize = true, Width = 10, Height = 5 };
  1065. var view2 = new View () { Text = "Say Hello view2 你", Width = 10, Height = 5, AutoSize = true };
  1066. var view3 = new View () { AutoSize = true, Width = 10, Height = 5, Text = "Say Hello view3 你" };
  1067. var view4 = new View () {
  1068. Text = "Say Hello view4 你",
  1069. AutoSize = true,
  1070. Width = 10,
  1071. Height = 5,
  1072. TextDirection = TextDirection.TopBottom_LeftRight
  1073. };
  1074. var view5 = new View () {
  1075. Text = "Say Hello view5 你",
  1076. Width = 10,
  1077. Height = 5,
  1078. AutoSize = true,
  1079. TextDirection = TextDirection.TopBottom_LeftRight
  1080. };
  1081. var view6 = new View () {
  1082. AutoSize = true,
  1083. Width = 10,
  1084. Height = 5,
  1085. TextDirection = TextDirection.TopBottom_LeftRight,
  1086. Text = "Say Hello view6 你",
  1087. };
  1088. Application.Top.Add (view1, view2, view3, view4, view5, view6);
  1089. Assert.False (view1.IsInitialized);
  1090. Assert.False (view2.IsInitialized);
  1091. Assert.False (view3.IsInitialized);
  1092. Assert.False (view4.IsInitialized);
  1093. Assert.False (view5.IsInitialized);
  1094. Assert.True (view1.AutoSize);
  1095. Assert.Equal (new Rect (0, 0, 18, 5), view1.Frame);
  1096. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1097. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1098. Assert.True (view2.AutoSize);
  1099. Assert.Equal (new Rect (0, 0, 18, 5), view2.Frame);
  1100. Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1101. Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1102. Assert.True (view3.AutoSize);
  1103. Assert.Equal (new Rect (0, 0, 18, 5), view3.Frame);
  1104. Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1105. Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1106. Assert.True (view4.AutoSize);
  1107. Assert.Equal (new Rect (0, 0, 10, 17), view4.Frame);
  1108. Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1109. Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1110. Assert.True (view5.AutoSize);
  1111. Assert.Equal (new Rect (0, 0, 10, 17), view5.Frame);
  1112. Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1113. Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1114. Assert.True (view6.AutoSize);
  1115. Assert.Equal (new Rect (0, 0, 10, 17), view6.Frame);
  1116. Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1117. Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1118. Application.Begin (Application.Top);
  1119. Assert.True (view1.IsInitialized);
  1120. Assert.True (view2.IsInitialized);
  1121. Assert.True (view3.IsInitialized);
  1122. Assert.True (view4.IsInitialized);
  1123. Assert.True (view5.IsInitialized);
  1124. Assert.True (view1.AutoSize);
  1125. Assert.Equal (new Rect (0, 0, 18, 5), view1.Frame);
  1126. Assert.Equal ("Absolute(10)", view1.Width.ToString ());
  1127. Assert.Equal ("Absolute(5)", view1.Height.ToString ());
  1128. Assert.True (view2.AutoSize);
  1129. Assert.Equal (new Rect (0, 0, 18, 5), view2.Frame);
  1130. Assert.Equal ("Absolute(10)", view2.Width.ToString ());
  1131. Assert.Equal ("Absolute(5)", view2.Height.ToString ());
  1132. Assert.True (view3.AutoSize);
  1133. Assert.Equal (new Rect (0, 0, 18, 5), view3.Frame);
  1134. Assert.Equal ("Absolute(10)", view3.Width.ToString ());
  1135. Assert.Equal ("Absolute(5)", view3.Height.ToString ());
  1136. Assert.True (view4.AutoSize);
  1137. Assert.Equal (new Rect (0, 0, 10, 17), view4.Frame);
  1138. Assert.Equal ("Absolute(10)", view4.Width.ToString ());
  1139. Assert.Equal ("Absolute(5)", view4.Height.ToString ());
  1140. Assert.True (view5.AutoSize);
  1141. Assert.Equal (new Rect (0, 0, 10, 17), view5.Frame);
  1142. Assert.Equal ("Absolute(10)", view5.Width.ToString ());
  1143. Assert.Equal ("Absolute(5)", view5.Height.ToString ());
  1144. Assert.True (view6.AutoSize);
  1145. Assert.Equal (new Rect (0, 0, 10, 17), view6.Frame);
  1146. Assert.Equal ("Absolute(10)", view6.Width.ToString ());
  1147. Assert.Equal ("Absolute(5)", view6.Height.ToString ());
  1148. }
  1149. [Fact, AutoInitShutdown]
  1150. public void Setting_Frame_Dont_Respect_AutoSize_True_On_Layout_Absolute ()
  1151. {
  1152. var view1 = new View (new Rect (0, 0, 10, 0)) { Text = "Say Hello view1 你", AutoSize = true };
  1153. var view2 = new View (new Rect (0, 0, 0, 10)) {
  1154. Text = "Say Hello view2 你",
  1155. AutoSize = true,
  1156. TextDirection = TextDirection.TopBottom_LeftRight
  1157. };
  1158. Application.Top.Add (view1, view2);
  1159. var rs = Application.Begin (Application.Top);
  1160. Assert.True (view1.AutoSize);
  1161. Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle);
  1162. Assert.Equal (new Rect (0, 0, 18, 1), view1.Frame);
  1163. Assert.Equal ("Absolute(0)", view1.X.ToString ());
  1164. Assert.Equal ("Absolute(0)", view1.Y.ToString ());
  1165. Assert.Equal ("Absolute(18)", view1.Width.ToString ());
  1166. Assert.Equal ("Absolute(1)", view1.Height.ToString ());
  1167. Assert.True (view2.AutoSize);
  1168. Assert.Equal (LayoutStyle.Absolute, view2.LayoutStyle);
  1169. Assert.Equal (new Rect (0, 0, 2, 17), view2.Frame);
  1170. Assert.Equal ("Absolute(0)", view2.X.ToString ());
  1171. Assert.Equal ("Absolute(0)", view2.Y.ToString ());
  1172. Assert.Equal ("Absolute(2)", view2.Width.ToString ());
  1173. Assert.Equal ("Absolute(17)", view2.Height.ToString ());
  1174. view1.Frame = new Rect (0, 0, 25, 4);
  1175. bool firstIteration = false;
  1176. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  1177. Assert.True (view1.AutoSize);
  1178. Assert.Equal (LayoutStyle.Absolute, view1.LayoutStyle);
  1179. Assert.Equal (new Rect (0, 0, 25, 4), view1.Frame);
  1180. Assert.Equal ("Absolute(0)", view1.X.ToString ());
  1181. Assert.Equal ("Absolute(0)", view1.Y.ToString ());
  1182. Assert.Equal ("Absolute(18)", view1.Width.ToString ());
  1183. Assert.Equal ("Absolute(1)", view1.Height.ToString ());
  1184. view2.Frame = new Rect (0, 0, 1, 25);
  1185. Application.RunMainLoopIteration (ref rs, true, ref firstIteration);
  1186. Assert.True (view2.AutoSize);
  1187. Assert.Equal (LayoutStyle.Absolute, view2.LayoutStyle);
  1188. Assert.Equal (new Rect (0, 0, 1, 25), view2.Frame);
  1189. Assert.Equal ("Absolute(0)", view2.X.ToString ());
  1190. Assert.Equal ("Absolute(0)", view2.Y.ToString ());
  1191. Assert.Equal ("Absolute(2)", view2.Width.ToString ());
  1192. Assert.Equal ("Absolute(17)", view2.Height.ToString ());
  1193. }
  1194. [Fact, AutoInitShutdown]
  1195. public void Pos_Dim_Are_Null_If_Not_Initialized_On_Constructor_IsAdded_False ()
  1196. {
  1197. var top = Application.Top;
  1198. var view1 = new View ();
  1199. Assert.False (view1.IsAdded);
  1200. Assert.Null (view1.X);
  1201. Assert.Null (view1.Y);
  1202. Assert.Null (view1.Width);
  1203. Assert.Null (view1.Height);
  1204. top.Add (view1);
  1205. Assert.True (view1.IsAdded);
  1206. Assert.Equal ("Absolute(0)", view1.X.ToString ());
  1207. Assert.Equal ("Absolute(0)", view1.Y.ToString ());
  1208. Assert.Equal ("Absolute(0)", view1.Width.ToString ());
  1209. Assert.Equal ("Absolute(0)", view1.Height.ToString ());
  1210. var view2 = new View () {
  1211. X = Pos.Center (),
  1212. Y = Pos.Center (),
  1213. Width = Dim.Fill (),
  1214. Height = Dim.Fill ()
  1215. };
  1216. Assert.False (view2.IsAdded);
  1217. Assert.Equal ("Center", view2.X.ToString ());
  1218. Assert.Equal ("Center", view2.Y.ToString ());
  1219. Assert.Equal ("Fill(0)", view2.Width.ToString ());
  1220. Assert.Equal ("Fill(0)", view2.Height.ToString ());
  1221. top.Add (view2);
  1222. Assert.True (view2.IsAdded);
  1223. Assert.Equal ("Center", view2.X.ToString ());
  1224. Assert.Equal ("Center", view2.Y.ToString ());
  1225. Assert.Equal ("Fill(0)", view2.Width.ToString ());
  1226. Assert.Equal ("Fill(0)", view2.Height.ToString ());
  1227. }
  1228. }
  1229. }