ShadowStyles.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Diagnostics.Metrics;
  5. using System.Linq;
  6. namespace UICatalog.Scenarios;
  7. [ScenarioMetadata ("ShadowStyles Demo", "Demonstrates ShadowStyles Effects.")]
  8. [ScenarioCategory ("Layout")]
  9. [ScenarioCategory ("Adornments")]
  10. public class ShadowStyles : Scenario
  11. {
  12. public override void Main ()
  13. {
  14. Application.Init ();
  15. Window app = new ()
  16. {
  17. Id = "app",
  18. Title = GetQuitKeyAndName ()
  19. };
  20. var editor = new AdornmentsEditor ()
  21. {
  22. Id = "editor",
  23. AutoSelectViewToEdit = true,
  24. ShowViewIdentifier = true,
  25. };
  26. editor.Initialized += (sender, args) => editor.MarginEditor.ExpanderButton.Collapsed = false;
  27. app.Add (editor);
  28. Window shadowWindow = new ()
  29. {
  30. Id = "shadowWindow",
  31. X = Pos.Right (editor),
  32. Y = 0,
  33. Width = Dim.Percent (30),
  34. Height = Dim.Percent (30),
  35. Title = "Shadow Window",
  36. Arrangement = ViewArrangement.Movable | ViewArrangement.Overlapped,
  37. BorderStyle = LineStyle.Double,
  38. ShadowStyle = ShadowStyle.Transparent,
  39. };
  40. app.DrawingContent += (s, e) =>
  41. {
  42. app!.FillRect (app!.Viewport, Glyphs.Dot);
  43. e.Cancel = true;
  44. };
  45. var buttonInWin = new Button
  46. {
  47. Id = "buttonInWin",
  48. X = Pos.Center (),
  49. Y = Pos.Center (), Text = "Button in Window",
  50. ShadowStyle = ShadowStyle.Opaque
  51. };
  52. shadowWindow.Add (buttonInWin);
  53. app.Add (shadowWindow);
  54. Window shadowWindow2 = new ()
  55. {
  56. Id = "shadowWindow2",
  57. X = Pos.Right (editor) + 10,
  58. Y = 10,
  59. Width = Dim.Percent (30),
  60. Height = Dim.Percent (30),
  61. Title = "Shadow Window #2",
  62. Arrangement = ViewArrangement.Movable | ViewArrangement.Overlapped,
  63. BorderStyle = LineStyle.Double,
  64. ShadowStyle = ShadowStyle.Transparent,
  65. };
  66. app.Add (shadowWindow2);
  67. var button = new Button
  68. {
  69. Id = "button",
  70. X = Pos.Right (editor) + 10,
  71. Y = Pos.Center (), Text = "Button",
  72. ShadowStyle = ShadowStyle.Opaque
  73. };
  74. button.Accepting += ButtonOnAccepting;
  75. ColorPicker colorPicker = new ()
  76. {
  77. Title = "ColorPicker to illustrate highlight (currently broken)",
  78. BorderStyle = LineStyle.Dotted,
  79. Id = "colorPicker16",
  80. X = Pos.Center (),
  81. Y = Pos.AnchorEnd (),
  82. Width = Dim.Percent (80),
  83. };
  84. colorPicker.ColorChanged += (sender, args) =>
  85. {
  86. var normal = app.GetScheme ().Normal;
  87. app.SetScheme (app.GetScheme () with { Normal = new Attribute (normal.Foreground, args.Result) });
  88. };
  89. app.Add (button, colorPicker);
  90. editor.AutoSelectViewToEdit = true;
  91. editor.AutoSelectSuperView = app;
  92. editor.AutoSelectAdornments = false;
  93. Application.Run (app);
  94. app.Dispose ();
  95. Application.Shutdown ();
  96. }
  97. private void ButtonOnAccepting (object sender, CommandEventArgs e)
  98. {
  99. MessageBox.Query ((sender as View)?.App, "Hello", "You pushed the button!");
  100. e.Handled = true;
  101. }
  102. }