SplitContainerExample.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using Terminal.Gui;
  2. using System;
  3. using Terminal.Gui.Graphs;
  4. namespace UICatalog.Scenarios {
  5. [ScenarioMetadata (Name: "Split Container", Description: "Demonstrates the SplitContainer functionality")]
  6. [ScenarioCategory ("Controls")]
  7. [ScenarioCategory ("LineView")]
  8. public class SplitContainerExample : Scenario {
  9. private SplitContainer splitContainer;
  10. private MenuItem miVertical;
  11. private MenuItem miShowBoth;
  12. private MenuItem miShowPanel1;
  13. private MenuItem miShowPanel2;
  14. private MenuItem miShowNeither;
  15. /// <summary>
  16. /// Setup the scenario.
  17. /// </summary>
  18. public override void Setup ()
  19. {
  20. // Scenario Windows.
  21. Win.Title = this.GetName ();
  22. Win.Y = 1;
  23. Win.Add (new Label ("This is a SplitContainer with a minimum panel size of 4. Drag the splitter to resize:"));
  24. splitContainer = new SplitContainer {
  25. Y = 2,
  26. X = 2,
  27. Width = Dim.Fill () - 2,
  28. Height = Dim.Fill () - 1,
  29. SplitterDistance = Pos.Percent (50), // TODO: get this to work with drag resizing and percents
  30. };
  31. splitContainer.Panels [0].MinSize = 4;
  32. splitContainer.Panels [1].MinSize = 4;
  33. Label lbl1;
  34. splitContainer.Panels [0].Title = "Hello";
  35. splitContainer.Panels [0].Add (lbl1 = new Label ("Type Something:") { Y = 1 });
  36. splitContainer.Panels [0].Add (new TextField () { Width = Dim.Fill (), Y = 1, X = Pos.Right (lbl1) + 1 });
  37. Label lbl2;
  38. splitContainer.Panels [1].Title = "World";
  39. splitContainer.Panels [1].Add (lbl2 = new Label ("Type Here Too:") { Y = 1 });
  40. splitContainer.Panels [1].Add (new TextField () { Width = Dim.Fill (), Y = 1, X = Pos.Right (lbl2) + 1 });
  41. splitContainer.Panels [1].Add (new Label ("Here is a Text box:") { Y = 3 });
  42. splitContainer.Panels [1].Add (new TextView () { Y = 4, Width = Dim.Fill (), Height = Dim.Fill (), AllowsTab = false });
  43. Win.Add (splitContainer);
  44. var menu = new MenuBar (new MenuBarItem [] {
  45. new MenuBarItem ("_File", new MenuItem [] {
  46. new MenuItem ("_Quit", "", () => Quit()),
  47. }),
  48. new MenuBarItem ("_Options", new MenuItem [] {
  49. miVertical = new MenuItem ("_Vertical", "", () => ToggleOrientation())
  50. {
  51. Checked = splitContainer.Orientation == Orientation.Vertical,
  52. CheckType = MenuItemCheckStyle.Checked
  53. },
  54. new MenuBarItem ("_Show", new MenuItem [] {
  55. miShowBoth = new MenuItem ("Both", "",()=>{
  56. splitContainer.Panels [0].Visible = true;
  57. splitContainer.Panels [1].Visible = true;
  58. UpdateShowMenuCheckedStates();
  59. }),
  60. miShowPanel1 = new MenuItem ("Panel 1", "", () => {
  61. splitContainer.Panels [0].Visible = true;
  62. splitContainer.Panels [1].Visible = false;
  63. UpdateShowMenuCheckedStates();
  64. }),
  65. miShowPanel2 = new MenuItem ("Panel 2", "", () => {
  66. splitContainer.Panels [0].Visible = false;
  67. splitContainer.Panels [1].Visible = true;
  68. UpdateShowMenuCheckedStates();
  69. }),
  70. miShowNeither = new MenuItem ("Neither", "",()=>{
  71. splitContainer.Panels [0].Visible = false;
  72. splitContainer.Panels [1].Visible = false;
  73. UpdateShowMenuCheckedStates();
  74. }),
  75. })
  76. }),
  77. });
  78. UpdateShowMenuCheckedStates ();
  79. Application.Top.Add (menu);
  80. }
  81. private void UpdateShowMenuCheckedStates ()
  82. {
  83. miShowBoth.Checked = (splitContainer.Panels [0].Visible) && (splitContainer.Panels [1].Visible);
  84. miShowBoth.CheckType = MenuItemCheckStyle.Checked;
  85. miShowPanel1.Checked = splitContainer.Panels [0].Visible && !splitContainer.Panels [1].Visible;
  86. miShowPanel1.CheckType = MenuItemCheckStyle.Checked;
  87. miShowPanel2.Checked = !splitContainer.Panels [0].Visible && splitContainer.Panels [1].Visible;
  88. miShowPanel2.CheckType = MenuItemCheckStyle.Checked;
  89. miShowNeither.Checked = (!splitContainer.Panels [0].Visible) && (!splitContainer.Panels [1].Visible);
  90. miShowNeither.CheckType = MenuItemCheckStyle.Checked;
  91. }
  92. public void ToggleOrientation ()
  93. {
  94. miVertical.Checked = !miVertical.Checked;
  95. splitContainer.Orientation = miVertical.Checked ? Orientation.Vertical : Orientation.Horizontal;
  96. }
  97. private void Quit ()
  98. {
  99. Application.RequestStop ();
  100. }
  101. }
  102. }