SplitContainerExample.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using Terminal.Gui;
  2. using System;
  3. using Terminal.Gui.Graphs;
  4. using NStack;
  5. using System.Linq;
  6. namespace UICatalog.Scenarios {
  7. [ScenarioMetadata (Name: "Split Container", Description: "Demonstrates the SplitContainer functionality")]
  8. [ScenarioCategory ("Controls")]
  9. [ScenarioCategory ("LineView")]
  10. public class SplitContainerExample : Scenario {
  11. private SplitContainer splitContainer;
  12. private SplitContainer nestedSplitContainer;
  13. private MenuItem miVertical;
  14. private MenuItem miShowBoth;
  15. private MenuItem miShowPanel1;
  16. private MenuItem miShowPanel2;
  17. private MenuItem miShowNeither;
  18. private MenuItem miSplitContainer1Border;
  19. private MenuItem minestedSplitContainerBorder;
  20. /// <summary>
  21. /// Setup the scenario.
  22. /// </summary>
  23. public override void Setup ()
  24. {
  25. // Scenario Windows.
  26. Win.Title = this.GetName ();
  27. Win.Y = 1;
  28. Win.Add (new Label ("This is a SplitContainer with a minimum panel size of 4. Drag the splitter to resize:"));
  29. splitContainer = new SplitContainer {
  30. Y = 2,
  31. X = 2,
  32. Width = Dim.Fill () - 2,
  33. Height = Dim.Fill () - 1,
  34. SplitterDistance = Pos.Percent (50),
  35. };
  36. nestedSplitContainer = new SplitContainer(){
  37. Width = Dim.Fill(),
  38. Height = Dim.Fill(),
  39. Orientation = Orientation.Horizontal
  40. };
  41. splitContainer.Panel1MinSize = 4;
  42. splitContainer.Panel2MinSize = 4;
  43. Label lbl1;
  44. splitContainer.Panel1Title = "Hello";
  45. splitContainer.Panel1.Add (lbl1 = new Label ("Type Something:") { Y = 0 });
  46. splitContainer.Panel1.Add (new TextField () { Width = Dim.Fill (), Y = 0, X = Pos.Right (lbl1) + 1 });
  47. Label lbl2;
  48. splitContainer.Panel2Title = "World";
  49. splitContainer.Panel2.Add(nestedSplitContainer);
  50. nestedSplitContainer.Panel1.Add (new TextView ()
  51. {
  52. Width = Dim.Fill(),
  53. Height = Dim.Fill(),
  54. Text = GenerateLotsOfText(),
  55. AllowsTab = false,
  56. WordWrap = true,
  57. });
  58. nestedSplitContainer.IntegratedBorder = BorderStyle.None;
  59. nestedSplitContainer.Panel2.Add (lbl2 = new Label ("Type Here Too:") { Y = 0 });
  60. nestedSplitContainer.Panel2.Add (new TextField () { Width = Dim.Fill (), Y = 0, X = Pos.Right (lbl2) + 1 });
  61. nestedSplitContainer.Panel2.Add (new Label ("Here is a Text box:") { Y = 1 });
  62. nestedSplitContainer.Panel2.Add (new TextView () { Y = 2, Width = Dim.Fill (), Height = Dim.Fill (), AllowsTab = false });
  63. Win.Add (splitContainer);
  64. var menu = new MenuBar (new MenuBarItem [] {
  65. new MenuBarItem ("_File", new MenuItem [] {
  66. new MenuItem ("_Quit", "", () => Quit()),
  67. }),
  68. new MenuBarItem ("_Options", new MenuItem [] {
  69. miVertical = new MenuItem ("_Vertical", "", () => ToggleOrientation())
  70. {
  71. Checked = splitContainer.Orientation == Orientation.Vertical,
  72. CheckType = MenuItemCheckStyle.Checked
  73. },
  74. miSplitContainer1Border = new MenuItem ("_Outer Panel Border", "", () => ToggleBorder(miSplitContainer1Border, splitContainer))
  75. {
  76. Checked = splitContainer.IntegratedBorder == BorderStyle.Single,
  77. CheckType = MenuItemCheckStyle.Checked
  78. },
  79. minestedSplitContainerBorder = new MenuItem ("_Inner Panel Border", "", () => ToggleBorder(minestedSplitContainerBorder,nestedSplitContainer))
  80. {
  81. Checked = nestedSplitContainer.IntegratedBorder == BorderStyle.Single,
  82. CheckType = MenuItemCheckStyle.Checked
  83. },
  84. new MenuBarItem ("_Show", new MenuItem [] {
  85. miShowBoth = new MenuItem ("Both", "",()=>{
  86. splitContainer.Panel1.Visible = true;
  87. splitContainer.Panel2.Visible = true;
  88. UpdateShowMenuCheckedStates();
  89. }),
  90. miShowPanel1 = new MenuItem ("Panel 1", "", () => {
  91. splitContainer.Panel1.Visible = true;
  92. splitContainer.Panel2.Visible = false;
  93. UpdateShowMenuCheckedStates();
  94. }),
  95. miShowPanel2 = new MenuItem ("Panel 2", "", () => {
  96. splitContainer.Panel1.Visible = false;
  97. splitContainer.Panel2.Visible = true;
  98. UpdateShowMenuCheckedStates();
  99. }),
  100. miShowNeither = new MenuItem ("Neither", "",()=>{
  101. splitContainer.Panel1.Visible = false;
  102. splitContainer.Panel2.Visible = false;
  103. UpdateShowMenuCheckedStates();
  104. }),
  105. })
  106. }),
  107. });
  108. UpdateShowMenuCheckedStates ();
  109. Application.Top.Add (menu);
  110. }
  111. private ustring GenerateLotsOfText ()
  112. {
  113. return "Hello There ".Repeat(100);
  114. }
  115. private void UpdateShowMenuCheckedStates ()
  116. {
  117. miShowBoth.Checked = (splitContainer.Panel1.Visible) && (splitContainer.Panel2.Visible);
  118. miShowBoth.CheckType = MenuItemCheckStyle.Checked;
  119. miShowPanel1.Checked = splitContainer.Panel1.Visible && !splitContainer.Panel2.Visible;
  120. miShowPanel1.CheckType = MenuItemCheckStyle.Checked;
  121. miShowPanel2.Checked = !splitContainer.Panel1.Visible && splitContainer.Panel2.Visible;
  122. miShowPanel2.CheckType = MenuItemCheckStyle.Checked;
  123. miShowNeither.Checked = (!splitContainer.Panel1.Visible) && (!splitContainer.Panel2.Visible);
  124. miShowNeither.CheckType = MenuItemCheckStyle.Checked;
  125. }
  126. public void ToggleOrientation ()
  127. {
  128. miVertical.Checked = !miVertical.Checked;
  129. splitContainer.Orientation = miVertical.Checked ? Orientation.Vertical : Orientation.Horizontal;
  130. nestedSplitContainer.Orientation = miVertical.Checked ? Orientation.Horizontal : Orientation.Vertical;
  131. }
  132. private void ToggleBorder (MenuItem menuItem, SplitContainer splitContainer)
  133. {
  134. menuItem.Checked = !menuItem.Checked;
  135. if(menuItem.Checked) {
  136. splitContainer.IntegratedBorder = BorderStyle.Single;
  137. } else {
  138. splitContainer.IntegratedBorder = BorderStyle.None;
  139. }
  140. }
  141. private void Quit ()
  142. {
  143. Application.RequestStop ();
  144. }
  145. }
  146. }