SliderOption.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #nullable disable
  2. namespace Terminal.Gui.Views;
  3. /// <summary>Represents an option in a <see cref="Slider{T}"/> .</summary>
  4. /// <typeparam name="T">Data type of the option.</typeparam>
  5. public class SliderOption<T>
  6. {
  7. /// <summary>Creates a new empty instance of the <see cref="SliderOption{T}"/> class.</summary>
  8. public SliderOption () { }
  9. /// <summary>Creates a new instance of the <see cref="SliderOption{T}"/> class with values for each property.</summary>
  10. public SliderOption (string legend, Rune legendAbbr, T data)
  11. {
  12. Legend = legend;
  13. LegendAbbr = legendAbbr;
  14. Data = data;
  15. }
  16. /// <summary>Event fired when an option has changed.</summary>
  17. public event EventHandler<SliderOptionEventArgs> Changed;
  18. /// <summary>Custom data of the option.</summary>
  19. public T Data { get; set; }
  20. /// <summary>Legend of the option.</summary>
  21. public string Legend { get; set; }
  22. /// <summary>
  23. /// Abbreviation of the Legend. When the <see cref="Slider{T}.MinimumInnerSpacing"/> too small to fit
  24. /// <see cref="Legend"/>.
  25. /// </summary>
  26. public Rune LegendAbbr { get; set; }
  27. /// <summary>Event Raised when this option is set.</summary>
  28. public event EventHandler<SliderOptionEventArgs> Set;
  29. /// <summary>Creates a human-readable string that represents this <see cref="SliderOption{T}"/>.</summary>
  30. public override string ToString () { return "{Legend=" + Legend + ", LegendAbbr=" + LegendAbbr + ", Data=" + Data + "}"; }
  31. /// <summary>Event Raised when this option is unset.</summary>
  32. public event EventHandler<SliderOptionEventArgs> UnSet;
  33. /// <summary>To Raise the <see cref="Changed"/> event from the Slider.</summary>
  34. internal void OnChanged (bool isSet) { Changed?.Invoke (this, new (isSet)); }
  35. /// <summary>To Raise the <see cref="Set"/> event from the Slider.</summary>
  36. internal void OnSet () { Set?.Invoke (this, new (true)); }
  37. /// <summary>To Raise the <see cref="UnSet"/> event from the Slider.</summary>
  38. internal void OnUnSet () { UnSet?.Invoke (this, new (false)); }
  39. }