WindowsAndFrameViews.cs 5.0 KB

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