DialogTests.cs 37 KB

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