From b64f10cc6adf6a5287c87ca6ecf0f8071c1239c0 Mon Sep 17 00:00:00 2001 From: Tig Date: Fri, 17 May 2024 16:21:58 -0700 Subject: [PATCH] Slider - one type per file --- Terminal.Gui/Views/OrientationEventArgs.cs | 19 ++ Terminal.Gui/Views/Slider.cs | 205 -------------------- Terminal.Gui/Views/SliderAttributes.cs | 14 ++ Terminal.Gui/Views/SliderConfiguration.cs | 19 ++ Terminal.Gui/Views/SliderEventArgs.cs | 24 +++ Terminal.Gui/Views/SliderOption.cs | 50 +++++ Terminal.Gui/Views/SliderOptionEventArgs.cs | 12 ++ Terminal.Gui/Views/SliderStyle.cs | 35 ++++ Terminal.Gui/Views/SliderType.cs | 40 ++++ 9 files changed, 213 insertions(+), 205 deletions(-) create mode 100644 Terminal.Gui/Views/OrientationEventArgs.cs create mode 100644 Terminal.Gui/Views/SliderAttributes.cs create mode 100644 Terminal.Gui/Views/SliderConfiguration.cs create mode 100644 Terminal.Gui/Views/SliderEventArgs.cs create mode 100644 Terminal.Gui/Views/SliderOption.cs create mode 100644 Terminal.Gui/Views/SliderOptionEventArgs.cs create mode 100644 Terminal.Gui/Views/SliderStyle.cs create mode 100644 Terminal.Gui/Views/SliderType.cs diff --git a/Terminal.Gui/Views/OrientationEventArgs.cs b/Terminal.Gui/Views/OrientationEventArgs.cs new file mode 100644 index 000000000..8a633ca83 --- /dev/null +++ b/Terminal.Gui/Views/OrientationEventArgs.cs @@ -0,0 +1,19 @@ +namespace Terminal.Gui; + +/// for events. +public class OrientationEventArgs : EventArgs +{ + /// Constructs a new instance. + /// the new orientation + public OrientationEventArgs (Orientation orientation) + { + Orientation = orientation; + Cancel = false; + } + + /// If set to true, the orientation change operation will be canceled, if applicable. + public bool Cancel { get; set; } + + /// The new orientation. + public Orientation Orientation { get; set; } +} \ No newline at end of file diff --git a/Terminal.Gui/Views/Slider.cs b/Terminal.Gui/Views/Slider.cs index 2572e6536..e26eb650d 100644 --- a/Terminal.Gui/Views/Slider.cs +++ b/Terminal.Gui/Views/Slider.cs @@ -1,210 +1,5 @@ namespace Terminal.Gui; -/// for events. -public class SliderOptionEventArgs : EventArgs -{ - /// Initializes a new instance of - /// indicates whether the option is set - public SliderOptionEventArgs (bool isSet) { IsSet = isSet; } - - /// Gets whether the option is set or not. - public bool IsSet { get; } -} - -/// Represents an option in a . -/// Data type of the option. -public class SliderOption -{ - /// Creates a new empty instance of the class. - public SliderOption () { } - - /// Creates a new instance of the class with values for each property. - public SliderOption (string legend, Rune legendAbbr, T data) - { - Legend = legend; - LegendAbbr = legendAbbr; - Data = data; - } - - /// Event fired when the an option has changed. - public event EventHandler Changed; - - /// Custom data of the option. - public T Data { get; set; } - - /// Legend of the option. - public string Legend { get; set; } - - /// - /// Abbreviation of the Legend. When the too small to fit - /// . - /// - public Rune LegendAbbr { get; set; } - - /// Event Raised when this option is set. - public event EventHandler Set; - - /// Creates a human-readable string that represents this . - public override string ToString () { return "{Legend=" + Legend + ", LegendAbbr=" + LegendAbbr + ", Data=" + Data + "}"; } - - /// Event Raised when this option is unset. - public event EventHandler UnSet; - - /// To Raise the event from the Slider. - internal void OnChanged (bool isSet) { Changed?.Invoke (this, new (isSet)); } - - /// To Raise the event from the Slider. - internal void OnSet () { Set?.Invoke (this, new (true)); } - - /// To Raise the event from the Slider. - internal void OnUnSet () { UnSet?.Invoke (this, new (false)); } -} - -/// Types -public enum SliderType -{ - /// - /// - /// ├─┼─┼─┼─┼─█─┼─┼─┼─┼─┼─┼─┤ - /// - /// - Single, - - /// - /// - /// ├─┼─█─┼─┼─█─┼─┼─┼─┼─█─┼─┤ - /// - /// - Multiple, - - /// - /// - /// ├▒▒▒▒▒▒▒▒▒█─┼─┼─┼─┼─┼─┼─┤ - /// - /// - LeftRange, - - /// - /// - /// ├─┼─┼─┼─┼─█▒▒▒▒▒▒▒▒▒▒▒▒▒┤ - /// - /// - RightRange, - - /// - /// - /// ├─┼─┼─┼─┼─█▒▒▒▒▒▒▒█─┼─┼─┤ - /// - /// - Range -} - -/// Legend Style -public class SliderAttributes -{ - /// Attribute for the Legends Container. - public Attribute? EmptyAttribute { get; set; } - - /// Attribute for when the respective Option is NOT Set. - public Attribute? NormalAttribute { get; set; } - - /// Attribute for when the respective Option is Set. - public Attribute? SetAttribute { get; set; } -} - -/// Style -public class SliderStyle -{ - /// Constructs a new instance. - public SliderStyle () { LegendAttributes = new (); } - - /// The glyph and the attribute to indicate mouse dragging. - public Cell DragChar { get; set; } - - /// The glyph and the attribute used for empty spaces on the slider. - public Cell EmptyChar { get; set; } - - /// The glyph and the attribute used for the end of ranges on the slider. - public Cell EndRangeChar { get; set; } - - /// Legend attributes - public SliderAttributes LegendAttributes { get; set; } - - /// The glyph and the attribute used for each option (tick) on the slider. - public Cell OptionChar { get; set; } - - /// The glyph and the attribute used for filling in ranges on the slider. - public Cell RangeChar { get; set; } - - /// The glyph and the attribute used for options (ticks) that are set on the slider. - public Cell SetChar { get; set; } - - /// The glyph and the attribute used for spaces between options (ticks) on the slider. - public Cell SpaceChar { get; set; } - - /// The glyph and the attribute used for the start of ranges on the slider. - public Cell StartRangeChar { get; set; } -} - -/// All configuration are grouped in this class. -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; -} - -/// for events. -public class SliderEventArgs : EventArgs -{ - /// Initializes a new instance of - /// The current options. - /// Index of the option that is focused. -1 if no option has the focus. - public SliderEventArgs (Dictionary> options, int focused = -1) - { - Options = options; - Focused = focused; - Cancel = false; - } - - /// If set to true, the focus operation will be canceled, if applicable. - public bool Cancel { get; set; } - - /// Gets or sets the index of the option that is focused. - public int Focused { get; set; } - - /// Gets/sets whether the option is set or not. - public Dictionary> Options { get; set; } -} - -/// for events. -public class OrientationEventArgs : EventArgs -{ - /// Constructs a new instance. - /// the new orientation - public OrientationEventArgs (Orientation orientation) - { - Orientation = orientation; - Cancel = false; - } - - /// If set to true, the orientation change operation will be canceled, if applicable. - public bool Cancel { get; set; } - - /// The new orientation. - public Orientation Orientation { get; set; } -} - /// Slider control. public class Slider : Slider { diff --git a/Terminal.Gui/Views/SliderAttributes.cs b/Terminal.Gui/Views/SliderAttributes.cs new file mode 100644 index 000000000..6f75546dd --- /dev/null +++ b/Terminal.Gui/Views/SliderAttributes.cs @@ -0,0 +1,14 @@ +namespace Terminal.Gui; + +/// Legend Style +public class SliderAttributes +{ + /// Attribute for the Legends Container. + public Attribute? EmptyAttribute { get; set; } + + /// Attribute for when the respective Option is NOT Set. + public Attribute? NormalAttribute { get; set; } + + /// Attribute for when the respective Option is Set. + public Attribute? SetAttribute { get; set; } +} \ No newline at end of file diff --git a/Terminal.Gui/Views/SliderConfiguration.cs b/Terminal.Gui/Views/SliderConfiguration.cs new file mode 100644 index 000000000..3cadafd86 --- /dev/null +++ b/Terminal.Gui/Views/SliderConfiguration.cs @@ -0,0 +1,19 @@ +namespace Terminal.Gui; + +/// All configuration are grouped in this class. +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; +} \ No newline at end of file diff --git a/Terminal.Gui/Views/SliderEventArgs.cs b/Terminal.Gui/Views/SliderEventArgs.cs new file mode 100644 index 000000000..76c4eed90 --- /dev/null +++ b/Terminal.Gui/Views/SliderEventArgs.cs @@ -0,0 +1,24 @@ +namespace Terminal.Gui; + +/// for events. +public class SliderEventArgs : EventArgs +{ + /// Initializes a new instance of + /// The current options. + /// Index of the option that is focused. -1 if no option has the focus. + public SliderEventArgs (Dictionary> options, int focused = -1) + { + Options = options; + Focused = focused; + Cancel = false; + } + + /// If set to true, the focus operation will be canceled, if applicable. + public bool Cancel { get; set; } + + /// Gets or sets the index of the option that is focused. + public int Focused { get; set; } + + /// Gets/sets whether the option is set or not. + public Dictionary> Options { get; set; } +} \ No newline at end of file diff --git a/Terminal.Gui/Views/SliderOption.cs b/Terminal.Gui/Views/SliderOption.cs new file mode 100644 index 000000000..1cfcc1f07 --- /dev/null +++ b/Terminal.Gui/Views/SliderOption.cs @@ -0,0 +1,50 @@ +namespace Terminal.Gui; + +/// Represents an option in a . +/// Data type of the option. +public class SliderOption +{ + /// Creates a new empty instance of the class. + public SliderOption () { } + + /// Creates a new instance of the class with values for each property. + public SliderOption (string legend, Rune legendAbbr, T data) + { + Legend = legend; + LegendAbbr = legendAbbr; + Data = data; + } + + /// Event fired when the an option has changed. + public event EventHandler Changed; + + /// Custom data of the option. + public T Data { get; set; } + + /// Legend of the option. + public string Legend { get; set; } + + /// + /// Abbreviation of the Legend. When the too small to fit + /// . + /// + public Rune LegendAbbr { get; set; } + + /// Event Raised when this option is set. + public event EventHandler Set; + + /// Creates a human-readable string that represents this . + public override string ToString () { return "{Legend=" + Legend + ", LegendAbbr=" + LegendAbbr + ", Data=" + Data + "}"; } + + /// Event Raised when this option is unset. + public event EventHandler UnSet; + + /// To Raise the event from the Slider. + internal void OnChanged (bool isSet) { Changed?.Invoke (this, new (isSet)); } + + /// To Raise the event from the Slider. + internal void OnSet () { Set?.Invoke (this, new (true)); } + + /// To Raise the event from the Slider. + internal void OnUnSet () { UnSet?.Invoke (this, new (false)); } +} \ No newline at end of file diff --git a/Terminal.Gui/Views/SliderOptionEventArgs.cs b/Terminal.Gui/Views/SliderOptionEventArgs.cs new file mode 100644 index 000000000..b4b5e6936 --- /dev/null +++ b/Terminal.Gui/Views/SliderOptionEventArgs.cs @@ -0,0 +1,12 @@ +namespace Terminal.Gui; + +/// for events. +public class SliderOptionEventArgs : EventArgs +{ + /// Initializes a new instance of + /// indicates whether the option is set + public SliderOptionEventArgs (bool isSet) { IsSet = isSet; } + + /// Gets whether the option is set or not. + public bool IsSet { get; } +} \ No newline at end of file diff --git a/Terminal.Gui/Views/SliderStyle.cs b/Terminal.Gui/Views/SliderStyle.cs new file mode 100644 index 000000000..e6429d6cb --- /dev/null +++ b/Terminal.Gui/Views/SliderStyle.cs @@ -0,0 +1,35 @@ +namespace Terminal.Gui; + +/// Style +public class SliderStyle +{ + /// Constructs a new instance. + public SliderStyle () { LegendAttributes = new (); } + + /// The glyph and the attribute to indicate mouse dragging. + public Cell DragChar { get; set; } + + /// The glyph and the attribute used for empty spaces on the slider. + public Cell EmptyChar { get; set; } + + /// The glyph and the attribute used for the end of ranges on the slider. + public Cell EndRangeChar { get; set; } + + /// Legend attributes + public SliderAttributes LegendAttributes { get; set; } + + /// The glyph and the attribute used for each option (tick) on the slider. + public Cell OptionChar { get; set; } + + /// The glyph and the attribute used for filling in ranges on the slider. + public Cell RangeChar { get; set; } + + /// The glyph and the attribute used for options (ticks) that are set on the slider. + public Cell SetChar { get; set; } + + /// The glyph and the attribute used for spaces between options (ticks) on the slider. + public Cell SpaceChar { get; set; } + + /// The glyph and the attribute used for the start of ranges on the slider. + public Cell StartRangeChar { get; set; } +} \ No newline at end of file diff --git a/Terminal.Gui/Views/SliderType.cs b/Terminal.Gui/Views/SliderType.cs new file mode 100644 index 000000000..7cbde908a --- /dev/null +++ b/Terminal.Gui/Views/SliderType.cs @@ -0,0 +1,40 @@ +namespace Terminal.Gui; + +/// Types +public enum SliderType +{ + /// + /// + /// ├─┼─┼─┼─┼─█─┼─┼─┼─┼─┼─┼─┤ + /// + /// + Single, + + /// + /// + /// ├─┼─█─┼─┼─█─┼─┼─┼─┼─█─┼─┤ + /// + /// + Multiple, + + /// + /// + /// ├▒▒▒▒▒▒▒▒▒█─┼─┼─┼─┼─┼─┼─┤ + /// + /// + LeftRange, + + /// + /// + /// ├─┼─┼─┼─┼─█▒▒▒▒▒▒▒▒▒▒▒▒▒┤ + /// + /// + RightRange, + + /// + /// + /// ├─┼─┼─┼─┼─█▒▒▒▒▒▒▒█─┼─┼─┤ + /// + /// + Range +} \ No newline at end of file