ViewExperiments.cs 3.2 KB

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