BasicColors.cs 2.5 KB

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