|
@@ -1,210 +1,5 @@
|
|
|
namespace Terminal.Gui;
|
|
|
|
|
|
-/// <summary><see cref="EventArgs"/> for <see cref="Slider{T}"/> <see cref="SliderOption{T}"/> events.</summary>
|
|
|
-public class SliderOptionEventArgs : EventArgs
|
|
|
-{
|
|
|
- /// <summary>Initializes a new instance of <see cref="SliderOptionEventArgs"/></summary>
|
|
|
- /// <param name="isSet"> indicates whether the option is set</param>
|
|
|
- public SliderOptionEventArgs (bool isSet) { IsSet = isSet; }
|
|
|
-
|
|
|
- /// <summary>Gets whether the option is set or not.</summary>
|
|
|
- public bool IsSet { get; }
|
|
|
-}
|
|
|
-
|
|
|
-/// <summary>Represents an option in a <see cref="Slider{T}"/> .</summary>
|
|
|
-/// <typeparam name="T">Data type of the option.</typeparam>
|
|
|
-public class SliderOption<T>
|
|
|
-{
|
|
|
- /// <summary>Creates a new empty instance of the <see cref="SliderOption{T}"/> class.</summary>
|
|
|
- public SliderOption () { }
|
|
|
-
|
|
|
- /// <summary>Creates a new instance of the <see cref="SliderOption{T}"/> class with values for each property.</summary>
|
|
|
- public SliderOption (string legend, Rune legendAbbr, T data)
|
|
|
- {
|
|
|
- Legend = legend;
|
|
|
- LegendAbbr = legendAbbr;
|
|
|
- Data = data;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>Event fired when the an option has changed.</summary>
|
|
|
- public event EventHandler<SliderOptionEventArgs> Changed;
|
|
|
-
|
|
|
- /// <summary>Custom data of the option.</summary>
|
|
|
- public T Data { get; set; }
|
|
|
-
|
|
|
- /// <summary>Legend of the option.</summary>
|
|
|
- public string Legend { get; set; }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Abbreviation of the Legend. When the <see cref="Slider{T}.MinimumInnerSpacing"/> too small to fit
|
|
|
- /// <see cref="Legend"/>.
|
|
|
- /// </summary>
|
|
|
- public Rune LegendAbbr { get; set; }
|
|
|
-
|
|
|
- /// <summary>Event Raised when this option is set.</summary>
|
|
|
- public event EventHandler<SliderOptionEventArgs> Set;
|
|
|
-
|
|
|
- /// <summary>Creates a human-readable string that represents this <see cref="SliderOption{T}"/>.</summary>
|
|
|
- public override string ToString () { return "{Legend=" + Legend + ", LegendAbbr=" + LegendAbbr + ", Data=" + Data + "}"; }
|
|
|
-
|
|
|
- /// <summary>Event Raised when this option is unset.</summary>
|
|
|
- public event EventHandler<SliderOptionEventArgs> UnSet;
|
|
|
-
|
|
|
- /// <summary>To Raise the <see cref="Changed"/> event from the Slider.</summary>
|
|
|
- internal void OnChanged (bool isSet) { Changed?.Invoke (this, new (isSet)); }
|
|
|
-
|
|
|
- /// <summary>To Raise the <see cref="Set"/> event from the Slider.</summary>
|
|
|
- internal void OnSet () { Set?.Invoke (this, new (true)); }
|
|
|
-
|
|
|
- /// <summary>To Raise the <see cref="UnSet"/> event from the Slider.</summary>
|
|
|
- internal void OnUnSet () { UnSet?.Invoke (this, new (false)); }
|
|
|
-}
|
|
|
-
|
|
|
-/// <summary><see cref="Slider{T}"/> Types</summary>
|
|
|
-public enum SliderType
|
|
|
-{
|
|
|
- /// <summary>
|
|
|
- /// <code>
|
|
|
- /// ├─┼─┼─┼─┼─█─┼─┼─┼─┼─┼─┼─┤
|
|
|
- /// </code>
|
|
|
- /// </summary>
|
|
|
- Single,
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// <code>
|
|
|
- /// ├─┼─█─┼─┼─█─┼─┼─┼─┼─█─┼─┤
|
|
|
- /// </code>
|
|
|
- /// </summary>
|
|
|
- Multiple,
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// <code>
|
|
|
- /// ├▒▒▒▒▒▒▒▒▒█─┼─┼─┼─┼─┼─┼─┤
|
|
|
- /// </code>
|
|
|
- /// </summary>
|
|
|
- LeftRange,
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// <code>
|
|
|
- /// ├─┼─┼─┼─┼─█▒▒▒▒▒▒▒▒▒▒▒▒▒┤
|
|
|
- /// </code>
|
|
|
- /// </summary>
|
|
|
- RightRange,
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// <code>
|
|
|
- /// ├─┼─┼─┼─┼─█▒▒▒▒▒▒▒█─┼─┼─┤
|
|
|
- /// </code>
|
|
|
- /// </summary>
|
|
|
- Range
|
|
|
-}
|
|
|
-
|
|
|
-/// <summary><see cref="Slider{T}"/> Legend Style</summary>
|
|
|
-public class SliderAttributes
|
|
|
-{
|
|
|
- /// <summary>Attribute for the Legends Container.</summary>
|
|
|
- public Attribute? EmptyAttribute { get; set; }
|
|
|
-
|
|
|
- /// <summary>Attribute for when the respective Option is NOT Set.</summary>
|
|
|
- public Attribute? NormalAttribute { get; set; }
|
|
|
-
|
|
|
- /// <summary>Attribute for when the respective Option is Set.</summary>
|
|
|
- public Attribute? SetAttribute { get; set; }
|
|
|
-}
|
|
|
-
|
|
|
-/// <summary><see cref="Slider{T}"/> Style</summary>
|
|
|
-public class SliderStyle
|
|
|
-{
|
|
|
- /// <summary>Constructs a new instance.</summary>
|
|
|
- public SliderStyle () { LegendAttributes = new (); }
|
|
|
-
|
|
|
- /// <summary>The glyph and the attribute to indicate mouse dragging.</summary>
|
|
|
- public Cell DragChar { get; set; }
|
|
|
-
|
|
|
- /// <summary>The glyph and the attribute used for empty spaces on the slider.</summary>
|
|
|
- public Cell EmptyChar { get; set; }
|
|
|
-
|
|
|
- /// <summary>The glyph and the attribute used for the end of ranges on the slider.</summary>
|
|
|
- public Cell EndRangeChar { get; set; }
|
|
|
-
|
|
|
- /// <summary>Legend attributes</summary>
|
|
|
- public SliderAttributes LegendAttributes { get; set; }
|
|
|
-
|
|
|
- /// <summary>The glyph and the attribute used for each option (tick) on the slider.</summary>
|
|
|
- public Cell OptionChar { get; set; }
|
|
|
-
|
|
|
- /// <summary>The glyph and the attribute used for filling in ranges on the slider.</summary>
|
|
|
- public Cell RangeChar { get; set; }
|
|
|
-
|
|
|
- /// <summary>The glyph and the attribute used for options (ticks) that are set on the slider.</summary>
|
|
|
- public Cell SetChar { get; set; }
|
|
|
-
|
|
|
- /// <summary>The glyph and the attribute used for spaces between options (ticks) on the slider.</summary>
|
|
|
- public Cell SpaceChar { get; set; }
|
|
|
-
|
|
|
- /// <summary>The glyph and the attribute used for the start of ranges on the slider.</summary>
|
|
|
- public Cell StartRangeChar { get; set; }
|
|
|
-}
|
|
|
-
|
|
|
-/// <summary>All <see cref="Slider{T}"/> configuration are grouped in this class.</summary>
|
|
|
-internal class SliderConfiguration
|
|
|
-{
|
|
|
- internal bool _allowEmpty;
|
|
|
- internal int _endSpacing;
|
|
|
- internal int _minInnerSpacing = 1;
|
|
|
- internal int _cachedInnerSpacing; // Currently calculated
|
|
|
- internal Orientation _legendsOrientation = Orientation.Horizontal;
|
|
|
- internal bool _rangeAllowSingle;
|
|
|
- internal bool _showEndSpacing;
|
|
|
- internal bool _showLegends;
|
|
|
- internal bool _showLegendsAbbr;
|
|
|
- internal Orientation _sliderOrientation = Orientation.Horizontal;
|
|
|
- internal int _startSpacing;
|
|
|
- internal SliderType _type = SliderType.Single;
|
|
|
- internal bool _useMinimumSize;
|
|
|
-}
|
|
|
-
|
|
|
-/// <summary><see cref="EventArgs"/> for <see cref="Slider{T}"/> events.</summary>
|
|
|
-public class SliderEventArgs<T> : EventArgs
|
|
|
-{
|
|
|
- /// <summary>Initializes a new instance of <see cref="SliderEventArgs{T}"/></summary>
|
|
|
- /// <param name="options">The current options.</param>
|
|
|
- /// <param name="focused">Index of the option that is focused. -1 if no option has the focus.</param>
|
|
|
- public SliderEventArgs (Dictionary<int, SliderOption<T>> options, int focused = -1)
|
|
|
- {
|
|
|
- Options = options;
|
|
|
- Focused = focused;
|
|
|
- Cancel = false;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>If set to true, the focus operation will be canceled, if applicable.</summary>
|
|
|
- public bool Cancel { get; set; }
|
|
|
-
|
|
|
- /// <summary>Gets or sets the index of the option that is focused.</summary>
|
|
|
- public int Focused { get; set; }
|
|
|
-
|
|
|
- /// <summary>Gets/sets whether the option is set or not.</summary>
|
|
|
- public Dictionary<int, SliderOption<T>> Options { get; set; }
|
|
|
-}
|
|
|
-
|
|
|
-/// <summary><see cref="EventArgs"/> for <see cref="Orientation"/> events.</summary>
|
|
|
-public class OrientationEventArgs : EventArgs
|
|
|
-{
|
|
|
- /// <summary>Constructs a new instance.</summary>
|
|
|
- /// <param name="orientation">the new orientation</param>
|
|
|
- public OrientationEventArgs (Orientation orientation)
|
|
|
- {
|
|
|
- Orientation = orientation;
|
|
|
- Cancel = false;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>If set to true, the orientation change operation will be canceled, if applicable.</summary>
|
|
|
- public bool Cancel { get; set; }
|
|
|
-
|
|
|
- /// <summary>The new orientation.</summary>
|
|
|
- public Orientation Orientation { get; set; }
|
|
|
-}
|
|
|
-
|
|
|
/// <summary>Slider control.</summary>
|
|
|
public class Slider : Slider<object>
|
|
|
{
|