DialogTests.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using Terminal.Gui;
  7. using Xunit;
  8. using System.Globalization;
  9. using Xunit.Abstractions;
  10. using System.Text;
  11. using static Terminal.Gui.Application;
  12. namespace Terminal.Gui.DialogTests {
  13. public class DialogTests {
  14. readonly ITestOutputHelper output;
  15. public DialogTests (ITestOutputHelper output)
  16. {
  17. this.output = output;
  18. }
  19. //[Fact]
  20. //[AutoInitShutdown]
  21. //public void Default_Has_Border ()
  22. //{
  23. // var d = (FakeDriver)Application.Driver;
  24. // d.SetBufferSize (20, 5);
  25. // Application.RunState runstate = null;
  26. // var title = "Title";
  27. // var btnText = "ok";
  28. // var buttonRow = $"{CM.Glyphs.VLine}{CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket}{CM.Glyphs.VLine}";
  29. // var width = buttonRow.Length;
  30. // var topRow = $"┌┤{title} {new string (d.HLine.ToString () [0], width - title.Length - 2)}├┐";
  31. // var bottomRow = $"└{new string (d.HLine.ToString () [0], width - 2)}┘";
  32. // var dlg = new Dialog (title, new Button (btnText));
  33. // Application.Begin (dlg);
  34. // TestHelpers.AssertDriverContentsWithFrameAre ($"{topRow}\n{buttonRow}\n{bottomRow}", output);
  35. // Application.End (runstate);
  36. //}
  37. private (RunState, Dialog) RunButtonTestDialog (string title, int width, Dialog.ButtonAlignments align, params Button [] btns)
  38. {
  39. var dlg = new Dialog (btns) {
  40. Title = title,
  41. X = 0,
  42. Y = 0,
  43. Width = width,
  44. Height = 1,
  45. ButtonAlignment = align,
  46. };
  47. // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
  48. dlg.Border.Thickness = new Thickness (1, 0, 1, 0);
  49. return (Application.Begin (dlg), dlg);
  50. }
  51. [Fact]
  52. [AutoInitShutdown]
  53. public void Size_Default ()
  54. {
  55. var d = new Dialog () {
  56. };
  57. Application.Begin (d);
  58. ((FakeDriver)Application.Driver).SetBufferSize (100, 100);
  59. // Default size is Percent(85)
  60. Assert.Equal (new Size ((int)(100 * .85), (int)(100 * .85)), d.Frame.Size);
  61. }
  62. [Fact]
  63. [AutoInitShutdown]
  64. public void Location_Default ()
  65. {
  66. var d = new Dialog () {
  67. };
  68. Application.Begin (d);
  69. ((FakeDriver)Application.Driver).SetBufferSize (100, 100);
  70. // Default location is centered, so 100 / 2 - 85 / 2 = 7
  71. var expected = 7;
  72. Assert.Equal (new Point (expected, expected), d.Frame.Location);
  73. }
  74. [Fact]
  75. [AutoInitShutdown]
  76. public void Size_Not_Default ()
  77. {
  78. var d = new Dialog () {
  79. Width = 50,
  80. Height = 50,
  81. };
  82. Application.Begin (d);
  83. ((FakeDriver)Application.Driver).SetBufferSize (100, 100);
  84. // Default size is Percent(85)
  85. Assert.Equal (new Size (50, 50), d.Frame.Size);
  86. }
  87. [Fact]
  88. [AutoInitShutdown]
  89. public void Location_Not_Default ()
  90. {
  91. var d = new Dialog () {
  92. X = 1,
  93. Y = 1,
  94. };
  95. Application.Begin (d);
  96. ((FakeDriver)Application.Driver).SetBufferSize (100, 100);
  97. // Default location is centered, so 100 / 2 - 85 / 2 = 7
  98. var expected = 1;
  99. Assert.Equal (new Point (expected, expected), d.Frame.Location);
  100. }
  101. [Fact]
  102. [AutoInitShutdown]
  103. public void Location_When_Application_Top_Not_Default ()
  104. {
  105. var expected = 5;
  106. var d = new Dialog () {
  107. X = expected,
  108. Y = expected,
  109. Height = 5,
  110. Width = 5
  111. };
  112. Application.Begin (d);
  113. ((FakeDriver)Application.Driver).SetBufferSize (20, 10);
  114. // Default location is centered, so 100 / 2 - 85 / 2 = 7
  115. Assert.Equal (new Point (expected, expected), d.Frame.Location);
  116. TestHelpers.AssertDriverContentsWithFrameAre (@"
  117. ┌───┐
  118. │ │
  119. │ │
  120. │ │
  121. └───┘", output);
  122. }
  123. [Fact]
  124. [AutoInitShutdown]
  125. public void Location_When_Not_Application_Top_Not_Default ()
  126. {
  127. Application.Top.BorderStyle = LineStyle.Double;
  128. var iterations = -1;
  129. Application.Iteration += () => {
  130. iterations++;
  131. if (iterations == 0) {
  132. var d = new Dialog () {
  133. X = 5,
  134. Y = 5,
  135. Height = 3,
  136. Width = 5
  137. };
  138. Application.Begin (d);
  139. Assert.Equal (new Point (5, 5), d.Frame.Location);
  140. TestHelpers.AssertDriverContentsWithFrameAre (@"
  141. ╔══════════════════╗
  142. ║ ║
  143. ║ ║
  144. ║ ║
  145. ║ ║
  146. ║ ┌───┐ ║
  147. ║ │ │ ║
  148. ║ └───┘ ║
  149. ║ ║
  150. ╚══════════════════╝", output);
  151. d = new Dialog () {
  152. X = 5,
  153. Y = 5,
  154. };
  155. Application.Begin (d);
  156. // This is because of PostionTopLevels and EnsureVisibleBounds
  157. Assert.Equal (new Point (3, 2), d.Frame.Location);
  158. Assert.Equal (new Size (17, 8), d.Frame.Size);
  159. TestHelpers.AssertDriverContentsWithFrameAre (@"
  160. ╔══════════════════╗
  161. ║ ║
  162. ║ ┌───────────────┐
  163. ║ │ │
  164. ║ │ │
  165. ║ │ │
  166. ║ │ │
  167. ║ │ │
  168. ║ │ │
  169. ╚══└───────────────┘", output);
  170. } else if (iterations > 0) {
  171. Application.RequestStop ();
  172. }
  173. };
  174. Application.Begin (Application.Top);
  175. ((FakeDriver)Application.Driver).SetBufferSize (20, 10);
  176. Application.Run ();
  177. }
  178. [Fact]
  179. [AutoInitShutdown]
  180. public void ButtonAlignment_One ()
  181. {
  182. var d = (FakeDriver)Application.Driver;
  183. RunState runstate = null;
  184. var title = "1234";
  185. // E.g "|[ ok ]|"
  186. var btnText = "ok";
  187. var buttonRow = $"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket} {CM.Glyphs.VLine}";
  188. var width = buttonRow.Length;
  189. d.SetBufferSize (width, 1);
  190. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText));
  191. // Center
  192. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  193. Application.End (runstate);
  194. // Justify
  195. buttonRow = $"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket}{CM.Glyphs.VLine}";
  196. Assert.Equal (width, buttonRow.Length);
  197. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btnText));
  198. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  199. Application.End (runstate);
  200. // Right
  201. buttonRow = $"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket}{CM.Glyphs.VLine}";
  202. Assert.Equal (width, buttonRow.Length);
  203. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btnText));
  204. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  205. Application.End (runstate);
  206. // Left
  207. buttonRow = $"{CM.Glyphs.VLine}{CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket} {CM.Glyphs.VLine}";
  208. Assert.Equal (width, buttonRow.Length);
  209. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btnText));
  210. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  211. Application.End (runstate);
  212. // Wider
  213. buttonRow = $"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket} {CM.Glyphs.VLine}";
  214. width = buttonRow.Length;
  215. d.SetBufferSize (width, 1);
  216. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText));
  217. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  218. Application.End (runstate);
  219. // Justify
  220. buttonRow = $"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket}{CM.Glyphs.VLine}";
  221. Assert.Equal (width, buttonRow.Length);
  222. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btnText));
  223. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  224. Application.End (runstate);
  225. // Right
  226. buttonRow = $"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket}{CM.Glyphs.VLine}";
  227. Assert.Equal (width, buttonRow.Length);
  228. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btnText));
  229. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  230. Application.End (runstate);
  231. // Left
  232. buttonRow = $"{CM.Glyphs.VLine}{CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket} {CM.Glyphs.VLine}";
  233. Assert.Equal (width, buttonRow.Length);
  234. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btnText));
  235. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  236. Application.End (runstate);
  237. }
  238. [Fact]
  239. [AutoInitShutdown]
  240. public void ButtonAlignment_Two ()
  241. {
  242. RunState runstate = null;
  243. var d = (FakeDriver)Application.Driver;
  244. var title = "1234";
  245. // E.g "|[ yes ][ no ]|"
  246. var btn1Text = "yes";
  247. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  248. var btn2Text = "no";
  249. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  250. var buttonRow = $@"{CM.Glyphs.VLine} {btn1} {btn2} {CM.Glyphs.VLine}";
  251. var width = buttonRow.Length;
  252. d.SetBufferSize (buttonRow.Length, 3);
  253. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text));
  254. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  255. Application.End (runstate);
  256. // Justify
  257. buttonRow = $@"{CM.Glyphs.VLine}{btn1} {btn2}{CM.Glyphs.VLine}";
  258. Assert.Equal (width, buttonRow.Length);
  259. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text));
  260. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  261. Application.End (runstate);
  262. // Right
  263. buttonRow = $@"{CM.Glyphs.VLine} {btn1} {btn2}{CM.Glyphs.VLine}";
  264. Assert.Equal (width, buttonRow.Length);
  265. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text));
  266. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  267. Application.End (runstate);
  268. // Left
  269. buttonRow = $@"{CM.Glyphs.VLine}{btn1} {btn2} {CM.Glyphs.VLine}";
  270. Assert.Equal (width, buttonRow.Length);
  271. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text));
  272. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  273. Application.End (runstate);
  274. }
  275. [Fact]
  276. [AutoInitShutdown]
  277. public void ButtonAlignment_Two_Hidden ()
  278. {
  279. RunState runstate = null;
  280. bool firstIteration = false;
  281. var d = (FakeDriver)Application.Driver;
  282. var title = "1234";
  283. // E.g "|[ yes ][ no ]|"
  284. var btn1Text = "yes";
  285. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  286. var btn2Text = "no";
  287. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  288. var buttonRow = $@"{CM.Glyphs.VLine} {btn1} {btn2} {CM.Glyphs.VLine}";
  289. var width = buttonRow.Length;
  290. d.SetBufferSize (buttonRow.Length, 3);
  291. Dialog dlg = null;
  292. Button button1, button2;
  293. // Default (Center)
  294. button1 = new Button (btn1Text);
  295. button2 = new Button (btn2Text);
  296. (runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, button1, button2);
  297. button1.Visible = false;
  298. Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
  299. buttonRow = $@"{CM.Glyphs.VLine} {btn2} {CM.Glyphs.VLine}";
  300. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  301. Application.End (runstate);
  302. // Justify
  303. Assert.Equal (width, buttonRow.Length);
  304. button1 = new Button (btn1Text);
  305. button2 = new Button (btn2Text);
  306. (runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, button1, button2);
  307. button1.Visible = false;
  308. Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
  309. buttonRow = $@"{CM.Glyphs.VLine} {btn2}{CM.Glyphs.VLine}";
  310. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  311. Application.End (runstate);
  312. // Right
  313. Assert.Equal (width, buttonRow.Length);
  314. button1 = new Button (btn1Text);
  315. button2 = new Button (btn2Text);
  316. (runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, button1, button2);
  317. button1.Visible = false;
  318. Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
  319. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  320. Application.End (runstate);
  321. // Left
  322. Assert.Equal (width, buttonRow.Length);
  323. button1 = new Button (btn1Text);
  324. button2 = new Button (btn2Text);
  325. (runstate, dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, button1, button2);
  326. button1.Visible = false;
  327. Application.RunMainLoopIteration (ref runstate, true, ref firstIteration);
  328. buttonRow = $@"{CM.Glyphs.VLine} {btn2} {CM.Glyphs.VLine}";
  329. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  330. Application.End (runstate);
  331. }
  332. [Fact]
  333. [AutoInitShutdown]
  334. public void ButtonAlignment_Three ()
  335. {
  336. RunState runstate = null;
  337. var d = (FakeDriver)Application.Driver;
  338. var title = "1234";
  339. // E.g "|[ yes ][ no ][ maybe ]|"
  340. var btn1Text = "yes";
  341. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  342. var btn2Text = "no";
  343. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  344. var btn3Text = "maybe";
  345. var btn3 = $"{CM.Glyphs.LeftBracket} {btn3Text} {CM.Glyphs.RightBracket}";
  346. var buttonRow = $@"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {CM.Glyphs.VLine}";
  347. var width = buttonRow.Length;
  348. d.SetBufferSize (buttonRow.Length, 3);
  349. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text));
  350. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  351. Application.End (runstate);
  352. // Justify
  353. buttonRow = $@"{CM.Glyphs.VLine}{btn1} {btn2} {btn3}{CM.Glyphs.VLine}";
  354. Assert.Equal (width, buttonRow.Length);
  355. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text));
  356. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  357. Application.End (runstate);
  358. // Right
  359. buttonRow = $@"{CM.Glyphs.VLine} {btn1} {btn2} {btn3}{CM.Glyphs.VLine}";
  360. Assert.Equal (width, buttonRow.Length);
  361. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text));
  362. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  363. Application.End (runstate);
  364. // Left
  365. buttonRow = $@"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {CM.Glyphs.VLine}";
  366. Assert.Equal (width, buttonRow.Length);
  367. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text));
  368. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  369. Application.End (runstate);
  370. }
  371. [Fact]
  372. [AutoInitShutdown]
  373. public void ButtonAlignment_Four ()
  374. {
  375. RunState runstate = null;
  376. var d = (FakeDriver)Application.Driver;
  377. var title = "1234";
  378. // E.g "|[ yes ][ no ][ maybe ]|"
  379. var btn1Text = "yes";
  380. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  381. var btn2Text = "no";
  382. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  383. var btn3Text = "maybe";
  384. var btn3 = $"{CM.Glyphs.LeftBracket} {btn3Text} {CM.Glyphs.RightBracket}";
  385. var btn4Text = "never";
  386. var btn4 = $"{CM.Glyphs.LeftBracket} {btn4Text} {CM.Glyphs.RightBracket}";
  387. var buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
  388. var width = buttonRow.Length;
  389. d.SetBufferSize (buttonRow.Length, 3);
  390. // Default - Center
  391. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  392. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  393. Application.End (runstate);
  394. // Justify
  395. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
  396. Assert.Equal (width, buttonRow.Length);
  397. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  398. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  399. Application.End (runstate);
  400. // Right
  401. buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
  402. Assert.Equal (width, buttonRow.Length);
  403. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  404. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  405. Application.End (runstate);
  406. // Left
  407. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
  408. Assert.Equal (width, buttonRow.Length);
  409. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  410. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  411. Application.End (runstate);
  412. }
  413. [Fact]
  414. [AutoInitShutdown]
  415. public void ButtonAlignment_Four_On_Too_Small_Width ()
  416. {
  417. RunState runstate = null;
  418. var d = (FakeDriver)Application.Driver;
  419. var title = "1234";
  420. // E.g "|[ yes ][ no ][ maybe ][ never ]|"
  421. var btn1Text = "yes";
  422. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  423. var btn2Text = "no";
  424. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  425. var btn3Text = "maybe";
  426. var btn3 = $"{CM.Glyphs.LeftBracket} {btn3Text} {CM.Glyphs.RightBracket}";
  427. var btn4Text = "never";
  428. var btn4 = $"{CM.Glyphs.LeftBracket} {btn4Text} {CM.Glyphs.RightBracket}";
  429. var buttonRow = string.Empty;
  430. var width = 30;
  431. d.SetBufferSize (width, 1);
  432. // Default - Center
  433. buttonRow = $"{CM.Glyphs.VLine}es {CM.Glyphs.RightBracket} {btn2} {btn3} {CM.Glyphs.LeftBracket} neve{CM.Glyphs.VLine}";
  434. (runstate, var dlg) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  435. Assert.Equal (new Size (width, 1), dlg.Frame.Size);
  436. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  437. Application.End (runstate);
  438. // Justify
  439. buttonRow = $"{CM.Glyphs.VLine}{CM.Glyphs.LeftBracket} yes {CM.Glyphs.LeftBracket} no {CM.Glyphs.LeftBracket} maybe {CM.Glyphs.LeftBracket} never {CM.Glyphs.RightBracket}{CM.Glyphs.VLine}";
  440. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  441. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output); Application.End (runstate);
  442. // Right
  443. buttonRow = $"{CM.Glyphs.VLine}{CM.Glyphs.RightBracket} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
  444. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  445. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output); Application.End (runstate);
  446. // Left
  447. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {CM.Glyphs.LeftBracket} n{CM.Glyphs.VLine}";
  448. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  449. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output); Application.End (runstate);
  450. }
  451. [Fact]
  452. [AutoInitShutdown]
  453. public void ButtonAlignment_Four_Wider ()
  454. {
  455. RunState runstate = null;
  456. var d = (FakeDriver)Application.Driver;
  457. var title = "1234";
  458. // E.g "|[ yes ][ no ][ maybe ]|"
  459. var btn1Text = "yes";
  460. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  461. var btn2Text = "no";
  462. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  463. var btn3Text = "你你你你你"; // This is a wide char
  464. var btn3 = $"{CM.Glyphs.LeftBracket} {btn3Text} {CM.Glyphs.RightBracket}";
  465. // Requires a Nerd Font
  466. var btn4Text = "\uE36E\uE36F\uE370\uE371\uE372\uE373";
  467. var btn4 = $"{CM.Glyphs.LeftBracket} {btn4Text} {CM.Glyphs.RightBracket}";
  468. // Note extra spaces to make dialog even wider
  469. // 123456 123456
  470. var buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
  471. var width = buttonRow.GetColumns ();
  472. d.SetBufferSize (width, 3);
  473. // Default - Center
  474. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  475. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  476. Application.End (runstate);
  477. // Justify
  478. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
  479. Assert.Equal (width, buttonRow.GetColumns ());
  480. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  481. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  482. Application.End (runstate);
  483. // Right
  484. buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
  485. Assert.Equal (width, buttonRow.GetColumns ());
  486. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  487. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  488. Application.End (runstate);
  489. // Left
  490. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
  491. Assert.Equal (width, buttonRow.GetColumns ());
  492. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  493. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  494. Application.End (runstate);
  495. }
  496. [Fact]
  497. [AutoInitShutdown]
  498. public void ButtonAlignment_Four_WideOdd ()
  499. {
  500. RunState runstate = null;
  501. var d = (FakeDriver)Application.Driver;
  502. var title = "1234";
  503. // E.g "|[ yes ][ no ][ maybe ]|"
  504. var btn1Text = "really long button 1";
  505. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  506. var btn2Text = "really long button 2";
  507. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  508. var btn3Text = "really long button 3";
  509. var btn3 = $"{CM.Glyphs.LeftBracket} {btn3Text} {CM.Glyphs.RightBracket}";
  510. var btn4Text = "really long button 44"; // 44 is intentional to make length different than rest
  511. var btn4 = $"{CM.Glyphs.LeftBracket} {btn4Text} {CM.Glyphs.RightBracket}";
  512. // Note extra spaces to make dialog even wider
  513. // 123456 1234567
  514. var buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
  515. var width = buttonRow.Length;
  516. d.SetBufferSize (buttonRow.Length, 1);
  517. // Default - Center
  518. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  519. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  520. Application.End (runstate);
  521. // Justify
  522. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
  523. Assert.Equal (width, buttonRow.Length);
  524. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Justify, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  525. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  526. Application.End (runstate);
  527. // Right
  528. buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {btn3} {btn4}{CM.Glyphs.VLine}";
  529. Assert.Equal (width, buttonRow.Length);
  530. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Right, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  531. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  532. Application.End (runstate);
  533. // Left
  534. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {btn3} {btn4} {CM.Glyphs.VLine}";
  535. Assert.Equal (width, buttonRow.Length);
  536. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Left, new Button (btn1Text), new Button (btn2Text), new Button (btn3Text), new Button (btn4Text));
  537. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  538. Application.End (runstate);
  539. }
  540. [Fact]
  541. [AutoInitShutdown]
  542. public void Zero_Buttons_Works ()
  543. {
  544. RunState runstate = null;
  545. var d = (FakeDriver)Application.Driver;
  546. var title = "1234";
  547. var buttonRow = $"{CM.Glyphs.VLine} {CM.Glyphs.VLine}";
  548. var width = buttonRow.Length;
  549. d.SetBufferSize (buttonRow.Length, 3);
  550. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, null);
  551. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  552. Application.End (runstate);
  553. }
  554. [Fact]
  555. [AutoInitShutdown]
  556. public void One_Button_Works ()
  557. {
  558. RunState runstate = null;
  559. var d = (FakeDriver)Application.Driver;
  560. var title = "";
  561. var btnText = "ok";
  562. var buttonRow = $"{CM.Glyphs.VLine} {CM.Glyphs.LeftBracket} {btnText} {CM.Glyphs.RightBracket} {CM.Glyphs.VLine}";
  563. var width = buttonRow.Length;
  564. d.SetBufferSize (buttonRow.Length, 10);
  565. (runstate, var _) = RunButtonTestDialog (title, width, Dialog.ButtonAlignments.Center, new Button (btnText));
  566. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  567. Application.End (runstate);
  568. }
  569. [Fact]
  570. [AutoInitShutdown]
  571. public void Add_Button_Works ()
  572. {
  573. RunState runstate = null;
  574. var d = (FakeDriver)Application.Driver;
  575. var title = "1234";
  576. var btn1Text = "yes";
  577. var btn1 = $"{CM.Glyphs.LeftBracket} {btn1Text} {CM.Glyphs.RightBracket}";
  578. var btn2Text = "no";
  579. var btn2 = $"{CM.Glyphs.LeftBracket} {btn2Text} {CM.Glyphs.RightBracket}";
  580. // We test with one button first, but do this to get the width right for 2
  581. var width = $@"{CM.Glyphs.VLine} {btn1} {btn2} {CM.Glyphs.VLine}".Length;
  582. d.SetBufferSize (width, 1);
  583. // Default (center)
  584. var dlg = new Dialog (new Button (btn1Text)) { Title = title, Width = width, Height = 1, ButtonAlignment = Dialog.ButtonAlignments.Center };
  585. // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
  586. dlg.Border.Thickness = new Thickness (1, 0, 1, 0);
  587. runstate = Application.Begin (dlg);
  588. var buttonRow = $"{CM.Glyphs.VLine} {btn1} {CM.Glyphs.VLine}";
  589. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  590. // Now add a second button
  591. buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2} {CM.Glyphs.VLine}";
  592. dlg.AddButton (new Button (btn2Text));
  593. bool first = false;
  594. Application.RunMainLoopIteration (ref runstate, true, ref first);
  595. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  596. Application.End (runstate);
  597. // Justify
  598. dlg = new Dialog (new Button (btn1Text)) { Title = title, Width = width, Height = 1, ButtonAlignment = Dialog.ButtonAlignments.Justify };
  599. // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
  600. dlg.Border.Thickness = new Thickness (1, 0, 1, 0);
  601. runstate = Application.Begin (dlg);
  602. buttonRow = $"{CM.Glyphs.VLine} {btn1}{CM.Glyphs.VLine}";
  603. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  604. // Now add a second button
  605. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2}{CM.Glyphs.VLine}";
  606. dlg.AddButton (new Button (btn2Text));
  607. first = false;
  608. Application.RunMainLoopIteration (ref runstate, true, ref first);
  609. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  610. Application.End (runstate);
  611. // Right
  612. dlg = new Dialog (new Button (btn1Text)) { Title = title, Width = width, Height = 1, ButtonAlignment = Dialog.ButtonAlignments.Right };
  613. // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
  614. dlg.Border.Thickness = new Thickness (1, 0, 1, 0);
  615. runstate = Application.Begin (dlg);
  616. buttonRow = $"{CM.Glyphs.VLine}{new string (' ', width - btn1.Length - 2)}{btn1}{CM.Glyphs.VLine}";
  617. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  618. // Now add a second button
  619. buttonRow = $"{CM.Glyphs.VLine} {btn1} {btn2}{CM.Glyphs.VLine}";
  620. dlg.AddButton (new Button (btn2Text));
  621. first = false;
  622. Application.RunMainLoopIteration (ref runstate, true, ref first);
  623. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  624. Application.End (runstate);
  625. // Left
  626. dlg = new Dialog (new Button (btn1Text)) { Title = title, Width = width, Height = 1, ButtonAlignment = Dialog.ButtonAlignments.Left };
  627. // Create with no top or bottom border to simplify testing button layout (no need to account for title etc..)
  628. dlg.Border.Thickness = new Thickness (1, 0, 1, 0);
  629. runstate = Application.Begin (dlg);
  630. buttonRow = $"{CM.Glyphs.VLine}{btn1}{new string (' ', width - btn1.Length - 2)}{CM.Glyphs.VLine}";
  631. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  632. // Now add a second button
  633. buttonRow = $"{CM.Glyphs.VLine}{btn1} {btn2} {CM.Glyphs.VLine}";
  634. dlg.AddButton (new Button (btn2Text));
  635. first = false;
  636. Application.RunMainLoopIteration (ref runstate, true, ref first);
  637. TestHelpers.AssertDriverContentsWithFrameAre ($"{buttonRow}", output);
  638. Application.End (runstate);
  639. }
  640. [Fact]
  641. [AutoInitShutdown]
  642. public void FileDialog_FileSystemWatcher ()
  643. {
  644. for (int i = 0; i < 8; i++) {
  645. var fd = new FileDialog ();
  646. fd.Ready += (s, e) => Application.RequestStop ();
  647. Application.Run (fd);
  648. }
  649. }
  650. [Fact, AutoInitShutdown]
  651. public void Dialog_Opened_From_Another_Dialog ()
  652. {
  653. var btn1 = new Button ("press me 1");
  654. Button btn2 = null;
  655. Button btn3 = null;
  656. string expected = null;
  657. btn1.Clicked += (s, e) => {
  658. btn2 = new Button ("Show Sub");
  659. btn3 = new Button ("Close");
  660. btn3.Clicked += (s, e) => Application.RequestStop ();
  661. btn2.Clicked += (s, e) => { MessageBox.Query (string.Empty, "ya", "Ok"); };
  662. var dlg = new Dialog (btn2, btn3);
  663. Application.Run (dlg);
  664. };
  665. var btn = $"{CM.Glyphs.LeftBracket}{CM.Glyphs.LeftDefaultIndicator} Ok {CM.Glyphs.RightDefaultIndicator}{CM.Glyphs.RightBracket}";
  666. var iterations = -1;
  667. Application.Iteration += () => {
  668. iterations++;
  669. if (iterations == 0) {
  670. Assert.True (btn1.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  671. } else if (iterations == 1) {
  672. expected = @$"
  673. ┌──────────────────────────────────────────────────────────────────┐
  674. │ │
  675. │ │
  676. │ │
  677. │ │
  678. │ │
  679. │ │
  680. │ │
  681. │ │
  682. │ │
  683. │ │
  684. │ │
  685. │ │
  686. │ │
  687. │ │
  688. │ │
  689. │ │
  690. │ │
  691. │ │
  692. │ {CM.Glyphs.LeftBracket} Show Sub {CM.Glyphs.RightBracket} {CM.Glyphs.LeftBracket} Close {CM.Glyphs.RightBracket} │
  693. └──────────────────────────────────────────────────────────────────┘";
  694. TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  695. Assert.True (btn2.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  696. } else if (iterations == 2) {
  697. TestHelpers.AssertDriverContentsWithFrameAre (@$"
  698. ┌──────────────────────────────────────────────────────────────────┐
  699. │ │
  700. │ │
  701. │ │
  702. │ │
  703. │ │
  704. │ │
  705. │ │
  706. │ ┌──────────────────────────────────────────────┐ │
  707. │ │ ya │ │
  708. │ │ │ │
  709. │ │ {btn} │ │
  710. │ └──────────────────────────────────────────────┘ │
  711. │ │
  712. │ │
  713. │ │
  714. │ │
  715. │ │
  716. │ │
  717. │ {CM.Glyphs.LeftBracket} Show Sub {CM.Glyphs.RightBracket} {CM.Glyphs.LeftBracket} Close {CM.Glyphs.RightBracket} │
  718. └──────────────────────────────────────────────────────────────────┘", output);
  719. Assert.True (Application.Current.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  720. } else if (iterations == 3) {
  721. TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  722. Assert.True (btn3.ProcessKey (new KeyEvent (Key.Enter, new KeyModifiers ())));
  723. } else if (iterations == 4) {
  724. TestHelpers.AssertDriverContentsWithFrameAre ("", output);
  725. Application.RequestStop ();
  726. }
  727. };
  728. Application.Run ();
  729. Application.Shutdown ();
  730. Assert.Equal (4, iterations);
  731. }
  732. [Fact, AutoInitShutdown]
  733. public void Dialog_In_Window_With_Size_One_Button_Aligns ()
  734. {
  735. ((FakeDriver)Application.Driver).SetBufferSize (20, 5);
  736. var win = new Window ();
  737. int iterations = 0;
  738. Application.Iteration += () => {
  739. if (++iterations > 2) {
  740. Application.RequestStop ();
  741. }
  742. };
  743. var btn = $"{CM.Glyphs.LeftBracket} Ok {CM.Glyphs.RightBracket}";
  744. win.Loaded += (s, a) => {
  745. var dlg = new Dialog (new Button ("Ok")) { Width = 18, Height = 3 };
  746. dlg.Loaded += (s, a) => {
  747. Application.Refresh ();
  748. var expected = @$"
  749. ┌──────────────────┐
  750. │┌────────────────┐│
  751. ││ {btn} ││
  752. │└────────────────┘│
  753. └──────────────────┘";
  754. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  755. };
  756. Application.Run (dlg);
  757. };
  758. Application.Run (win);
  759. }
  760. // [Theory, AutoInitShutdown]
  761. // [InlineData (5)]
  762. // //[InlineData (6)]
  763. // //[InlineData (7)]
  764. // //[InlineData (8)]
  765. // //[InlineData (9)]
  766. // public void Dialog_In_Window_Without_Size_One_Button_Aligns (int height)
  767. // {
  768. // ((FakeDriver)Application.Driver).SetBufferSize (20, height);
  769. // var win = new Window ();
  770. // Application.Iteration += () => {
  771. // var dlg = new Dialog ("Test", new Button ("Ok"));
  772. // dlg.LayoutComplete += (s, a) => {
  773. // Application.Refresh ();
  774. // // BUGBUG: This seems wrong; is it a bug in Dim.Percent(85)??
  775. // var expected = @"
  776. //┌┌┤Test├─────────┐─┐
  777. //││ │ │
  778. //││ [ Ok ] │ │
  779. //│└───────────────┘ │
  780. //└──────────────────┘";
  781. // _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  782. // dlg.RequestStop ();
  783. // win.RequestStop ();
  784. // };
  785. // Application.Run (dlg);
  786. // };
  787. // Application.Run (win);
  788. // Application.Shutdown ();
  789. // }
  790. [Fact, AutoInitShutdown]
  791. public void Dialog_In_Window_With_TexxtField_And_Button_AnchorEnd ()
  792. {
  793. ((FakeDriver)Application.Driver).SetBufferSize (20, 5);
  794. var win = new Window ();
  795. int iterations = 0;
  796. Application.Iteration += () => {
  797. if (++iterations > 2) {
  798. Application.RequestStop ();
  799. }
  800. };
  801. var b = $"{CM.Glyphs.LeftBracket} Ok {CM.Glyphs.RightBracket}";
  802. win.Loaded += (s, a) => {
  803. var dlg = new Dialog () { Width = 18, Height = 3 };
  804. Button btn = null;
  805. btn = new Button ("Ok") {
  806. X = Pos.AnchorEnd () - Pos.Function (Btn_Width)
  807. };
  808. int Btn_Width ()
  809. {
  810. return (btn?.Bounds.Width) ?? 0;
  811. }
  812. var tf = new TextField ("01234567890123456789") {
  813. Width = Dim.Fill (1) - Dim.Function (Btn_Width)
  814. };
  815. dlg.Loaded += (s, a) => {
  816. Application.Refresh ();
  817. Assert.Equal (new Rect (10, 0, 6, 1), btn.Frame);
  818. Assert.Equal (new Rect (0, 0, 6, 1), btn.Bounds);
  819. var expected = @$"
  820. ┌──────────────────┐
  821. │┌────────────────┐│
  822. ││23456789 {b}││
  823. │└────────────────┘│
  824. └──────────────────┘";
  825. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  826. dlg.SetNeedsLayout ();
  827. dlg.LayoutSubviews ();
  828. Application.Refresh ();
  829. Assert.Equal (new Rect (10, 0, 6, 1), btn.Frame);
  830. Assert.Equal (new Rect (0, 0, 6, 1), btn.Bounds);
  831. expected = @$"
  832. ┌──────────────────┐
  833. │┌────────────────┐│
  834. ││23456789 {b}││
  835. │└────────────────┘│
  836. └──────────────────┘";
  837. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  838. };
  839. dlg.Add (btn, tf);
  840. Application.Run (dlg);
  841. };
  842. Application.Run (win);
  843. }
  844. }
  845. }