Clipping.cs 4.9 KB

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