Clipping.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using Terminal.Gui;
  2. using Timer = System.Timers.Timer;
  3. namespace UICatalog.Scenarios;
  4. [ScenarioMetadata ("Clipping", "Demonstrates non-rectangular clip region support.")]
  5. [ScenarioCategory ("Scrolling")]
  6. [ScenarioCategory ("Layout")]
  7. [ScenarioCategory ("Arrangement")]
  8. [ScenarioCategory ("Tests")]
  9. [ScenarioCategory ("Drawing")]
  10. public class Clipping : Scenario
  11. {
  12. private int _hotkeyCount;
  13. public override void Main ()
  14. {
  15. Application.Init ();
  16. Window app = new ()
  17. {
  18. Title = GetQuitKeyAndName ()
  19. //BorderStyle = LineStyle.None
  20. };
  21. app.DrawingContent += (s, e) =>
  22. {
  23. app!.FillRect (app!.Viewport, Glyphs.Dot);
  24. e.Cancel = true;
  25. };
  26. var arrangementEditor = new ArrangementEditor
  27. {
  28. X = Pos.AnchorEnd (),
  29. Y = 0,
  30. AutoSelectViewToEdit = true
  31. };
  32. app.Add (arrangementEditor);
  33. View tiledView1 = CreateTiledView (1, 0, 0);
  34. tiledView1.Width = 30;
  35. ProgressBar tiledProgressBar1 = new ()
  36. {
  37. X = 0,
  38. Y = Pos.AnchorEnd (),
  39. Width = Dim.Fill (),
  40. Id = "tiledProgressBar",
  41. BidirectionalMarquee = true
  42. };
  43. tiledView1.Add (tiledProgressBar1);
  44. View tiledView2 = CreateTiledView (2, 4, 2);
  45. ProgressBar tiledProgressBar2 = new ()
  46. {
  47. X = 0,
  48. Y = Pos.AnchorEnd (),
  49. Width = Dim.Fill (),
  50. Id = "tiledProgressBar",
  51. BidirectionalMarquee = true,
  52. ProgressBarStyle = ProgressBarStyle.MarqueeBlocks
  53. // BorderStyle = LineStyle.Rounded
  54. };
  55. tiledView2.Add (tiledProgressBar2);
  56. app.Add (tiledView1);
  57. app.Add (tiledView2);
  58. View tiledView3 = CreateTiledView (3, 8, 4);
  59. app.Add (tiledView3);
  60. // View overlappedView1 = CreateOverlappedView (1, 30, 2);
  61. //ProgressBar progressBar = new ()
  62. //{
  63. // X = Pos.AnchorEnd (),
  64. // Y = Pos.AnchorEnd (),
  65. // Width = Dim.Fill (),
  66. // Id = "progressBar",
  67. // BorderStyle = LineStyle.Rounded
  68. //};
  69. //overlappedView1.Add (progressBar);
  70. //View overlappedView2 = CreateOverlappedView (2, 32, 4);
  71. //View overlappedView3 = CreateOverlappedView (3, 34, 6);
  72. //app.Add (overlappedView1);
  73. //app.Add (overlappedView2);
  74. //app.Add (overlappedView3);
  75. var progressTimer = new Timer (150)
  76. {
  77. AutoReset = true
  78. };
  79. progressTimer.Elapsed += (s, e) =>
  80. {
  81. tiledProgressBar1.Pulse ();
  82. tiledProgressBar2.Pulse ();
  83. Application.Wakeup ();
  84. };
  85. progressTimer.Start ();
  86. Application.Run (app);
  87. progressTimer.Stop ();
  88. app.Dispose ();
  89. Application.Shutdown ();
  90. }
  91. private View CreateOverlappedView (int id, Pos x, Pos y)
  92. {
  93. var overlapped = new View
  94. {
  95. X = x,
  96. Y = y,
  97. Height = Dim.Auto (minimumContentDim: 4),
  98. Width = Dim.Auto (minimumContentDim: 14),
  99. Title = $"Overlapped{id} _{GetNextHotKey ()}",
  100. ColorScheme = Colors.ColorSchemes ["Toplevel"],
  101. Id = $"Overlapped{id}",
  102. ShadowStyle = ShadowStyle.Transparent,
  103. BorderStyle = LineStyle.Double,
  104. CanFocus = true, // Can't drag without this? BUGBUG
  105. TabStop = TabBehavior.TabGroup,
  106. Arrangement = ViewArrangement.Movable | ViewArrangement.Overlapped | ViewArrangement.Resizable
  107. };
  108. return overlapped;
  109. }
  110. private View CreateTiledView (int id, Pos x, Pos y)
  111. {
  112. var tiled = new View
  113. {
  114. X = x,
  115. Y = y,
  116. Height = Dim.Auto (minimumContentDim: 8),
  117. Width = Dim.Auto (minimumContentDim: 15),
  118. Title = $"Tiled{id} _{GetNextHotKey ()}",
  119. Id = $"Tiled{id}",
  120. Text = $"Tiled{id}",
  121. BorderStyle = LineStyle.Single,
  122. CanFocus = true, // Can't drag without this? BUGBUG
  123. TabStop = TabBehavior.TabStop,
  124. Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable,
  125. ShadowStyle = ShadowStyle.Transparent
  126. };
  127. //tiled.Padding.Thickness = new (1);
  128. //tiled.Padding.Diagnostics = ViewDiagnosticFlags.Thickness;
  129. //tiled.Margin.Thickness = new (1);
  130. FrameView fv = new ()
  131. {
  132. Title = "FrameView",
  133. Width = 15,
  134. Height = 3
  135. };
  136. tiled.Add (fv);
  137. return tiled;
  138. }
  139. private char GetNextHotKey () { return (char)('A' + _hotkeyCount++); }
  140. }