WindowsAndFrameViews.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Terminal.Gui;
  4. namespace UICatalog {
  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. class WindowsAndFrameViews : Scenario {
  10. public override void Init (Toplevel top)
  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 (50, 10, "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. //about.Add (new Label ("UI Catalog is a comprehensive sample library for Terminal.Gui"));
  40. Application.Run (about);
  41. return 0;
  42. }
  43. int margin = 2;
  44. int padding = 1;
  45. int contentHeight = 7;
  46. var listWin = new List<View> ();
  47. Win = new Window ($"{listWin.Count} - Scenario: {GetName ()}", padding) {
  48. X = Pos.Center (),
  49. Y = 1,
  50. Width = Dim.Fill (10),
  51. Height = Dim.Percent (15)
  52. };
  53. Win.ColorScheme = Colors.Dialog;
  54. Win.Add (new Button ($"Padding of container is {padding}") {
  55. X = Pos.Center (),
  56. Y = 0,
  57. ColorScheme = Colors.Error,
  58. Clicked = () => About()
  59. });
  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. win.Add (new Button ("Press me! (Y = 0)") {
  77. X = Pos.Center (),
  78. Y = 0,
  79. ColorScheme = Colors.Error,
  80. Clicked = () => MessageBox.ErrorQuery (30, 10, win.Title.ToString (), "Neat?", "Yes", "No")
  81. });
  82. var subWin = new Window ("Sub Window") {
  83. X = Pos.Percent (0),
  84. Y = 1,
  85. Width = Dim.Percent (50),
  86. Height = 5,
  87. ColorScheme = Colors.Base,
  88. };
  89. subWin.Add (new TextField (win.Title.ToString ()) {
  90. ColorScheme = Colors.Error
  91. });
  92. win.Add (subWin);
  93. var frameView = new FrameView ("This is a Sub-FrameView") {
  94. X = Pos.Percent (50),
  95. Y = 1,
  96. Width = Dim.Percent (100),
  97. Height = 5,
  98. ColorScheme = Colors.Base,
  99. };
  100. frameView.Add (new TextField ("Edit Me"));
  101. win.Add (frameView);
  102. Top.Add (win);
  103. listWin.Add (win);
  104. }
  105. FrameView frame = null;
  106. frame = new FrameView ($"This is a FrameView") {
  107. X = margin,
  108. Y = Pos.Bottom (listWin.Last ()) + (margin / 2),
  109. Width = Dim.Fill (margin),
  110. Height = contentHeight + 2, // 2 for default padding
  111. };
  112. frame.ColorScheme = Colors.Dialog;
  113. frame.Add (new Label ("This is a Label! (Y = 0)") {
  114. X = Pos.Center (),
  115. Y = 0,
  116. ColorScheme = Colors.Error,
  117. //Clicked = () => MessageBox.ErrorQuery (30, 10, frame.Title.ToString (), "Neat?", "Yes", "No")
  118. });
  119. var subWinofFV = new Window ("this is a Sub-Window") {
  120. X = Pos.Percent (0),
  121. Y = 1,
  122. Width = Dim.Percent (50),
  123. Height = Dim.Fill () - 1,
  124. ColorScheme = Colors.Base,
  125. };
  126. subWinofFV.Add (new TextField ("Edit Me") {
  127. ColorScheme = Colors.Error
  128. });
  129. subWinofFV.Add (new CheckBox (0, 1, "Check me"));
  130. subWinofFV.Add (new CheckBox (0, 2, "Or, Check me"));
  131. frame.Add (subWinofFV);
  132. var subFrameViewofFV = new FrameView ("this is a Sub-FrameView") {
  133. X = Pos.Percent (50),
  134. Y = 1,
  135. Width = Dim.Percent (100),
  136. Height = Dim.Fill () - 1,
  137. ColorScheme = Colors.Base,
  138. };
  139. subFrameViewofFV.Add (new TextField ("Edit Me"));
  140. subFrameViewofFV.Add (new CheckBox (0, 1, "Check me"));
  141. // BUGBUG: This checkbox is not shown even though frameViewFV has 3 rows in
  142. // its client area. #522
  143. subFrameViewofFV.Add (new CheckBox (0, 2, "Or, Check me"));
  144. frame.Add (new CheckBox ("Btn1 (Y = Pos.AnchorEnd (1))") {
  145. X = 0,
  146. Y = Pos.AnchorEnd (1),
  147. });
  148. CheckBox c = new CheckBox ("Btn2 (Y = Pos.AnchorEnd (1))") {
  149. Y = Pos.AnchorEnd (1),
  150. };
  151. c.X = Pos.AnchorEnd () - (Pos.Right (c) - Pos.Left (c));
  152. frame.Add (c);
  153. frame.Add (subFrameViewofFV);
  154. Top.Add (frame);
  155. listWin.Add (frame);
  156. }
  157. }
  158. }