Clipping.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. };
  83. progressTimer.Start ();
  84. Application.Run (app);
  85. progressTimer.Stop ();
  86. app.Dispose ();
  87. Application.Shutdown ();
  88. }
  89. private View CreateOverlappedView (int id, Pos x, Pos y)
  90. {
  91. var overlapped = new View
  92. {
  93. X = x,
  94. Y = y,
  95. Height = Dim.Auto (minimumContentDim: 4),
  96. Width = Dim.Auto (minimumContentDim: 14),
  97. Title = $"Overlapped{id} _{GetNextHotKey ()}",
  98. SchemeName = SchemeManager.SchemesToSchemeName(Schemes.Runnable),
  99. Id = $"Overlapped{id}",
  100. ShadowStyle = ShadowStyle.Transparent,
  101. BorderStyle = LineStyle.Double,
  102. CanFocus = true, // Can't drag without this? BUGBUG
  103. TabStop = TabBehavior.TabGroup,
  104. Arrangement = ViewArrangement.Movable | ViewArrangement.Overlapped | ViewArrangement.Resizable
  105. };
  106. return overlapped;
  107. }
  108. private View CreateTiledView (int id, Pos x, Pos y)
  109. {
  110. var tiled = new View
  111. {
  112. X = x,
  113. Y = y,
  114. Height = Dim.Auto (minimumContentDim: 8),
  115. Width = Dim.Auto (minimumContentDim: 15),
  116. Title = $"Tiled{id} _{GetNextHotKey ()}",
  117. Id = $"Tiled{id}",
  118. Text = $"Tiled{id}",
  119. BorderStyle = LineStyle.Single,
  120. CanFocus = true, // Can't drag without this? BUGBUG
  121. TabStop = TabBehavior.TabStop,
  122. Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable,
  123. ShadowStyle = ShadowStyle.Transparent
  124. };
  125. //tiled.Padding.Thickness = new (1);
  126. //tiled.Padding.Diagnostics = ViewDiagnosticFlags.Thickness;
  127. //tiled.Margin!.Thickness = new (1);
  128. FrameView fv = new ()
  129. {
  130. Title = "FrameView",
  131. Width = 15,
  132. Height = 3
  133. };
  134. tiled.Add (fv);
  135. return tiled;
  136. }
  137. private char GetNextHotKey () { return (char)('A' + _hotkeyCount++); }
  138. }