WindowsAndFrameViews.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 ($"{listWin.Count} - Scenario: {GetName ()}", padding) {
  23. X = Pos.Center (),
  24. Y = 1,
  25. Width = Dim.Fill (15),
  26. Height = 10
  27. };
  28. Win.ColorScheme = Colors.Dialog;
  29. var paddingButton = new Button ($"Padding of container is {padding}") {
  30. X = Pos.Center (),
  31. Y = 0,
  32. ColorScheme = Colors.Error,
  33. };
  34. paddingButton.Clicked += (s,e) => About ();
  35. Win.Add (paddingButton);
  36. Win.Add (new Button ("Press ME! (Y = Pos.AnchorEnd(1))") {
  37. X = Pos.Center (),
  38. Y = Pos.AnchorEnd (1),
  39. ColorScheme = Colors.Error
  40. });
  41. Application.Top.Add (Win);
  42. // add it to our list
  43. listWin.Add (Win);
  44. // create 3 more Windows in a loop, adding them Application.Top
  45. // Each with a
  46. // button
  47. // sub Window with
  48. // TextField
  49. // sub FrameView with
  50. //
  51. for (var i = 0; i < 3; i++) {
  52. Window win = null;
  53. win = new Window ($"{listWin.Count} - Window Loop - padding = {i}", i) {
  54. X = margin,
  55. Y = Pos.Bottom (listWin.Last ()) + (margin),
  56. Width = Dim.Fill (margin),
  57. Height = contentHeight + (i * 2) + 2,
  58. };
  59. win.ColorScheme = Colors.Dialog;
  60. var pressMeButton = new Button ("Press me! (Y = 0)") {
  61. X = Pos.Center (),
  62. Y = 0,
  63. ColorScheme = Colors.Error,
  64. };
  65. pressMeButton.Clicked += (s,e) =>
  66. MessageBox.ErrorQuery (win.Title.ToString (), "Neat?", "Yes", "No");
  67. win.Add (pressMeButton);
  68. var subWin = new Window ("Sub Window") {
  69. X = Pos.Percent (0),
  70. Y = 1,
  71. Width = Dim.Percent (50),
  72. Height = 5,
  73. ColorScheme = Colors.Base,
  74. Text = "The Text in the Window",
  75. };
  76. subWin.Add (new TextField ("Edit me! " + win.Title.ToString ()) {
  77. Y = 1,
  78. ColorScheme = Colors.Error
  79. });
  80. win.Add (subWin);
  81. var frameView = new FrameView ("This is a Sub-FrameView") {
  82. X = Pos.Percent (50),
  83. Y = 1,
  84. Width = Dim.Percent (100, true), // Or Dim.Percent (50)
  85. Height = 5,
  86. ColorScheme = Colors.Base,
  87. Text = "The Text in the FrameView",
  88. };
  89. frameView.Add (new TextField ("Edit Me!") {
  90. Y = 1,
  91. });
  92. win.Add (frameView);
  93. Application.Top.Add (win);
  94. listWin.Add (win);
  95. }
  96. // Add a FrameView (frame) to Application.Top
  97. // Position it at Bottom, using the list of Windows we created above.
  98. // Fill it with
  99. // a label
  100. // a SubWindow containing (subWinofFV)
  101. // a TextField
  102. // two checkboxes
  103. // a Sub FrameView containing (subFrameViewofFV)
  104. // a TextField
  105. // two CheckBoxes
  106. // a checkbox
  107. // a checkbox
  108. FrameView frame = null;
  109. frame = new FrameView ($"This is a FrameView") {
  110. X = margin,
  111. Y = Pos.Bottom (listWin.Last ()) + (margin / 2),
  112. Width = Dim.Fill (margin),
  113. Height = contentHeight + 2, // 2 for default padding
  114. };
  115. frame.ColorScheme = Colors.Dialog;
  116. frame.Add (new Label ("This is a Label! (Y = 0)") {
  117. X = Pos.Center (),
  118. Y = 0,
  119. ColorScheme = Colors.Error,
  120. //Clicked = () => MessageBox.ErrorQuery (frame.Title.ToString (), "Neat?", "Yes", "No")
  121. });
  122. var subWinofFV = new Window ("this is a Sub-Window") {
  123. X = Pos.Percent (0),
  124. Y = 1,
  125. Width = Dim.Percent (50),
  126. Height = Dim.Fill () - 1,
  127. ColorScheme = Colors.Base,
  128. Text = "The Text in the Window",
  129. };
  130. subWinofFV.Add (new TextField ("Edit Me") {
  131. ColorScheme = Colors.Error
  132. });
  133. subWinofFV.Add (new CheckBox (0, 1, "Check me"));
  134. subWinofFV.Add (new CheckBox (0, 2, "Or, Check me"));
  135. frame.Add (subWinofFV);
  136. var subFrameViewofFV = new FrameView ("this is a Sub-FrameView") {
  137. X = Pos.Percent (50),
  138. Y = 1,
  139. Width = Dim.Percent (100),
  140. Height = Dim.Fill () - 1,
  141. ColorScheme = Colors.Base,
  142. Text = "The Text in the FrameView",
  143. };
  144. subFrameViewofFV.Add (new TextField (0, 0, 15, "Edit Me"));
  145. subFrameViewofFV.Add (new CheckBox (0, 1, "Check me"));
  146. // BUGBUG: This checkbox is not shown even though frameViewFV has 3 rows in
  147. // its client area. #522
  148. subFrameViewofFV.Add (new CheckBox (0, 2, "Or, Check me"));
  149. frame.Add (new CheckBox ("Btn1 (Y = Pos.AnchorEnd (1))") {
  150. X = 0,
  151. Y = Pos.AnchorEnd (1),
  152. });
  153. CheckBox c = new CheckBox ("Btn2 (Y = Pos.AnchorEnd (1))") {
  154. Y = Pos.AnchorEnd (1),
  155. };
  156. c.X = Pos.AnchorEnd () - (Pos.Right (c) - Pos.Left (c));
  157. frame.Add (c);
  158. frame.Add (subFrameViewofFV);
  159. Application.Top.Add (frame);
  160. listWin.Add (frame);
  161. Application.Top.ColorScheme = Colors.Base;
  162. }
  163. }
  164. }