2
0

SliderOption.cs 2.0 KB

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