InvertColors.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Terminal.Gui;
  5. namespace UICatalog.Scenarios {
  6. [ScenarioMetadata (Name: "Invert Colors", Description: "Invert the foreground and the background colors.")]
  7. [ScenarioCategory ("Colors")]
  8. public class InvertColors : Scenario {
  9. public override void Setup ()
  10. {
  11. Win.ColorScheme = Colors.TopLevel;
  12. List<Label> labels = new List<Label> ();
  13. var foreColors = Enum.GetValues (typeof (Color)).Cast<Color> ().ToArray ();
  14. for (int y = 0; y < foreColors.Length; y++) {
  15. var fore = foreColors [y];
  16. var back = foreColors [(y + 1) % foreColors.Length];
  17. var color = Application.Driver.MakeAttribute (fore, back);
  18. var label = new Label ($"{fore} on {back}") {
  19. ColorScheme = new ColorScheme (),
  20. Y = y
  21. };
  22. label.ColorScheme.Normal = color;
  23. Win.Add (label);
  24. labels.Add (label);
  25. }
  26. var button = new Button ("Invert color!") {
  27. X = Pos.Center (),
  28. Y = foreColors.Length + 1,
  29. };
  30. button.Clicked += () => {
  31. foreach (var label in labels) {
  32. var color = label.ColorScheme.Normal;
  33. color = Application.Driver.MakeAttribute (color.Background, color.Foreground);
  34. label.ColorScheme.Normal = color;
  35. label.Text = $"{color.Foreground} on {color.Background}";
  36. label.SetNeedsDisplay ();
  37. }
  38. };
  39. Win.Add (button);
  40. }
  41. }
  42. }