LayoutTests.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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) => _output = output;
  11. [Fact]
  12. public void TopologicalSort_Missing_Add ()
  13. {
  14. var root = new View ();
  15. var sub1 = new View ();
  16. root.Add (sub1);
  17. var sub2 = new View ();
  18. sub1.Width = Dim.Width (sub2);
  19. Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
  20. sub2.Width = Dim.Width (sub1);
  21. Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
  22. root.Dispose ();
  23. sub1.Dispose ();
  24. sub2.Dispose ();
  25. }
  26. [Fact]
  27. public void TopologicalSort_Recursive_Ref ()
  28. {
  29. var root = new View ();
  30. var sub1 = new View ();
  31. root.Add (sub1);
  32. var sub2 = new View ();
  33. root.Add (sub2);
  34. sub2.Width = Dim.Width (sub2);
  35. var exception = Record.Exception (root.LayoutSubviews);
  36. Assert.Null (exception);
  37. root.Dispose ();
  38. sub1.Dispose ();
  39. sub2.Dispose ();
  40. }
  41. [Fact]
  42. public void LayoutSubviews_No_SuperView ()
  43. {
  44. var root = new View ();
  45. var first = new View { Id = "first", X = 1, Y = 2, Height = 3, Width = 4 };
  46. root.Add (first);
  47. var second = new View { Id = "second" };
  48. root.Add (second);
  49. second.X = Pos.Right (first) + 1;
  50. root.LayoutSubviews ();
  51. Assert.Equal (6, second.Frame.X);
  52. root.Dispose ();
  53. first.Dispose ();
  54. second.Dispose ();
  55. }
  56. [Fact]
  57. public void LayoutSubviews_RootHas_SuperView ()
  58. {
  59. var top = new View ();
  60. var root = new View ();
  61. top.Add (root);
  62. var first = new View { Id = "first", X = 1, Y = 2, Height = 3, Width = 4 };
  63. root.Add (first);
  64. var second = new View { Id = "second" };
  65. root.Add (second);
  66. second.X = Pos.Right (first) + 1;
  67. root.LayoutSubviews ();
  68. Assert.Equal (6, second.Frame.X);
  69. root.Dispose ();
  70. top.Dispose ();
  71. first.Dispose ();
  72. second.Dispose ();
  73. }
  74. [Fact]
  75. public void LayoutSubviews_ViewThatRefsSubView_Throws ()
  76. {
  77. var root = new View ();
  78. var super = new View ();
  79. root.Add (super);
  80. var sub = new View ();
  81. super.Add (sub);
  82. super.Width = Dim.Width (sub);
  83. Assert.Throws<InvalidOperationException> (() => root.LayoutSubviews ());
  84. root.Dispose ();
  85. super.Dispose ();
  86. }
  87. [Fact] [AutoInitShutdown]
  88. public void TrySetWidth_ForceValidatePosDim ()
  89. {
  90. var top = new View () {
  91. X = 0,
  92. Y = 0,
  93. Width = 80
  94. };
  95. var v = new View () {
  96. Width = Dim.Fill (),
  97. ValidatePosDim = true
  98. };
  99. top.Add (v);
  100. Assert.False (v.TrySetWidth (70, out var rWidth));
  101. Assert.Equal (70, rWidth);
  102. v.Width = Dim.Fill (1);
  103. Assert.False (v.TrySetWidth (70, out rWidth));
  104. Assert.Equal (69, rWidth);
  105. v.Width = 0;
  106. Assert.True (v.TrySetWidth (70, out rWidth));
  107. Assert.Equal (70, rWidth);
  108. Assert.False (v.IsInitialized);
  109. Application.Top.Add (top);
  110. Application.Begin (Application.Top);
  111. Assert.True (v.IsInitialized);
  112. v.Width = 75;
  113. Assert.True (v.TrySetWidth (60, out rWidth));
  114. Assert.Equal (60, rWidth);
  115. }
  116. [Fact] [AutoInitShutdown]
  117. public void TrySetHeight_ForceValidatePosDim ()
  118. {
  119. var top = new View () {
  120. X = 0,
  121. Y = 0,
  122. Height = 20
  123. };
  124. var v = new View () {
  125. Height = Dim.Fill (),
  126. ValidatePosDim = true
  127. };
  128. top.Add (v);
  129. Assert.False (v.TrySetHeight (10, out var rHeight));
  130. Assert.Equal (10, rHeight);
  131. v.Height = Dim.Fill (1);
  132. Assert.False (v.TrySetHeight (10, out rHeight));
  133. Assert.Equal (9, rHeight);
  134. v.Height = 0;
  135. Assert.True (v.TrySetHeight (10, out rHeight));
  136. Assert.Equal (10, rHeight);
  137. Assert.False (v.IsInitialized);
  138. Application.Top.Add (top);
  139. Application.Begin (Application.Top);
  140. Assert.True (v.IsInitialized);
  141. v.Height = 15;
  142. Assert.True (v.TrySetHeight (5, out rHeight));
  143. Assert.Equal (5, rHeight);
  144. }
  145. [Fact] [TestRespondersDisposed]
  146. public void GetCurrentWidth_TrySetWidth ()
  147. {
  148. var top = new View () {
  149. X = 0,
  150. Y = 0,
  151. Width = 80
  152. };
  153. var v = new View () {
  154. Width = Dim.Fill (),
  155. ValidatePosDim = true
  156. };
  157. top.Add (v);
  158. top.BeginInit ();
  159. top.EndInit ();
  160. top.LayoutSubviews ();
  161. Assert.False (v.AutoSize);
  162. Assert.False (v.TrySetWidth (0, out _));
  163. Assert.True (v.Width is Dim.DimFill);
  164. Assert.Equal (80, v.Frame.Width);
  165. v.Width = Dim.Fill (1);
  166. top.LayoutSubviews ();
  167. Assert.False (v.TrySetWidth (0, out _));
  168. Assert.True (v.Width is Dim.DimFill);
  169. Assert.Equal (79, v.Frame.Width);
  170. v.AutoSize = true;
  171. top.LayoutSubviews ();
  172. Assert.True (v.TrySetWidth (0, out _));
  173. Assert.True (v.Width is Dim.DimAbsolute);
  174. Assert.Equal (79, v.Frame.Width);
  175. top.Dispose ();
  176. }
  177. [Fact]
  178. public void GetCurrentHeight_TrySetHeight ()
  179. {
  180. var top = new View () {
  181. X = 0,
  182. Y = 0,
  183. Height = 20
  184. };
  185. var v = new View () {
  186. Height = Dim.Fill (),
  187. ValidatePosDim = true
  188. };
  189. top.Add (v);
  190. top.BeginInit ();
  191. top.EndInit ();
  192. top.LayoutSubviews ();
  193. Assert.False (v.AutoSize);
  194. Assert.False (v.TrySetHeight (0, out _));
  195. Assert.Equal (20, v.Frame.Height);
  196. v.Height = Dim.Fill (1);
  197. top.LayoutSubviews ();
  198. Assert.False (v.TrySetHeight (0, out _));
  199. Assert.True (v.Height is Dim.DimFill);
  200. Assert.Equal (19, v.Frame.Height);
  201. v.AutoSize = true;
  202. top.LayoutSubviews ();
  203. Assert.True (v.TrySetHeight (0, out _));
  204. Assert.True (v.Height is Dim.DimAbsolute);
  205. Assert.Equal (19, v.Frame.Height);
  206. top.Dispose ();
  207. }
  208. [Fact]
  209. [AutoInitShutdown]
  210. public void DimFill_SizedCorrectly ()
  211. {
  212. var view = new View () {
  213. Width = Dim.Fill (),
  214. Height = Dim.Fill (),
  215. BorderStyle = LineStyle.Single,
  216. };
  217. Application.Top.Add (view);
  218. var rs = Application.Begin (Application.Top);
  219. ((FakeDriver)Application.Driver).SetBufferSize (32, 5);
  220. //view.SetNeedsLayout ();
  221. Application.Top.LayoutSubviews ();
  222. //view.SetRelativeLayout (new Rect (0, 0, 32, 5));
  223. Assert.Equal (32, view.Frame.Width);
  224. Assert.Equal (5, view.Frame.Height);
  225. }
  226. // Tested in AbsoluteLayoutTests.cs
  227. // public void Pos_Dim_Are_Null_If_Not_Initialized_On_Constructor_IsAdded_False ()
  228. [Theory] [AutoInitShutdown]
  229. [InlineData (1)]
  230. [InlineData (2)]
  231. [InlineData (3)]
  232. [InlineData (4)]
  233. [InlineData (5)]
  234. [InlineData (6)]
  235. [InlineData (7)]
  236. [InlineData (8)]
  237. [InlineData (9)]
  238. [InlineData (10)]
  239. public void Dim_CenteredSubView_85_Percent_Height (int height)
  240. {
  241. var win = new Window () {
  242. Width = Dim.Fill (),
  243. Height = Dim.Fill ()
  244. };
  245. var subview = new Window () {
  246. X = Pos.Center (),
  247. Y = Pos.Center (),
  248. Width = Dim.Percent (85),
  249. Height = Dim.Percent (85)
  250. };
  251. win.Add (subview);
  252. var rs = Application.Begin (win);
  253. var firstIteration = false;
  254. ((FakeDriver)Application.Driver).SetBufferSize (20, height);
  255. Application.RunIteration (ref rs, ref firstIteration);
  256. var expected = string.Empty;
  257. switch (height) {
  258. case 1:
  259. //Assert.Equal (new Rect (0, 0, 17, 0), subview.Frame);
  260. expected = @"
  261. ────────────────────";
  262. break;
  263. case 2:
  264. //Assert.Equal (new Rect (0, 0, 17, 1), subview.Frame);
  265. expected = @"
  266. ┌──────────────────┐
  267. └──────────────────┘
  268. ";
  269. break;
  270. case 3:
  271. //Assert.Equal (new Rect (0, 0, 17, 2), subview.Frame);
  272. expected = @"
  273. ┌──────────────────┐
  274. │ │
  275. └──────────────────┘
  276. ";
  277. break;
  278. case 4:
  279. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  280. expected = @"
  281. ┌──────────────────┐
  282. │ ─────────────── │
  283. │ │
  284. └──────────────────┘";
  285. break;
  286. case 5:
  287. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  288. expected = @"
  289. ┌──────────────────┐
  290. │ ┌─────────────┐ │
  291. │ └─────────────┘ │
  292. │ │
  293. └──────────────────┘";
  294. break;
  295. case 6:
  296. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  297. expected = @"
  298. ┌──────────────────┐
  299. │ ┌─────────────┐ │
  300. │ │ │ │
  301. │ └─────────────┘ │
  302. │ │
  303. └──────────────────┘";
  304. break;
  305. case 7:
  306. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  307. expected = @"
  308. ┌──────────────────┐
  309. │ ┌─────────────┐ │
  310. │ │ │ │
  311. │ │ │ │
  312. │ └─────────────┘ │
  313. │ │
  314. └──────────────────┘";
  315. break;
  316. case 8:
  317. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  318. expected = @"
  319. ┌──────────────────┐
  320. │ ┌─────────────┐ │
  321. │ │ │ │
  322. │ │ │ │
  323. │ │ │ │
  324. │ └─────────────┘ │
  325. │ │
  326. └──────────────────┘";
  327. break;
  328. case 9:
  329. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  330. expected = @"
  331. ┌──────────────────┐
  332. │ │
  333. │ ┌─────────────┐ │
  334. │ │ │ │
  335. │ │ │ │
  336. │ │ │ │
  337. │ └─────────────┘ │
  338. │ │
  339. └──────────────────┘";
  340. break;
  341. case 10:
  342. //Assert.Equal (new Rect (0, 0, 17, 3), subview.Frame);
  343. expected = @"
  344. ┌──────────────────┐
  345. │ │
  346. │ ┌─────────────┐ │
  347. │ │ │ │
  348. │ │ │ │
  349. │ │ │ │
  350. │ │ │ │
  351. │ └─────────────┘ │
  352. │ │
  353. └──────────────────┘";
  354. break;
  355. }
  356. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  357. Application.End (rs);
  358. }
  359. [Theory] [AutoInitShutdown]
  360. [InlineData (1)]
  361. [InlineData (2)]
  362. [InlineData (3)]
  363. [InlineData (4)]
  364. [InlineData (5)]
  365. [InlineData (6)]
  366. [InlineData (7)]
  367. [InlineData (8)]
  368. [InlineData (9)]
  369. [InlineData (10)]
  370. public void Dim_CenteredSubView_85_Percent_Width (int width)
  371. {
  372. var win = new Window () {
  373. Width = Dim.Fill (),
  374. Height = Dim.Fill ()
  375. };
  376. var subview = new Window () {
  377. X = Pos.Center (),
  378. Y = Pos.Center (),
  379. Width = Dim.Percent (85),
  380. Height = Dim.Percent (85)
  381. };
  382. win.Add (subview);
  383. var rs = Application.Begin (win);
  384. var firstIteration = false;
  385. ((FakeDriver)Application.Driver).SetBufferSize (width, 7);
  386. Application.RunIteration (ref rs, ref firstIteration);
  387. var expected = string.Empty;
  388. switch (width) {
  389. case 1:
  390. Assert.Equal (new Rect (0, 0, 0, 4), subview.Frame);
  391. expected = @"
  392. │";
  393. break;
  394. case 2:
  395. Assert.Equal (new Rect (0, 0, 0, 4), subview.Frame);
  396. expected = @"
  397. ┌┐
  398. ││
  399. ││
  400. ││
  401. ││
  402. ││
  403. └┘";
  404. break;
  405. case 3:
  406. Assert.Equal (new Rect (0, 0, 0, 4), subview.Frame);
  407. expected = @"
  408. ┌─┐
  409. │ │
  410. │ │
  411. │ │
  412. │ │
  413. │ │
  414. └─┘";
  415. break;
  416. case 4:
  417. Assert.Equal (new Rect (0, 0, 1, 4), subview.Frame);
  418. expected = @"
  419. ┌──┐
  420. ││ │
  421. ││ │
  422. ││ │
  423. ││ │
  424. │ │
  425. └──┘";
  426. break;
  427. case 5:
  428. Assert.Equal (new Rect (0, 0, 2, 4), subview.Frame);
  429. expected = @"
  430. ┌───┐
  431. │┌┐ │
  432. │││ │
  433. │││ │
  434. │└┘ │
  435. │ │
  436. └───┘";
  437. break;
  438. case 6:
  439. Assert.Equal (new Rect (0, 0, 3, 4), subview.Frame);
  440. expected = @"
  441. ┌────┐
  442. │┌─┐ │
  443. ││ │ │
  444. ││ │ │
  445. │└─┘ │
  446. │ │
  447. └────┘";
  448. break;
  449. case 7:
  450. Assert.Equal (new Rect (0, 0, 4, 4), subview.Frame);
  451. expected = @"
  452. ┌─────┐
  453. │┌──┐ │
  454. ││ │ │
  455. ││ │ │
  456. │└──┘ │
  457. │ │
  458. └─────┘";
  459. break;
  460. case 8:
  461. Assert.Equal (new Rect (0, 0, 5, 4), subview.Frame);
  462. expected = @"
  463. ┌──────┐
  464. │┌───┐ │
  465. ││ │ │
  466. ││ │ │
  467. │└───┘ │
  468. │ │
  469. └──────┘";
  470. break;
  471. case 9:
  472. Assert.Equal (new Rect (1, 0, 5, 4), subview.Frame);
  473. expected = @"
  474. ┌───────┐
  475. │ ┌───┐ │
  476. │ │ │ │
  477. │ │ │ │
  478. │ └───┘ │
  479. │ │
  480. └───────┘";
  481. break;
  482. case 10:
  483. Assert.Equal (new Rect (1, 0, 6, 4), subview.Frame);
  484. expected = @"
  485. ┌────────┐
  486. │ ┌────┐ │
  487. │ │ │ │
  488. │ │ │ │
  489. │ └────┘ │
  490. │ │
  491. └────────┘";
  492. break;
  493. }
  494. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  495. Application.End (rs);
  496. }
  497. [Fact] [AutoInitShutdown]
  498. public void PosCombine_DimCombine_View_With_SubViews ()
  499. {
  500. var clicked = false;
  501. var top = Application.Top;
  502. var win1 = new Window () { Id = "win1", Width = 20, Height = 10 };
  503. var view1 = new View ("view1");
  504. var win2 = new Window () { Id = "win2", Y = Pos.Bottom (view1) + 1, Width = 10, Height = 3 };
  505. var view2 = new View () { Id = "view2", Width = Dim.Fill (), Height = 1, CanFocus = true };
  506. view2.MouseClick += (sender, e) => clicked = true;
  507. var view3 = new View () { Id = "view3", Width = Dim.Fill (1), Height = 1, CanFocus = true };
  508. view2.Add (view3);
  509. win2.Add (view2);
  510. win1.Add (view1, win2);
  511. top.Add (win1);
  512. var rs = Application.Begin (top);
  513. TestHelpers.AssertDriverContentsWithFrameAre (@"
  514. ┌──────────────────┐
  515. │view1 │
  516. │ │
  517. │┌────────┐ │
  518. ││ │ │
  519. │└────────┘ │
  520. │ │
  521. │ │
  522. │ │
  523. └──────────────────┘", _output);
  524. Assert.Equal (new Rect (0, 0, 80, 25), top.Frame);
  525. Assert.Equal (new Rect (0, 0, 5, 1), view1.Frame);
  526. Assert.Equal (new Rect (0, 0, 20, 10), win1.Frame);
  527. Assert.Equal (new Rect (0, 2, 10, 3), win2.Frame);
  528. Assert.Equal (new Rect (0, 0, 8, 1), view2.Frame);
  529. Assert.Equal (new Rect (0, 0, 7, 1), view3.Frame);
  530. var foundView = View.FindDeepestView (top, 9, 4, out int rx, out int ry);
  531. Assert.Equal (foundView, view2);
  532. Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent () {
  533. X = 9,
  534. Y = 4,
  535. Flags = MouseFlags.Button1Clicked
  536. }));
  537. Assert.True (clicked);
  538. Application.End (rs);
  539. }
  540. [Fact] [TestRespondersDisposed]
  541. public void Draw_Vertical_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
  542. {
  543. Application.Init (new FakeDriver ());
  544. var top = Application.Top;
  545. var view = new View ("view") {
  546. Y = -2,
  547. Height = 10,
  548. TextDirection = TextDirection.TopBottom_LeftRight
  549. };
  550. top.Add (view);
  551. Application.Iteration += (s, a) => {
  552. Assert.Equal (-2, view.Y);
  553. Application.RequestStop ();
  554. };
  555. try {
  556. Application.Run ();
  557. } catch (IndexOutOfRangeException ex) {
  558. // After the fix this exception will not be caught.
  559. Assert.IsType<IndexOutOfRangeException> (ex);
  560. }
  561. // Shutdown must be called to safely clean up Application if Init has been called
  562. Application.Shutdown ();
  563. }
  564. [Fact] [TestRespondersDisposed]
  565. public void Draw_Throws_IndexOutOfRangeException_With_Negative_Bounds ()
  566. {
  567. Application.Init (new FakeDriver ());
  568. var top = Application.Top;
  569. var view = new View ("view") { X = -2 };
  570. top.Add (view);
  571. Application.Iteration += (s, a) => {
  572. Assert.Equal (-2, view.X);
  573. Application.RequestStop ();
  574. };
  575. try {
  576. Application.Run ();
  577. } catch (IndexOutOfRangeException ex) {
  578. // After the fix this exception will not be caught.
  579. Assert.IsType<IndexOutOfRangeException> (ex);
  580. }
  581. // Shutdown must be called to safely clean up Application if Init has been called
  582. Application.Shutdown ();
  583. }
  584. [Fact]
  585. public void PosCombine_Refs_SuperView_Throws ()
  586. {
  587. Application.Init (new FakeDriver ());
  588. var w = new Window () {
  589. X = Pos.Left (Application.Top) + 2,
  590. Y = Pos.Top (Application.Top) + 2
  591. };
  592. var f = new FrameView ();
  593. var v1 = new View () {
  594. X = Pos.Left (w) + 2,
  595. Y = Pos.Top (w) + 2
  596. };
  597. var v2 = new View () {
  598. X = Pos.Left (v1) + 2,
  599. Y = Pos.Top (v1) + 2
  600. };
  601. f.Add (v1, v2);
  602. w.Add (f);
  603. Application.Top.Add (w);
  604. f.X = Pos.X (Application.Top) + Pos.X (v2) - Pos.X (v1);
  605. f.Y = Pos.Y (Application.Top) + Pos.Y (v2) - Pos.Y (v1);
  606. Application.Top.LayoutComplete += (s, e) => {
  607. Assert.Equal (0, Application.Top.Frame.X);
  608. Assert.Equal (0, Application.Top.Frame.Y);
  609. Assert.Equal (2, w.Frame.X);
  610. Assert.Equal (2, w.Frame.Y);
  611. Assert.Equal (2, f.Frame.X);
  612. Assert.Equal (2, f.Frame.Y);
  613. Assert.Equal (4, v1.Frame.X);
  614. Assert.Equal (4, v1.Frame.Y);
  615. Assert.Equal (6, v2.Frame.X);
  616. Assert.Equal (6, v2.Frame.Y);
  617. };
  618. Application.Iteration += (s, a) => Application.RequestStop ();
  619. Assert.Throws<InvalidOperationException> (() => Application.Run ());
  620. Application.Shutdown ();
  621. }
  622. // Was named AutoSize_Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute ()
  623. // but doesn't actually have anything to do with AutoSize.
  624. [Fact]
  625. public void Pos_Validation_Do_Not_Throws_If_NewValue_Is_PosAbsolute_And_OldValue_Is_Another_Type_After_Sets_To_LayoutStyle_Absolute ()
  626. {
  627. Application.Init (new FakeDriver ());
  628. var t = Application.Top;
  629. var w = new Window () {
  630. X = Pos.Left (t) + 2,
  631. Y = Pos.At (2)
  632. };
  633. var v = new View () {
  634. X = Pos.Center (),
  635. Y = Pos.Percent (10)
  636. };
  637. w.Add (v);
  638. t.Add (w);
  639. t.Ready += (s, e) => {
  640. v.Frame = new Rect (2, 2, 10, 10);
  641. Assert.Equal (2, v.X = 2);
  642. Assert.Equal (2, v.Y = 2);
  643. };
  644. Application.Iteration += (s, a) => Application.RequestStop ();
  645. Application.Run ();
  646. Application.Shutdown ();
  647. }
  648. }