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