BasicColors.cs 2.4 KB

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