BasicColors.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. X = vx,
  26. Y = 0,
  27. Width = 1,
  28. Height = 13,
  29. VerticalTextAlignment = Alignment.End,
  30. ColorScheme = new ColorScheme { Normal = attr },
  31. Text = bg.ToString (),
  32. TextDirection = TextDirection.TopBottom_LeftRight
  33. };
  34. app.Add (vl);
  35. var hl = new Label
  36. {
  37. X = 15,
  38. Y = y,
  39. Width = 13,
  40. Height = 1,
  41. TextAlignment = Alignment.End,
  42. ColorScheme = new ColorScheme { Normal = attr },
  43. Text = bg.ToString ()
  44. };
  45. app.Add (hl);
  46. vx++;
  47. foreach (ColorName fg in colors)
  48. {
  49. var c = new Attribute (fg, bg);
  50. var t = x.ToString ();
  51. var l = new Label
  52. {
  53. ColorScheme = new ColorScheme { Normal = c }, X = x, Y = y, Text = t [^1].ToString ()
  54. };
  55. app.Add (l);
  56. x++;
  57. }
  58. x = 30;
  59. y++;
  60. }
  61. app.Add (
  62. new Label { X = Pos.AnchorEnd (36), Text = "Mouse over to get the Attribute:" }
  63. );
  64. app.Add (new Label { X = Pos.AnchorEnd (35), Y = 2, Text = "Foreground:" });
  65. var lblForeground = new Label { X = Pos.AnchorEnd (23), Y = 2 };
  66. app.Add (lblForeground);
  67. var viewForeground = new View { X = Pos.AnchorEnd (2), Y = 2, ColorScheme = new ColorScheme (), Text = " " };
  68. app.Add (viewForeground);
  69. app.Add (new Label { X = Pos.AnchorEnd (35), Y = 4, Text = "Background:" });
  70. var lblBackground = new Label { X = Pos.AnchorEnd (23), Y = 4 };
  71. app.Add (lblBackground);
  72. var viewBackground = new View { X = Pos.AnchorEnd (2), Y = 4, ColorScheme = new ColorScheme (), Text = " " };
  73. app.Add (viewBackground);
  74. Application.MouseEvent += (s, e) =>
  75. {
  76. if (e.View != null)
  77. {
  78. Color fore = e.View.GetNormalColor ().Foreground;
  79. Color back = e.View.GetNormalColor ().Background;
  80. lblForeground.Text =
  81. $"#{fore.R:X2}{fore.G:X2}{fore.B:X2} {fore.GetClosestNamedColor ()} ";
  82. viewForeground.ColorScheme =
  83. new ColorScheme (viewForeground.ColorScheme) { Normal = new Attribute (fore, fore) };
  84. lblBackground.Text =
  85. $"#{back.R:X2}{back.G:X2}{back.B:X2} {back.GetClosestNamedColor ()} ";
  86. viewBackground.ColorScheme =
  87. new ColorScheme (viewBackground.ColorScheme) { Normal = new Attribute (back, back) };
  88. }
  89. };
  90. Application.Run (app);
  91. app.Dispose ();
  92. }
  93. }