ViewExperiments.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using Terminal.Gui;
  3. namespace UICatalog.Scenarios;
  4. [ScenarioMetadata ("View Experiments", "v2 View Experiments")]
  5. [ScenarioCategory ("Controls")]
  6. [ScenarioCategory ("Adornments")]
  7. [ScenarioCategory ("Layout")]
  8. [ScenarioCategory ("Proof of Concept")]
  9. public class ViewExperiments : Scenario
  10. {
  11. public override void Main ()
  12. {
  13. Application.Init ();
  14. Window app = new ()
  15. {
  16. Title = GetQuitKeyAndName (),
  17. TabStop = TabBehavior.TabGroup
  18. };
  19. var editor = new AdornmentsEditor
  20. {
  21. X = 0,
  22. Y = 0,
  23. TabStop = TabBehavior.NoStop,
  24. AutoSelectViewToEdit = true,
  25. ShowViewIdentifier = true
  26. };
  27. app.Add (editor);
  28. FrameView testFrame = new ()
  29. {
  30. Title = "_1 Test Frame",
  31. X = Pos.Right (editor),
  32. Width = Dim.Fill (),
  33. Height = Dim.Fill (),
  34. };
  35. app.Add (testFrame);
  36. Button button = new ()
  37. {
  38. X = 0,
  39. Y = 0,
  40. Title = $"TopButton _{GetNextHotKey ()}",
  41. };
  42. testFrame.Add (button);
  43. button = new ()
  44. {
  45. X = Pos.AnchorEnd (),
  46. Y = Pos.AnchorEnd (),
  47. Title = $"TopButton _{GetNextHotKey ()}",
  48. };
  49. var popoverView = new View ()
  50. {
  51. X = Pos.Center (),
  52. Y = Pos.Center (),
  53. Width = 30,
  54. Height = 10,
  55. Title = "Popover",
  56. Text = "This is a popover",
  57. Visible = false,
  58. CanFocus = true,
  59. Arrangement = ViewArrangement.Resizable | ViewArrangement.Movable
  60. };
  61. popoverView.BorderStyle = LineStyle.RoundedDotted;
  62. Button popoverButton = new ()
  63. {
  64. X = Pos.Center (),
  65. Y = Pos.Center (),
  66. Title = $"_Close",
  67. };
  68. //popoverButton.Accepting += (sender, e) => Application.Popover!.Visible = false;
  69. popoverView.Add (popoverButton);
  70. button.Accepting += ButtonAccepting;
  71. void ButtonAccepting (object sender, CommandEventArgs e)
  72. {
  73. //Application.Popover = popoverView;
  74. //Application.Popover!.Visible = true;
  75. }
  76. testFrame.MouseClick += TestFrameOnMouseClick;
  77. void TestFrameOnMouseClick (object sender, MouseEventArgs e)
  78. {
  79. if (e.Flags == MouseFlags.Button3Clicked)
  80. {
  81. popoverView.X = e.ScreenPosition.X;
  82. popoverView.Y = e.ScreenPosition.Y;
  83. //Application.Popover = popoverView;
  84. //Application.Popover!.Visible = true;
  85. }
  86. }
  87. testFrame.Add (button);
  88. editor.AutoSelectViewToEdit = true;
  89. editor.AutoSelectSuperView = testFrame;
  90. editor.AutoSelectAdornments = true;
  91. Application.Run (app);
  92. popoverView.Dispose ();
  93. app.Dispose ();
  94. Application.Shutdown ();
  95. return;
  96. }
  97. private int _hotkeyCount;
  98. private char GetNextHotKey ()
  99. {
  100. return (char)((int)'A' + _hotkeyCount++);
  101. }
  102. }