Transparent.cs 4.0 KB

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