BasicColors.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using Terminal.Gui;
  3. namespace UICatalog.Scenarios;
  4. [ScenarioMetadata ("Basic Colors", "Show all basic colors.")]
  5. [ScenarioCategory ("Colors")]
  6. [ScenarioCategory ("Text and Formatting")]
  7. public class BasicColors : Scenario
  8. {
  9. public override void Main ()
  10. {
  11. Application.Init ();
  12. Window app = new ()
  13. {
  14. Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
  15. };
  16. var vx = 30;
  17. var x = 30;
  18. var y = 14;
  19. Array colors = Enum.GetValues (typeof (ColorName));
  20. foreach (ColorName bg in colors)
  21. {
  22. var attr = new Attribute (bg, colors.Length - 1 - bg);
  23. var vl = new Label
  24. {
  25. AutoSize = false,
  26. X = vx,
  27. Y = 0,
  28. Width = 1,
  29. Height = 13,
  30. VerticalTextAlignment = VerticalTextAlignment.Bottom,
  31. ColorScheme = new ColorScheme { Normal = attr },
  32. Text = bg.ToString (),
  33. TextDirection = TextDirection.TopBottom_LeftRight
  34. };
  35. app.Add (vl);
  36. var hl = new Label
  37. {
  38. AutoSize = false,
  39. X = 15,
  40. Y = y,
  41. Width = 13,
  42. Height = 1,
  43. TextAlignment = TextAlignment.Right,
  44. ColorScheme = new ColorScheme { Normal = attr },
  45. Text = bg.ToString ()
  46. };
  47. app.Add (hl);
  48. vx++;
  49. foreach (ColorName fg in colors)
  50. {
  51. var c = new Attribute (fg, bg);
  52. var t = x.ToString ();
  53. var l = new Label
  54. {
  55. ColorScheme = new ColorScheme { Normal = c }, X = x, Y = y, Text = t [^1].ToString ()
  56. };
  57. app.Add (l);
  58. x++;
  59. }
  60. x = 30;
  61. y++;
  62. }
  63. app.Add (
  64. new Label { X = Pos.AnchorEnd (36), Text = "Mouse over to get the Attribute:" }
  65. );
  66. app.Add (new Label { X = Pos.AnchorEnd (35), Y = 2, Text = "Foreground:" });
  67. var lblForeground = new Label { X = Pos.AnchorEnd (23), Y = 2 };
  68. app.Add (lblForeground);
  69. var viewForeground = new View { X = Pos.AnchorEnd (2), Y = 2, ColorScheme = new ColorScheme (), Text = " " };
  70. app.Add (viewForeground);
  71. app.Add (new Label { X = Pos.AnchorEnd (35), Y = 4, Text = "Background:" });
  72. var lblBackground = new Label { X = Pos.AnchorEnd (23), Y = 4 };
  73. app.Add (lblBackground);
  74. var viewBackground = new View { X = Pos.AnchorEnd (2), Y = 4, ColorScheme = new ColorScheme (), Text = " " };
  75. app.Add (viewBackground);
  76. Application.MouseEvent += (s, e) =>
  77. {
  78. if (e.View != null)
  79. {
  80. Color fore = e.View.GetNormalColor ().Foreground;
  81. Color back = e.View.GetNormalColor ().Background;
  82. lblForeground.Text =
  83. $"#{fore.R:X2}{fore.G:X2}{fore.B:X2} {fore.GetClosestNamedColor ()} ";
  84. viewForeground.ColorScheme =
  85. new ColorScheme (viewForeground.ColorScheme) { Normal = new Attribute (fore, fore) };
  86. lblBackground.Text =
  87. $"#{back.R:X2}{back.G:X2}{back.B:X2} {back.GetClosestNamedColor ()} ";
  88. viewBackground.ColorScheme =
  89. new ColorScheme (viewBackground.ColorScheme) { Normal = new Attribute (back, back) };
  90. }
  91. };
  92. Application.Run (app);
  93. app.Dispose ();
  94. }
  95. }