Transparent.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #nullable enable
  2. namespace UICatalog.Scenarios;
  3. [ScenarioMetadata ("Transparent", "Testing Transparency")]
  4. public sealed class Transparent : Scenario
  5. {
  6. public override void Main ()
  7. {
  8. // Init
  9. Application.Init ();
  10. // Setup - Create a top-level application window and configure it.
  11. Window appWindow = new ()
  12. {
  13. Title = GetQuitKeyAndName (),
  14. };
  15. appWindow.BorderStyle = LineStyle.None;
  16. appWindow.SchemeName = "Error";
  17. appWindow.Text = "App Text - Centered Vertically and Horizontally.\n2nd Line of Text.\n3rd Line of Text.";
  18. appWindow.TextAlignment = Alignment.Center;
  19. appWindow.VerticalTextAlignment = Alignment.Center;
  20. appWindow.ClearingViewport += (s, e) =>
  21. {
  22. if (s is View sender)
  23. {
  24. sender.FillRect (sender.Viewport, Glyphs.Stipple);
  25. }
  26. e.Cancel = true;
  27. };
  28. ViewportSettingsEditor viewportSettingsEditor = new ViewportSettingsEditor ()
  29. {
  30. Y = Pos.AnchorEnd (),
  31. //X = Pos.Right (adornmentsEditor),
  32. AutoSelectViewToEdit = true
  33. };
  34. appWindow.Add (viewportSettingsEditor);
  35. Button appButton = new Button ()
  36. {
  37. X = 10,
  38. Y = 4,
  39. Title = "_AppButton",
  40. };
  41. appButton.Accepting += (sender, args) =>
  42. {
  43. MessageBox.Query ((sender as View)?.App, "AppButton", "Transparency is cool!", "_Ok");
  44. args.Handled = true;
  45. };
  46. appWindow.Add (appButton);
  47. var tv = new TransparentView ()
  48. {
  49. X = 3,
  50. Y = 3,
  51. Width = 50,
  52. Height = 15
  53. };
  54. appWindow.Add (tv);
  55. // Run - Start the application.
  56. Application.Run (appWindow);
  57. appWindow.Dispose ();
  58. // Shutdown - Calling Application.Shutdown is required.
  59. Application.Shutdown ();
  60. }
  61. public class TransparentView : FrameView
  62. {
  63. public TransparentView ()
  64. {
  65. Title = "Transparent View";
  66. //base.Text = "View.Text.\nThis should be opaque.\nNote how clipping works?";
  67. TextFormatter.Alignment = Alignment.Center;
  68. TextFormatter.VerticalAlignment = Alignment.Center;
  69. Arrangement = ViewArrangement.Overlapped | ViewArrangement.Resizable | ViewArrangement.Movable;
  70. ViewportSettings |= Terminal.Gui.ViewBase.ViewportSettingsFlags.Transparent | Terminal.Gui.ViewBase.ViewportSettingsFlags.TransparentMouse;
  71. BorderStyle = LineStyle.RoundedDotted;
  72. //SchemeName = "Base";
  73. var transparentSubView = new View ()
  74. {
  75. Text = "Sizable/Movable View with border. Should be opaque. No Shadow.",
  76. Id = "transparentSubView",
  77. X = 4,
  78. Y = 8,
  79. Width = 20,
  80. Height = 8,
  81. BorderStyle = LineStyle.Dashed,
  82. Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable,
  83. // ShadowStyle = ShadowStyle.Transparent,
  84. };
  85. transparentSubView.Border!.Thickness = new (1, 1, 1, 1);
  86. transparentSubView.SchemeName = "Dialog";
  87. //transparentSubView.Visible = false;
  88. Button button = new Button ()
  89. {
  90. Title = "_Opaque Shadows No Worky",
  91. X = Pos.Center (),
  92. Y = 2,
  93. SchemeName = "Dialog",
  94. };
  95. button.Accepting += (sender, args) =>
  96. {
  97. MessageBox.Query (App, "Clicked!", "Button in Transparent View", "_Ok");
  98. args.Handled = true;
  99. };
  100. //button.Visible = false;
  101. var shortcut = new Shortcut ()
  102. {
  103. Id = "shortcut",
  104. X = Pos.Center (),
  105. Y = Pos.AnchorEnd (),
  106. Title = "A _Shortcut",
  107. HelpText = "Help!",
  108. Key = Key.F11,
  109. SchemeName = "Base"
  110. };
  111. button.ClearingViewport += (sender, args) =>
  112. {
  113. args.Cancel = true;
  114. };
  115. base.Add (button);
  116. base.Add (shortcut);
  117. base.Add (transparentSubView);
  118. //Padding.Thickness = new (1);
  119. //Padding.SchemeName = "Error";
  120. Margin!.Thickness = new (1);
  121. // Margin.ViewportSettings |= Terminal.Gui.ViewportSettingsFlags.Transparent;
  122. }
  123. /// <inheritdoc />
  124. protected override bool OnClearingViewport () { return false; }
  125. /// <inheritdoc />
  126. protected override bool OnMouseEvent (MouseEventArgs mouseEvent) { return false; }
  127. }
  128. }