WindowsAndFrameViews.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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, 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. Win.Add (new Button ($"Padding of container is {padding}") {
  54. X = Pos.Center (),
  55. Y = 0,
  56. ColorScheme = Colors.Error,
  57. Clicked = () => About()
  58. });
  59. Win.Add (new Button ("Press ME! (Y = Pos.AnchorEnd(1))") {
  60. X = Pos.Center (),
  61. Y = Pos.AnchorEnd(1),
  62. ColorScheme = Colors.Error
  63. });
  64. Top.Add (Win);
  65. listWin.Add (Win);
  66. for (var i = 0; i < 3; i++) {
  67. Window win = null;
  68. win = new Window ($"{listWin.Count} - Window Loop - padding = {i}", i) {
  69. X = margin,
  70. Y = Pos.Bottom (listWin.Last ()) + (margin),
  71. Width = Dim.Fill (margin),
  72. Height = contentHeight + (i*2) + 2,
  73. };
  74. win.ColorScheme = Colors.Dialog;
  75. win.Add (new Button ("Press me! (Y = 0)") {
  76. X = Pos.Center (),
  77. Y = 0,
  78. ColorScheme = Colors.Error,
  79. Clicked = () => MessageBox.ErrorQuery (win.Title.ToString (), "Neat?", "Yes", "No")
  80. });
  81. var subWin = new Window ("Sub Window") {
  82. X = Pos.Percent (0),
  83. Y = 1,
  84. Width = Dim.Percent (50),
  85. Height = 5,
  86. ColorScheme = Colors.Base,
  87. };
  88. subWin.Add (new TextField (win.Title.ToString ()) {
  89. ColorScheme = Colors.Error
  90. });
  91. win.Add (subWin);
  92. var frameView = new FrameView ("This is a Sub-FrameView") {
  93. X = Pos.Percent (50),
  94. Y = 1,
  95. Width = Dim.Percent (100),
  96. Height = 5,
  97. ColorScheme = Colors.Base,
  98. };
  99. frameView.Add (new TextField ("Edit Me"));
  100. win.Add (frameView);
  101. Top.Add (win);
  102. listWin.Add (win);
  103. }
  104. FrameView frame = null;
  105. frame = new FrameView ($"This is a FrameView") {
  106. X = margin,
  107. Y = Pos.Bottom (listWin.Last ()) + (margin / 2),
  108. Width = Dim.Fill (margin),
  109. Height = contentHeight + 2, // 2 for default padding
  110. };
  111. frame.ColorScheme = Colors.Dialog;
  112. frame.Add (new Label ("This is a Label! (Y = 0)") {
  113. X = Pos.Center (),
  114. Y = 0,
  115. ColorScheme = Colors.Error,
  116. //Clicked = () => MessageBox.ErrorQuery (frame.Title.ToString (), "Neat?", "Yes", "No")
  117. });
  118. var subWinofFV = new Window ("this is a Sub-Window") {
  119. X = Pos.Percent (0),
  120. Y = 1,
  121. Width = Dim.Percent (50),
  122. Height = Dim.Fill () - 1,
  123. ColorScheme = Colors.Base,
  124. };
  125. subWinofFV.Add (new TextField ("Edit Me") {
  126. ColorScheme = Colors.Error
  127. });
  128. subWinofFV.Add (new CheckBox (0, 1, "Check me"));
  129. subWinofFV.Add (new CheckBox (0, 2, "Or, Check me"));
  130. frame.Add (subWinofFV);
  131. var subFrameViewofFV = new FrameView ("this is a Sub-FrameView") {
  132. X = Pos.Percent (50),
  133. Y = 1,
  134. Width = Dim.Percent (100),
  135. Height = Dim.Fill () - 1,
  136. ColorScheme = Colors.Base,
  137. };
  138. subFrameViewofFV.Add (new TextField ("Edit Me"));
  139. subFrameViewofFV.Add (new CheckBox (0, 1, "Check me"));
  140. // BUGBUG: This checkbox is not shown even though frameViewFV has 3 rows in
  141. // its client area. #522
  142. subFrameViewofFV.Add (new CheckBox (0, 2, "Or, Check me"));
  143. frame.Add (new CheckBox ("Btn1 (Y = Pos.AnchorEnd (1))") {
  144. X = 0,
  145. Y = Pos.AnchorEnd (1),
  146. });
  147. CheckBox c = new CheckBox ("Btn2 (Y = Pos.AnchorEnd (1))") {
  148. Y = Pos.AnchorEnd (1),
  149. };
  150. c.X = Pos.AnchorEnd () - (Pos.Right (c) - Pos.Left (c));
  151. frame.Add (c);
  152. frame.Add (subFrameViewofFV);
  153. Top.Add (frame);
  154. listWin.Add (frame);
  155. }
  156. }
  157. }