WindowsAndFrameViews.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Terminal.Gui;
  4. namespace UICatalog.Scenarios;
  5. [ScenarioMetadata ("Windows & FrameViews", "Stress Tests Windows, sub-Windows, and FrameViews.")]
  6. [ScenarioCategory ("Layout")]
  7. public class WindowsAndFrameViews : Scenario
  8. {
  9. public override void Main ()
  10. {
  11. Application.Init ();
  12. Window app = new ()
  13. {
  14. Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
  15. };
  16. static int About ()
  17. {
  18. return MessageBox.Query (
  19. "About UI Catalog",
  20. "UI Catalog is a comprehensive sample library for Terminal.Gui",
  21. "Ok"
  22. );
  23. }
  24. var margin = 2;
  25. var padding = 1;
  26. var contentHeight = 7;
  27. // list of Windows we create
  28. List<View> listWin = new ();
  29. var win = new Window
  30. {
  31. Title = $"{listWin.Count} - Scenario: {GetName ()}",
  32. X = Pos.Center (),
  33. Y = 1,
  34. Width = Dim.Fill (15),
  35. Height = 10,
  36. ColorScheme = Colors.ColorSchemes ["Dialog"]
  37. };
  38. win.Padding.Thickness = new (padding);
  39. win.Margin.Thickness = new (margin);
  40. var paddingButton = new Button
  41. {
  42. X = Pos.Center (),
  43. Y = 0,
  44. ColorScheme = Colors.ColorSchemes ["Error"],
  45. Text = $"Padding of container is {padding}"
  46. };
  47. paddingButton.Accept += (s, e) => About ();
  48. win.Add (paddingButton);
  49. win.Add (
  50. new Button
  51. {
  52. X = Pos.Center (),
  53. Y = Pos.AnchorEnd (),
  54. ColorScheme = Colors.ColorSchemes ["Error"],
  55. Text = "Press ME! (Y = Pos.AnchorEnd(1))"
  56. }
  57. );
  58. app.Add (win);
  59. // add it to our list
  60. listWin.Add (win);
  61. // create 3 more Windows in a loop, adding them Application.Top
  62. // Each with a
  63. // button
  64. // sub Window with
  65. // TextField
  66. // sub FrameView with
  67. //
  68. for (var pad = 0; pad < 3; pad++)
  69. {
  70. Window loopWin = null;
  71. loopWin = new()
  72. {
  73. Title = $"{listWin.Count} - Window Loop - padding = {pad}",
  74. X = margin,
  75. Y = Pos.Bottom (listWin.Last ()) + margin,
  76. Width = Dim.Fill (margin),
  77. Height = contentHeight + pad * 2 + 2
  78. };
  79. loopWin.Padding.Thickness = new (pad);
  80. loopWin.ColorScheme = Colors.ColorSchemes ["Dialog"];
  81. var pressMeButton = new Button
  82. {
  83. X = Pos.Center (), Y = 0, ColorScheme = Colors.ColorSchemes ["Error"], Text = "Press me! (Y = 0)"
  84. };
  85. pressMeButton.Accept += (s, e) =>
  86. MessageBox.ErrorQuery (loopWin.Title, "Neat?", "Yes", "No");
  87. loopWin.Add (pressMeButton);
  88. var subWin = new Window
  89. {
  90. Title = "Sub Window",
  91. X = Pos.Percent (0),
  92. Y = 1,
  93. Width = Dim.Percent (50),
  94. Height = 5,
  95. ColorScheme = Colors.ColorSchemes ["Base"],
  96. Text = "The Text in the Window"
  97. };
  98. subWin.Add (
  99. new TextField { Y = 1, ColorScheme = Colors.ColorSchemes ["Error"], Text = "Edit me! " + loopWin.Title }
  100. );
  101. loopWin.Add (subWin);
  102. var frameView = new FrameView
  103. {
  104. X = Pos.Percent (50),
  105. Y = 1,
  106. Width = Dim.Percent (100, DimPercentMode.Position), // Or Dim.Percent (50)
  107. Height = 5,
  108. ColorScheme = Colors.ColorSchemes ["Base"],
  109. Text = "The Text in the FrameView",
  110. Title = "This is a Sub-FrameView"
  111. };
  112. frameView.Add (
  113. new TextField { Y = 1, Text = "Edit Me!" }
  114. );
  115. loopWin.Add (frameView);
  116. app.Add (loopWin);
  117. listWin.Add (loopWin);
  118. }
  119. FrameView frame = null;
  120. frame = new()
  121. {
  122. X = margin,
  123. Y = Pos.Bottom (listWin.Last ()) + margin / 2,
  124. Width = Dim.Fill (margin),
  125. Height = contentHeight + 2, // 2 for default padding
  126. Title = "This is a FrameView"
  127. };
  128. frame.ColorScheme = Colors.ColorSchemes ["Dialog"];
  129. frame.Add (
  130. new Label
  131. {
  132. X = Pos.Center (), Y = 0, ColorScheme = Colors.ColorSchemes ["Error"], Text = "This is a Label! (Y = 0)"
  133. }
  134. );
  135. var subWinofFV = new Window
  136. {
  137. Title = "This is a Sub-Window",
  138. X = Pos.Percent (0),
  139. Y = 1,
  140. Width = Dim.Percent (50),
  141. Height = Dim.Fill () - 1,
  142. ColorScheme = Colors.ColorSchemes ["Base"],
  143. Text = "The Text in the Window"
  144. };
  145. subWinofFV.Add (
  146. new TextField { ColorScheme = Colors.ColorSchemes ["Error"], Text = "Edit Me" }
  147. );
  148. subWinofFV.Add (new CheckBox { Y = 1, Text = "Check me" });
  149. subWinofFV.Add (new CheckBox { Y = 2, Text = "Or, Check me" });
  150. frame.Add (subWinofFV);
  151. var subFrameViewofFV = new FrameView
  152. {
  153. X = Pos.Percent (50),
  154. Y = 1,
  155. Width = Dim.Percent (100),
  156. Height = Dim.Fill () - 1,
  157. ColorScheme = Colors.ColorSchemes ["Base"],
  158. Text = "The Text in the FrameView",
  159. Title = "this is a Sub-FrameView"
  160. };
  161. subFrameViewofFV.Add (new TextField { Width = 15, Text = "Edit Me" });
  162. subFrameViewofFV.Add (new CheckBox { Y = 1, Text = "Check me" });
  163. subFrameViewofFV.Add (new CheckBox { Y = 2, Text = "Or, Check me" });
  164. frame.Add (
  165. new CheckBox { X = 0, Y = Pos.AnchorEnd (), Text = "Btn1 (Y = Pos.AnchorEnd ())" }
  166. );
  167. var c = new CheckBox { X = Pos.AnchorEnd (), Y = Pos.AnchorEnd (), Text = "Btn2 (Y = Pos.AnchorEnd ())" };
  168. frame.Add (c);
  169. frame.Add (subFrameViewofFV);
  170. app.Add (frame);
  171. listWin.Add (frame);
  172. app.ColorScheme = Colors.ColorSchemes ["Base"];
  173. Application.Run (app);
  174. app.Dispose ();
  175. }
  176. }