WindowsAndFrameViews.cs 5.3 KB

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