CenteredWindowInsideWindow.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. using Terminal.Gui;
  2. namespace UICatalog.Scenarios {
  3. [ScenarioMetadata (Name: "CenteredWindowInsideWindow", Description: "Centered Window Inside Window")]
  4. [ScenarioCategory ("Controls")]
  5. public class CenteredWindowInsideWindow : Scenario {
  6. public override void Init (ColorScheme colorScheme)
  7. {
  8. Application.Run<ParentWindowClass> ();
  9. Application.Shutdown ();
  10. }
  11. public override void Run ()
  12. {
  13. }
  14. }
  15. //------------------------------------------------------------------------------
  16. // <auto-generated>
  17. // This code was generated by:
  18. // TerminalGuiDesigner v1.0.24.0
  19. // You can make changes to this file and they will not be overwritten when saving.
  20. // </auto-generated>
  21. // -----------------------------------------------------------------------------
  22. public partial class ParentWindowClass {
  23. private ChildWindowClass _childWindow;
  24. public ParentWindowClass ()
  25. {
  26. InitializeComponent ();
  27. // MenuBar
  28. createChildMenuItem.CanExecute = CanExecuteCreateChildWindow;
  29. createChildMenuItem.Action = CreateChildWindow;
  30. centerChildMenuItem.CanExecute = CanExecuteCenterChildWindow;
  31. centerChildMenuItem.Action = CenterChildWindow;
  32. hideShowChildMenuItem.CanExecute = CanExecuteHideShowChildWindow;
  33. hideShowChildMenuItem.Action = HideShowChildWindow;
  34. borderChildMenuItem.CanExecute = CanExecuteCenterChildWindow;
  35. borderChildMenuItem.Action = BorderToggleChildWindow;
  36. parentMenu.Action = BorderToggleParentWindow;
  37. // StatusBar
  38. createChildStatusItem.CanExecute = CanExecuteCreateChildWindow;
  39. createChildStatusItem.Action = CreateChildWindow;
  40. centerChildStatusItem.CanExecute = CanExecuteCenterChildWindow;
  41. centerChildStatusItem.Action = CenterChildWindow;
  42. hideShowChildStatusItem.CanExecute = CanExecuteHideShowChildWindow;
  43. hideShowChildStatusItem.Action = HideShowChildWindow;
  44. borderChildStatusItem.CanExecute = CanExecuteCenterChildWindow;
  45. borderChildStatusItem.Action = BorderToggleChildWindow;
  46. borderParentStatusItem.Action = BorderToggleParentWindow;
  47. KeyPress += ParentWindowClass_KeyPress;
  48. }
  49. private void BorderToggleParentWindow ()
  50. {
  51. if (Border.BorderStyle == BorderStyle.None) {
  52. Border.BorderStyle = BorderStyle.Single;
  53. // MenuBar
  54. parentMenu.Title = "Borderless _Parent";
  55. // StatusBar
  56. borderParentStatusItem.Title = "~CTRL-F1~ Borderless Parent";
  57. } else {
  58. Border.BorderStyle = BorderStyle.None;
  59. Border.DrawMarginFrame = false;
  60. // MenuBar
  61. parentMenu.Title = "Border _Parent";
  62. // StatusBar
  63. borderParentStatusItem.Title = "~CTRL-F1~ Border Parent";
  64. }
  65. }
  66. private void BorderToggleChildWindow ()
  67. {
  68. if (_childWindow.Border.BorderStyle == BorderStyle.None) {
  69. _childWindow.Border.BorderStyle = BorderStyle.Single;
  70. // MenuBar
  71. borderChildMenuItem.Title = "_Borderless Child";
  72. // StatusBar
  73. borderChildStatusItem.Title = "~CTRL-F2~ Borderless Child";
  74. } else {
  75. _childWindow.Border.BorderStyle = BorderStyle.None;
  76. _childWindow.Border.DrawMarginFrame = false;
  77. // MenuBar
  78. borderChildMenuItem.Title = "_Border Child";
  79. // StatusBar
  80. borderChildStatusItem.Title = "~CTRL-F2~ Border Child";
  81. }
  82. }
  83. private void ParentWindowClass_KeyPress (KeyEventEventArgs obj)
  84. {
  85. switch (obj.KeyEvent.Key) {
  86. case Key.F8:
  87. menuBar.Visible = !menuBar.Visible;
  88. obj.Handled = true;
  89. break;
  90. case Key.F10:
  91. statusBar.Visible = !statusBar.Visible;
  92. obj.Handled = true;
  93. break;
  94. }
  95. }
  96. private bool CanExecuteCreateChildWindow () => _childWindow == null;
  97. private void CreateChildWindow ()
  98. {
  99. _childWindow ??= new ChildWindowClass ();
  100. Add (_childWindow);
  101. }
  102. private bool CanExecuteCenterChildWindow () => _childWindow != null && _childWindow.Visible;
  103. private void CenterChildWindow ()
  104. {
  105. _childWindow.X = Pos.Center ();
  106. _childWindow.Y = Pos.Center ();
  107. _childWindow.SetNeedsDisplay ();
  108. }
  109. private bool CanExecuteHideShowChildWindow () => _childWindow != null;
  110. private void HideShowChildWindow ()
  111. {
  112. if (_childWindow.Visible) {
  113. _childWindow.Visible = false;
  114. // MenuBar
  115. hideShowChildMenuItem.Title = "Un_Hide Child";
  116. // StatusBar
  117. hideShowChildStatusItem.Title = "~CTRL-F7~ UnHide Child";
  118. } else {
  119. _childWindow.Visible = true;
  120. // MenuBar
  121. hideShowChildMenuItem.Title = "_Hide Child";
  122. // StatusBar
  123. hideShowChildStatusItem.Title = "~CTRL-F7~ Hide Child";
  124. }
  125. }
  126. }
  127. //------------------------------------------------------------------------------
  128. // <auto-generated>
  129. // This code was generated by:
  130. // TerminalGuiDesigner v1.0.24.0
  131. // Changes to this file may cause incorrect behavior and will be lost if
  132. // the code is regenerated.
  133. // </auto-generated>
  134. // -----------------------------------------------------------------------------
  135. public partial class ParentWindowClass : Terminal.Gui.Window {
  136. private Terminal.Gui.MenuBar menuBar;
  137. private Terminal.Gui.MenuBarItem childMenu;
  138. private Terminal.Gui.MenuItem createChildMenuItem;
  139. private Terminal.Gui.MenuItem centerChildMenuItem;
  140. private Terminal.Gui.MenuItem hideShowChildMenuItem;
  141. private Terminal.Gui.MenuItem borderChildMenuItem;
  142. private Terminal.Gui.MenuBarItem parentMenu;
  143. private Terminal.Gui.StatusBar statusBar;
  144. private Terminal.Gui.StatusItem createChildStatusItem;
  145. private Terminal.Gui.StatusItem centerChildStatusItem;
  146. private Terminal.Gui.StatusItem hideShowChildStatusItem;
  147. private Terminal.Gui.StatusItem borderChildStatusItem;
  148. private Terminal.Gui.StatusItem borderParentStatusItem;
  149. private void InitializeComponent ()
  150. {
  151. this.menuBar = new Terminal.Gui.MenuBar ();
  152. this.Width = Dim.Fill (0);
  153. this.Height = Dim.Fill (0);
  154. this.X = 0;
  155. this.Y = 0;
  156. this.Modal = false;
  157. this.Border.BorderStyle = Terminal.Gui.BorderStyle.Single;
  158. this.Border.BorderBrush = Terminal.Gui.Color.White;
  159. this.Border.Effect3D = false;
  160. this.Border.Effect3DBrush = null;
  161. this.Border.DrawMarginFrame = true;
  162. this.TextAlignment = Terminal.Gui.TextAlignment.Left;
  163. this.Title = "Parent Window (Press F8 to Hide/Show MenuBar)(Press F10 to Hide/Show StatusBar)";
  164. this.menuBar.Width = Dim.Fill (0);
  165. this.menuBar.Height = 1;
  166. this.menuBar.X = 0;
  167. this.menuBar.Y = 0;
  168. this.menuBar.Data = "menuBar";
  169. this.menuBar.TextAlignment = Terminal.Gui.TextAlignment.Left;
  170. this.childMenu = new Terminal.Gui.MenuBarItem ();
  171. this.childMenu.Title = "Ch_ild";
  172. this.parentMenu = new Terminal.Gui.MenuBarItem ();
  173. this.parentMenu.Title = "Borderless _Parent";
  174. this.menuBar.Menus = new Terminal.Gui.MenuBarItem [] {
  175. this.childMenu, this.parentMenu};
  176. this.createChildMenuItem = new Terminal.Gui.MenuItem ();
  177. this.createChildMenuItem.Title = "_Create Child";
  178. this.createChildMenuItem.Data = "createChildMenuItem";
  179. this.centerChildMenuItem = new Terminal.Gui.MenuItem ();
  180. this.centerChildMenuItem.Title = "C_enter Child";
  181. this.centerChildMenuItem.Data = "centerChildMenuItem";
  182. this.hideShowChildMenuItem = new Terminal.Gui.MenuItem ();
  183. this.hideShowChildMenuItem.Title = "_Hide Child";
  184. this.hideShowChildMenuItem.Data = "hideChildMenuItem";
  185. this.borderChildMenuItem = new Terminal.Gui.MenuItem ();
  186. this.borderChildMenuItem.Title = "_Borderless Child";
  187. this.borderChildMenuItem.Data = "borderChildMenuItem";
  188. this.childMenu.Children = new Terminal.Gui.MenuItem [] {
  189. this.createChildMenuItem, this.centerChildMenuItem, this.hideShowChildMenuItem, this.borderChildMenuItem};
  190. this.Add (this.menuBar);
  191. this.statusBar = new Terminal.Gui.StatusBar ();
  192. this.statusBar.Width = Dim.Fill ();
  193. this.statusBar.Height = 1;
  194. this.statusBar.X = 0;
  195. this.statusBar.Y = Pos.AnchorEnd (1);
  196. this.statusBar.Data = "statusBar";
  197. this.statusBar.TextAlignment = Terminal.Gui.TextAlignment.Left;
  198. this.createChildStatusItem = new Terminal.Gui.StatusItem (Key.F5 | Key.CtrlMask, "~CTRL-F5~ Create Child", null);
  199. this.createChildStatusItem.Data = "createChildStatusItem";
  200. this.centerChildStatusItem = new Terminal.Gui.StatusItem (Key.F6 | Key.CtrlMask, "~CTRL-F6~ Center Child", null);
  201. this.centerChildStatusItem.Data = "centerChildStatusItem";
  202. this.hideShowChildStatusItem = new Terminal.Gui.StatusItem (Key.F7 | Key.CtrlMask, "~CTRL-F7~ Hide Child", null);
  203. this.hideShowChildStatusItem.Data = "hideChildStatusItem";
  204. this.borderChildStatusItem = new Terminal.Gui.StatusItem (Key.F2 | Key.CtrlMask, "~CTRL-F2~ Borderless Child", null);
  205. this.borderChildStatusItem.Data = "borderChildStatusItem";
  206. this.borderParentStatusItem = new Terminal.Gui.StatusItem (Key.F1 | Key.CtrlMask, "~CTRL-F1~ Borderless Parent", null);
  207. this.borderParentStatusItem.Data = "borderParentStatusItem";
  208. this.statusBar.Items = new StatusItem [] {
  209. this.createChildStatusItem, this.centerChildStatusItem, this.hideShowChildStatusItem, this.borderChildStatusItem, this.borderParentStatusItem};
  210. this.Add (statusBar);
  211. }
  212. }
  213. //------------------------------------------------------------------------------
  214. // <auto-generated>
  215. // This code was generated by:
  216. // TerminalGuiDesigner v1.0.24.0
  217. // You can make changes to this file and they will not be overwritten when saving.
  218. // </auto-generated>
  219. // -----------------------------------------------------------------------------
  220. public partial class ChildWindowClass {
  221. public ChildWindowClass ()
  222. {
  223. InitializeComponent ();
  224. this.button1.Clicked += Button1_Clicked;
  225. }
  226. private void Button1_Clicked ()
  227. {
  228. Terminal.Gui.MessageBox.Query ("Press Me", "I hope you like the child window behavior!", "Ok");
  229. }
  230. }
  231. //------------------------------------------------------------------------------
  232. // <auto-generated>
  233. // This code was generated by:
  234. // TerminalGuiDesigner v1.0.24.0
  235. // Changes to this file may cause incorrect behavior and will be lost if
  236. // the code is regenerated.
  237. // </auto-generated>
  238. // -----------------------------------------------------------------------------
  239. public partial class ChildWindowClass : Terminal.Gui.Window {
  240. private Terminal.Gui.Button button1;
  241. private Terminal.Gui.Label Label1;
  242. private Terminal.Gui.Label Label2;
  243. private Terminal.Gui.Label Label3;
  244. private Terminal.Gui.Label Label4;
  245. private void InitializeComponent ()
  246. {
  247. this.Width = 80;
  248. this.Height = 16;
  249. this.X = Pos.Center ();
  250. this.Y = Pos.Center ();
  251. this.ColorScheme = Colors.TopLevel;
  252. this.Modal = false;
  253. this.Border.BorderStyle = Terminal.Gui.BorderStyle.Single;
  254. this.Border.BorderBrush = Terminal.Gui.Color.White;
  255. this.Border.Effect3D = false;
  256. this.Border.Effect3DBrush = null;
  257. this.Border.DrawMarginFrame = true;
  258. this.TextAlignment = Terminal.Gui.TextAlignment.Left;
  259. this.Title = "Child Window";
  260. this.button1 = new Terminal.Gui.Button ();
  261. this.button1.X = Pos.Center ();
  262. this.button1.Y = Pos.Center ();
  263. this.button1.Text = "Press Me";
  264. this.Label1 = new Terminal.Gui.Label ("TL");
  265. this.Label2 = new Terminal.Gui.Label ("TR");
  266. this.Label2.X = Pos.AnchorEnd (2);
  267. this.Label3 = new Terminal.Gui.Label ("BL");
  268. this.Label3.Y = Pos.AnchorEnd (1);
  269. this.Label4 = new Terminal.Gui.Label ("BR");
  270. this.Label4.X = Pos.AnchorEnd (2);
  271. this.Label4.Y = Pos.AnchorEnd (1);
  272. this.Add (this.button1, this.Label1, this.Label2, this.Label3, this.Label4);
  273. }
  274. }
  275. }