From 17fcf19150d585c3211f57de0c7d5fc4085d8e14 Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 18 Nov 2024 19:22:07 -0700 Subject: [PATCH 1/4] Move Slider.* into folder --- Terminal.Gui/Views/{ => Slider}/Slider.cs | 0 Terminal.Gui/Views/{ => Slider}/SliderAttributes.cs | 0 Terminal.Gui/Views/{ => Slider}/SliderConfiguration.cs | 0 Terminal.Gui/Views/{ => Slider}/SliderEventArgs.cs | 0 Terminal.Gui/Views/{ => Slider}/SliderOption.cs | 0 Terminal.Gui/Views/{ => Slider}/SliderOptionEventArgs.cs | 0 Terminal.Gui/Views/{ => Slider}/SliderStyle.cs | 0 Terminal.Gui/Views/{ => Slider}/SliderType.cs | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename Terminal.Gui/Views/{ => Slider}/Slider.cs (100%) rename Terminal.Gui/Views/{ => Slider}/SliderAttributes.cs (100%) rename Terminal.Gui/Views/{ => Slider}/SliderConfiguration.cs (100%) rename Terminal.Gui/Views/{ => Slider}/SliderEventArgs.cs (100%) rename Terminal.Gui/Views/{ => Slider}/SliderOption.cs (100%) rename Terminal.Gui/Views/{ => Slider}/SliderOptionEventArgs.cs (100%) rename Terminal.Gui/Views/{ => Slider}/SliderStyle.cs (100%) rename Terminal.Gui/Views/{ => Slider}/SliderType.cs (100%) diff --git a/Terminal.Gui/Views/Slider.cs b/Terminal.Gui/Views/Slider/Slider.cs similarity index 100% rename from Terminal.Gui/Views/Slider.cs rename to Terminal.Gui/Views/Slider/Slider.cs diff --git a/Terminal.Gui/Views/SliderAttributes.cs b/Terminal.Gui/Views/Slider/SliderAttributes.cs similarity index 100% rename from Terminal.Gui/Views/SliderAttributes.cs rename to Terminal.Gui/Views/Slider/SliderAttributes.cs diff --git a/Terminal.Gui/Views/SliderConfiguration.cs b/Terminal.Gui/Views/Slider/SliderConfiguration.cs similarity index 100% rename from Terminal.Gui/Views/SliderConfiguration.cs rename to Terminal.Gui/Views/Slider/SliderConfiguration.cs diff --git a/Terminal.Gui/Views/SliderEventArgs.cs b/Terminal.Gui/Views/Slider/SliderEventArgs.cs similarity index 100% rename from Terminal.Gui/Views/SliderEventArgs.cs rename to Terminal.Gui/Views/Slider/SliderEventArgs.cs diff --git a/Terminal.Gui/Views/SliderOption.cs b/Terminal.Gui/Views/Slider/SliderOption.cs similarity index 100% rename from Terminal.Gui/Views/SliderOption.cs rename to Terminal.Gui/Views/Slider/SliderOption.cs diff --git a/Terminal.Gui/Views/SliderOptionEventArgs.cs b/Terminal.Gui/Views/Slider/SliderOptionEventArgs.cs similarity index 100% rename from Terminal.Gui/Views/SliderOptionEventArgs.cs rename to Terminal.Gui/Views/Slider/SliderOptionEventArgs.cs diff --git a/Terminal.Gui/Views/SliderStyle.cs b/Terminal.Gui/Views/Slider/SliderStyle.cs similarity index 100% rename from Terminal.Gui/Views/SliderStyle.cs rename to Terminal.Gui/Views/Slider/SliderStyle.cs diff --git a/Terminal.Gui/Views/SliderType.cs b/Terminal.Gui/Views/Slider/SliderType.cs similarity index 100% rename from Terminal.Gui/Views/SliderType.cs rename to Terminal.Gui/Views/Slider/SliderType.cs From 4a90ed910cfd46043040188a2bb792cee8bcad4d Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 18 Nov 2024 19:30:35 -0700 Subject: [PATCH 2/4] Slider -> RangeSlider --- .../Slider.cs => RangeSlider/RangeSlider.cs} | 84 +++++++++---------- .../RangeSliderAttributes.cs} | 2 +- .../RangeSliderConfiguration.cs} | 4 +- .../RangeSliderEventArgs.cs} | 8 +- .../RangeSliderOption.cs} | 18 ++-- .../RangeSlider/RangeSliderOptionEventArgs.cs | 12 +++ .../RangeSliderStyle.cs} | 6 +- .../RangeSliderType.cs} | 2 +- .../Views/Slider/SliderOptionEventArgs.cs | 12 --- UICatalog/Scenarios/DimAutoDemo.cs | 4 +- .../Scenarios/Editors/ArrangementEditor.cs | 18 ++-- UICatalog/Scenarios/Mouse.cs | 4 +- .../Scenarios/{Sliders.cs => RangeSliders.cs} | 52 ++++++------ UICatalog/Scenarios/ViewportSettings.cs | 4 +- .../{SliderTests.cs => RangeSliderTests.cs} | 48 +++++------ 15 files changed, 139 insertions(+), 139 deletions(-) rename Terminal.Gui/Views/{Slider/Slider.cs => RangeSlider/RangeSlider.cs} (95%) rename Terminal.Gui/Views/{Slider/SliderAttributes.cs => RangeSlider/RangeSliderAttributes.cs} (93%) rename Terminal.Gui/Views/{Slider/SliderConfiguration.cs => RangeSlider/RangeSliderConfiguration.cs} (86%) rename Terminal.Gui/Views/{Slider/SliderEventArgs.cs => RangeSlider/RangeSliderEventArgs.cs} (68%) rename Terminal.Gui/Views/{Slider/SliderOption.cs => RangeSlider/RangeSliderOption.cs} (73%) create mode 100644 Terminal.Gui/Views/RangeSlider/RangeSliderOptionEventArgs.cs rename Terminal.Gui/Views/{Slider/SliderStyle.cs => RangeSlider/RangeSliderStyle.cs} (89%) rename Terminal.Gui/Views/{Slider/SliderType.cs => RangeSlider/RangeSliderType.cs} (97%) delete mode 100644 Terminal.Gui/Views/Slider/SliderOptionEventArgs.cs rename UICatalog/Scenarios/{Sliders.cs => RangeSliders.cs} (93%) rename UnitTests/Views/{SliderTests.cs => RangeSliderTests.cs} (91%) diff --git a/Terminal.Gui/Views/Slider/Slider.cs b/Terminal.Gui/Views/RangeSlider/RangeSlider.cs similarity index 95% rename from Terminal.Gui/Views/Slider/Slider.cs rename to Terminal.Gui/Views/RangeSlider/RangeSlider.cs index ff37d513c0..08526ad3bf 100644 --- a/Terminal.Gui/Views/Slider/Slider.cs +++ b/Terminal.Gui/Views/RangeSlider/RangeSlider.cs @@ -3,15 +3,15 @@ namespace Terminal.Gui; /// Slider control. -public class Slider : Slider +public class RangeSlider : Slider { - /// Initializes a new instance of the class. - public Slider () { } + /// Initializes a new instance of the class. + public RangeSlider () { } - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// Initial slider options. /// Initial slider options. - public Slider (List options, Orientation orientation = Orientation.Horizontal) : + public RangeSlider (List options, Orientation orientation = Orientation.Horizontal) : base (options, orientation) { } } @@ -23,20 +23,20 @@ public Slider (List options, Orientation orientation = Orientation.Horiz /// public class Slider : View, IOrientation { - private readonly SliderConfiguration _config = new (); + private readonly RangeSliderConfiguration _config = new (); // List of the current set options. private readonly List _setOptions = new (); // Options - private List> _options; + private List> _options; private OrientationHelper _orientationHelper; #region Initialize private void SetInitialProperties ( - List> options, + List> options, Orientation orientation = Orientation.Horizontal ) { @@ -45,7 +45,7 @@ private void SetInitialProperties ( CanFocus = true; CursorVisibility = CursorVisibility.Default; - _options = options ?? new List> (); + _options = options ?? new List> (); _orientationHelper = new (this); // Do not use object initializer! _orientationHelper.Orientation = _config._sliderOrientation = orientation; @@ -117,10 +117,10 @@ private void SetDefaultStyle () #region Constructors - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. public Slider () : this (new ()) { } - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// Initial slider options. /// Initial slider orientation. public Slider (List options, Orientation orientation = Orientation.Horizontal) @@ -137,7 +137,7 @@ public Slider (List options, Orientation orientation = Orientation.Horizontal { var legend = e.ToString (); - return new SliderOption + return new RangeSliderOption { Data = e, Legend = legend, @@ -180,7 +180,7 @@ public override string Text else { IEnumerable list = value.Split (',').Select (x => x.Trim ()); - Options = list.Select (x => new SliderOption { Legend = x }).ToList (); + Options = list.Select (x => new RangeSliderOption { Legend = x }).ToList (); } } } @@ -212,8 +212,8 @@ public int MinimumInnerSpacing } } - /// Slider Type. - public SliderType Type + /// Slider Type. + public RangeSliderType Type { get => _config._type; set @@ -278,11 +278,11 @@ public Orientation LegendsOrientation } } - /// Slider styles. - public SliderStyle Style { get; set; } = new (); + /// Slider styles. + public RangeSliderStyle Style { get; set; } = new (); /// Set the slider options. - public List> Options + public List> Options { get => _options; @@ -347,7 +347,7 @@ public bool UseMinimumSize #region Events /// Event raised when the slider option/s changed. The dictionary contains: key = option index, value = T - public event EventHandler> OptionsChanged; + public event EventHandler> OptionsChanged; /// Overridable method called when the slider options have changed. Raises the event. public virtual void OnOptionsChanged () @@ -357,7 +357,7 @@ public virtual void OnOptionsChanged () } /// Event raised When the option is hovered with the keys or the mouse. - public event EventHandler> OptionFocused; + public event EventHandler> OptionFocused; private int _lastFocusedOption; // for Range type; the most recently focused option. Used to determine shrink direction @@ -366,7 +366,7 @@ private int /// /// if the focus change was cancelled. /// - public virtual bool OnOptionFocused (int newFocusedOption, SliderEventArgs args) + public virtual bool OnOptionFocused (int newFocusedOption, RangeSliderEventArgs args) { if (newFocusedOption > _options.Count - 1 || newFocusedOption < 0) { @@ -500,7 +500,7 @@ void CalcSpacingConfig (int size) { _config._showLegendsAbbr = true; - foreach (SliderOption o in _options.Where (op => op.LegendAbbr == default (Rune))) + foreach (RangeSliderOption o in _options.Where (op => op.LegendAbbr == default (Rune))) { o.LegendAbbr = (Rune)(o.Legend?.GetColumns () > 0 ? o.Legend [0] : ' '); } @@ -867,11 +867,11 @@ private void DrawSlider () if (_config._showEndSpacing && _config._startSpacing > 0) { SetAttribute ( - isSet && _config._type == SliderType.LeftRange + isSet && _config._type == RangeSliderType.LeftRange ? Style.RangeChar.Attribute ?? normalAttr : Style.SpaceChar.Attribute ?? normalAttr ); - Rune rune = isSet && _config._type == SliderType.LeftRange ? Style.RangeChar.Rune : Style.SpaceChar.Rune; + Rune rune = isSet && _config._type == RangeSliderType.LeftRange ? Style.RangeChar.Rune : Style.SpaceChar.Rune; for (var i = 0; i < _config._startSpacing; i++) { @@ -917,19 +917,19 @@ private void DrawSlider () { switch (_config._type) { - case SliderType.LeftRange when i <= _setOptions [0]: + case RangeSliderType.LeftRange when i <= _setOptions [0]: drawRange = i < _setOptions [0]; break; - case SliderType.RightRange when i >= _setOptions [0]: + case RangeSliderType.RightRange when i >= _setOptions [0]: drawRange = i >= _setOptions [0]; break; - case SliderType.Range when _setOptions.Count == 1: + case RangeSliderType.Range when _setOptions.Count == 1: drawRange = false; break; - case SliderType.Range when _setOptions.Count == 2: + case RangeSliderType.Range when _setOptions.Count == 2: if ((i >= _setOptions [0] && i <= _setOptions [1]) || (i >= _setOptions [1] && i <= _setOptions [0])) { @@ -1009,11 +1009,11 @@ private void DrawSlider () if (_config._showEndSpacing) { SetAttribute ( - isSet && _config._type == SliderType.RightRange + isSet && _config._type == RangeSliderType.RightRange ? Style.RangeChar.Attribute ?? normalAttr : Style.SpaceChar.Attribute ?? normalAttr ); - Rune rune = isSet && _config._type == SliderType.RightRange ? Style.RangeChar.Rune : Style.SpaceChar.Rune; + Rune rune = isSet && _config._type == RangeSliderType.RightRange ? Style.RangeChar.Rune : Style.SpaceChar.Rune; for (var i = 0; i < remaining; i++) { @@ -1100,36 +1100,36 @@ private void DrawLegends () // Check if the Option is Set. switch (_config._type) { - case SliderType.Single: - case SliderType.Multiple: + case RangeSliderType.Single: + case RangeSliderType.Multiple: if (isSet && _setOptions.Contains (i)) { isOptionSet = true; } break; - case SliderType.LeftRange: + case RangeSliderType.LeftRange: if (isSet && i <= _setOptions [0]) { isOptionSet = true; } break; - case SliderType.RightRange: + case RangeSliderType.RightRange: if (isSet && i >= _setOptions [0]) { isOptionSet = true; } break; - case SliderType.Range when _setOptions.Count == 1: + case RangeSliderType.Range when _setOptions.Count == 1: if (isSet && i == _setOptions [0]) { isOptionSet = true; } break; - case SliderType.Range: + case RangeSliderType.Range: if (isSet && ((i >= _setOptions [0] && i <= _setOptions [1]) || (i >= _setOptions [1] && i <= _setOptions [0]))) @@ -1466,7 +1466,7 @@ private void SetKeyBindings () KeyBindings.Add (Key.Space, Command.Select); } - private Dictionary> GetSetOptionDictionary () { return _setOptions.ToDictionary (e => e, e => _options [e]); } + private Dictionary> GetSetOptionDictionary () { return _setOptions.ToDictionary (e => e, e => _options [e]); } /// /// Sets or unsets based on . @@ -1505,9 +1505,9 @@ private bool SetFocusedOption () bool changed = false; switch (_config._type) { - case SliderType.Single: - case SliderType.LeftRange: - case SliderType.RightRange: + case RangeSliderType.Single: + case RangeSliderType.LeftRange: + case RangeSliderType.RightRange: if (_setOptions.Count == 1) { @@ -1538,7 +1538,7 @@ private bool SetFocusedOption () changed = true; break; - case SliderType.Multiple: + case RangeSliderType.Multiple: if (_setOptions.Contains (FocusedOption)) { if (!_config._allowEmpty && _setOptions.Count () == 1) @@ -1560,7 +1560,7 @@ private bool SetFocusedOption () break; - case SliderType.Range: + case RangeSliderType.Range: if (_config._rangeAllowSingle) { if (_setOptions.Count == 1) diff --git a/Terminal.Gui/Views/Slider/SliderAttributes.cs b/Terminal.Gui/Views/RangeSlider/RangeSliderAttributes.cs similarity index 93% rename from Terminal.Gui/Views/Slider/SliderAttributes.cs rename to Terminal.Gui/Views/RangeSlider/RangeSliderAttributes.cs index 6f75546dd3..f96bf5c075 100644 --- a/Terminal.Gui/Views/Slider/SliderAttributes.cs +++ b/Terminal.Gui/Views/RangeSlider/RangeSliderAttributes.cs @@ -1,7 +1,7 @@ namespace Terminal.Gui; /// Legend Style -public class SliderAttributes +public class RangeSliderAttributes { /// Attribute for the Legends Container. public Attribute? EmptyAttribute { get; set; } diff --git a/Terminal.Gui/Views/Slider/SliderConfiguration.cs b/Terminal.Gui/Views/RangeSlider/RangeSliderConfiguration.cs similarity index 86% rename from Terminal.Gui/Views/Slider/SliderConfiguration.cs rename to Terminal.Gui/Views/RangeSlider/RangeSliderConfiguration.cs index 3cadafd869..8c9bba1b87 100644 --- a/Terminal.Gui/Views/Slider/SliderConfiguration.cs +++ b/Terminal.Gui/Views/RangeSlider/RangeSliderConfiguration.cs @@ -1,7 +1,7 @@ namespace Terminal.Gui; /// All configuration are grouped in this class. -internal class SliderConfiguration +internal class RangeSliderConfiguration { internal bool _allowEmpty; internal int _endSpacing; @@ -14,6 +14,6 @@ internal class SliderConfiguration internal bool _showLegendsAbbr; internal Orientation _sliderOrientation = Orientation.Horizontal; internal int _startSpacing; - internal SliderType _type = SliderType.Single; + internal RangeSliderType _type = RangeSliderType.Single; internal bool _useMinimumSize; } \ No newline at end of file diff --git a/Terminal.Gui/Views/Slider/SliderEventArgs.cs b/Terminal.Gui/Views/RangeSlider/RangeSliderEventArgs.cs similarity index 68% rename from Terminal.Gui/Views/Slider/SliderEventArgs.cs rename to Terminal.Gui/Views/RangeSlider/RangeSliderEventArgs.cs index 76c4eed90a..52bf8acbec 100644 --- a/Terminal.Gui/Views/Slider/SliderEventArgs.cs +++ b/Terminal.Gui/Views/RangeSlider/RangeSliderEventArgs.cs @@ -1,12 +1,12 @@ namespace Terminal.Gui; /// for events. -public class SliderEventArgs : EventArgs +public class RangeSliderEventArgs : EventArgs { - /// Initializes a new instance of + /// 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) + public RangeSliderEventArgs (Dictionary> options, int focused = -1) { Options = options; Focused = focused; @@ -20,5 +20,5 @@ public SliderEventArgs (Dictionary> options, int focused = public int Focused { get; set; } /// Gets/sets whether the option is set or not. - public Dictionary> Options { get; set; } + public Dictionary> Options { get; set; } } \ No newline at end of file diff --git a/Terminal.Gui/Views/Slider/SliderOption.cs b/Terminal.Gui/Views/RangeSlider/RangeSliderOption.cs similarity index 73% rename from Terminal.Gui/Views/Slider/SliderOption.cs rename to Terminal.Gui/Views/RangeSlider/RangeSliderOption.cs index a3d10781dd..f191f4c5a9 100644 --- a/Terminal.Gui/Views/Slider/SliderOption.cs +++ b/Terminal.Gui/Views/RangeSlider/RangeSliderOption.cs @@ -2,13 +2,13 @@ /// Represents an option in a . /// Data type of the option. -public class SliderOption +public class RangeSliderOption { - /// Creates a new empty instance of the class. - public SliderOption () { } + /// Creates a new empty instance of the class. + public RangeSliderOption () { } - /// Creates a new instance of the class with values for each property. - public SliderOption (string legend, Rune legendAbbr, T data) + /// Creates a new instance of the class with values for each property. + public RangeSliderOption (string legend, Rune legendAbbr, T data) { Legend = legend; LegendAbbr = legendAbbr; @@ -16,7 +16,7 @@ public SliderOption (string legend, Rune legendAbbr, T data) } /// Event fired when an option has changed. - public event EventHandler Changed; + public event EventHandler Changed; /// Custom data of the option. public T Data { get; set; } @@ -31,13 +31,13 @@ public SliderOption (string legend, Rune legendAbbr, T data) public Rune LegendAbbr { get; set; } /// Event Raised when this option is set. - public event EventHandler Set; + public event EventHandler Set; - /// Creates a human-readable string that represents this . + /// 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; + public event EventHandler UnSet; /// To Raise the event from the Slider. internal void OnChanged (bool isSet) { Changed?.Invoke (this, new (isSet)); } diff --git a/Terminal.Gui/Views/RangeSlider/RangeSliderOptionEventArgs.cs b/Terminal.Gui/Views/RangeSlider/RangeSliderOptionEventArgs.cs new file mode 100644 index 0000000000..37631324ac --- /dev/null +++ b/Terminal.Gui/Views/RangeSlider/RangeSliderOptionEventArgs.cs @@ -0,0 +1,12 @@ +namespace Terminal.Gui; + +/// for events. +public class RangeSliderOptionEventArgs : EventArgs +{ + /// Initializes a new instance of + /// indicates whether the option is set + public RangeSliderOptionEventArgs (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/Slider/SliderStyle.cs b/Terminal.Gui/Views/RangeSlider/RangeSliderStyle.cs similarity index 89% rename from Terminal.Gui/Views/Slider/SliderStyle.cs rename to Terminal.Gui/Views/RangeSlider/RangeSliderStyle.cs index e6429d6cb9..84f4a6ee2e 100644 --- a/Terminal.Gui/Views/Slider/SliderStyle.cs +++ b/Terminal.Gui/Views/RangeSlider/RangeSliderStyle.cs @@ -1,10 +1,10 @@ namespace Terminal.Gui; /// Style -public class SliderStyle +public class RangeSliderStyle { /// Constructs a new instance. - public SliderStyle () { LegendAttributes = new (); } + public RangeSliderStyle () { LegendAttributes = new (); } /// The glyph and the attribute to indicate mouse dragging. public Cell DragChar { get; set; } @@ -16,7 +16,7 @@ public class SliderStyle public Cell EndRangeChar { get; set; } /// Legend attributes - public SliderAttributes LegendAttributes { get; set; } + public RangeSliderAttributes LegendAttributes { get; set; } /// The glyph and the attribute used for each option (tick) on the slider. public Cell OptionChar { get; set; } diff --git a/Terminal.Gui/Views/Slider/SliderType.cs b/Terminal.Gui/Views/RangeSlider/RangeSliderType.cs similarity index 97% rename from Terminal.Gui/Views/Slider/SliderType.cs rename to Terminal.Gui/Views/RangeSlider/RangeSliderType.cs index 7cbde908a6..eeaf6645aa 100644 --- a/Terminal.Gui/Views/Slider/SliderType.cs +++ b/Terminal.Gui/Views/RangeSlider/RangeSliderType.cs @@ -1,7 +1,7 @@ namespace Terminal.Gui; /// Types -public enum SliderType +public enum RangeSliderType { /// /// diff --git a/Terminal.Gui/Views/Slider/SliderOptionEventArgs.cs b/Terminal.Gui/Views/Slider/SliderOptionEventArgs.cs deleted file mode 100644 index b4b5e69366..0000000000 --- a/Terminal.Gui/Views/Slider/SliderOptionEventArgs.cs +++ /dev/null @@ -1,12 +0,0 @@ -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/UICatalog/Scenarios/DimAutoDemo.cs b/UICatalog/Scenarios/DimAutoDemo.cs index 9f5cf3fa95..525dd02f01 100644 --- a/UICatalog/Scenarios/DimAutoDemo.cs +++ b/UICatalog/Scenarios/DimAutoDemo.cs @@ -184,11 +184,11 @@ private static FrameView CreateSliderFrameView () }; List options = new () { "One", "Two", "Three", "Four" }; - Slider slider = new (options) + RangeSlider slider = new (options) { X = 0, Y = 0, - Type = SliderType.Multiple, + Type = RangeSliderType.Multiple, AllowEmpty = false, BorderStyle = LineStyle.Double, Title = "_Slider" diff --git a/UICatalog/Scenarios/Editors/ArrangementEditor.cs b/UICatalog/Scenarios/Editors/ArrangementEditor.cs index 947c7b4d8d..80fe328924 100644 --- a/UICatalog/Scenarios/Editors/ArrangementEditor.cs +++ b/UICatalog/Scenarios/Editors/ArrangementEditor.cs @@ -19,37 +19,37 @@ public ArrangementEditor () _arrangementSlider.Options = [ - new SliderOption + new RangeSliderOption { Legend = ViewArrangement.Movable.ToString (), Data = ViewArrangement.Movable }, - new SliderOption + new RangeSliderOption { Legend = ViewArrangement.LeftResizable.ToString (), Data = ViewArrangement.LeftResizable }, - new SliderOption + new RangeSliderOption { Legend = ViewArrangement.RightResizable.ToString (), Data = ViewArrangement.RightResizable }, - new SliderOption + new RangeSliderOption { Legend = ViewArrangement.TopResizable.ToString (), Data = ViewArrangement.TopResizable }, - new SliderOption + new RangeSliderOption { Legend = ViewArrangement.BottomResizable.ToString (), Data = ViewArrangement.BottomResizable }, - new SliderOption + new RangeSliderOption { Legend = ViewArrangement.Overlapped.ToString (), Data = ViewArrangement.Overlapped @@ -63,7 +63,7 @@ public ArrangementEditor () { Orientation = Orientation.Vertical, UseMinimumSize = true, - Type = SliderType.Multiple, + Type = RangeSliderType.Multiple, AllowEmpty = true, }; @@ -90,14 +90,14 @@ protected override void OnViewToEditChanged () private void ArrangementEditor_Initialized (object? sender, EventArgs e) { _arrangementSlider.OptionsChanged += ArrangementSliderOnOptionsChanged; } - private void ArrangementSliderOnOptionsChanged (object? sender, SliderEventArgs e) + private void ArrangementSliderOnOptionsChanged (object? sender, RangeSliderEventArgs e) { if (ViewToEdit is { }) { // Set the arrangement based on the selected options var arrangement = ViewArrangement.Fixed; - foreach (KeyValuePair> option in e.Options) + foreach (KeyValuePair> option in e.Options) { arrangement |= option.Value.Data; } diff --git a/UICatalog/Scenarios/Mouse.cs b/UICatalog/Scenarios/Mouse.cs index dd1a087895..11e1d42cc2 100644 --- a/UICatalog/Scenarios/Mouse.cs +++ b/UICatalog/Scenarios/Mouse.cs @@ -25,7 +25,7 @@ public override void Main () X = 0, Y = 0, BorderStyle = LineStyle.Single, - Type = SliderType.Multiple, + Type = RangeSliderType.Multiple, Orientation = Orientation.Vertical, UseMinimumSize = true, MinimumInnerSpacing = 0 @@ -35,7 +35,7 @@ public override void Main () .Cast () .Where (value => !value.ToString ().Contains ("None") && !value.ToString ().Contains ("All")) .Select ( - value => new SliderOption + value => new RangeSliderOption { Legend = value.ToString (), Data = value diff --git a/UICatalog/Scenarios/Sliders.cs b/UICatalog/Scenarios/RangeSliders.cs similarity index 93% rename from UICatalog/Scenarios/Sliders.cs rename to UICatalog/Scenarios/RangeSliders.cs index 7645d1753a..42dc8d5267 100644 --- a/UICatalog/Scenarios/Sliders.cs +++ b/UICatalog/Scenarios/RangeSliders.cs @@ -8,18 +8,18 @@ namespace UICatalog.Scenarios; -[ScenarioMetadata ("Sliders", "Demonstrates the Slider view.")] +[ScenarioMetadata ("RangeSliders", "Demonstrates the RangeSlider view.")] [ScenarioCategory ("Controls")] -public class Sliders : Scenario +public class RangeSliders : Scenario { public void MakeSliders (View v, List options) { - List types = Enum.GetValues (typeof (SliderType)).Cast ().ToList (); - Slider prev = null; + List types = Enum.GetValues (typeof (RangeSliderType)).Cast ().ToList (); + RangeSlider prev = null; - foreach (SliderType type in types) + foreach (RangeSliderType type in types) { - var view = new Slider (options) + var view = new RangeSlider (options) { Title = type.ToString (), X = 0, @@ -76,12 +76,12 @@ public void MakeSliders (View v, List options) 39 }; - var single = new Slider (singleOptions) + var single = new RangeSlider (singleOptions) { Title = "_Continuous", X = 0, Y = prev == null ? 0 : Pos.Bottom (prev), - Type = SliderType.Single, + Type = RangeSliderType.Single, BorderStyle = LineStyle.Single, AllowEmpty = false }; @@ -111,12 +111,12 @@ public void MakeSliders (View v, List options) List oneOption = new () { "The Only Option" }; - var one = new Slider (oneOption) + var one = new RangeSlider (oneOption) { Title = "_One Option", X = 0, Y = prev == null ? 0 : Pos.Bottom (single), - Type = SliderType.Single, + Type = RangeSliderType.Single, BorderStyle = LineStyle.Single, AllowEmpty = false }; @@ -169,7 +169,7 @@ public override void Main () X = 0, Y = 0, Width = Dim.Fill (), - Type = SliderType.Multiple, + Type = RangeSliderType.Multiple, AllowEmpty = true, BorderStyle = LineStyle.Single }; @@ -177,7 +177,7 @@ public override void Main () optionsSlider.Style.SetChar = optionsSlider.Style.SetChar with { Attribute = new Attribute (Color.BrightGreen, Color.Black) }; optionsSlider.Style.LegendAttributes.SetAttribute = new Attribute (Color.Green, Color.Black); - optionsSlider.Options = new List> + optionsSlider.Options = new List> { new () { Legend = "Legends" }, new () { Legend = "RangeAllowSingle" }, @@ -189,7 +189,7 @@ public override void Main () optionsSlider.OptionsChanged += (sender, e) => { - foreach (Slider s in app.Subviews.OfType ()) + foreach (RangeSlider s in app.Subviews.OfType ()) { s.ShowLegends = e.Options.ContainsKey (0); s.RangeAllowSingle = e.Options.ContainsKey (1); @@ -233,7 +233,7 @@ public override void Main () dimAutoUsesMin.CheckedStateChanging += (sender, e) => { - foreach (Slider s in app.Subviews.OfType ()) + foreach (RangeSlider s in app.Subviews.OfType ()) { s.UseMinimumSize = !s.UseMinimumSize; } @@ -258,7 +258,7 @@ public override void Main () { View prev = null; - foreach (Slider s in app.Subviews.OfType ()) + foreach (RangeSlider s in app.Subviews.OfType ()) { if (e.Options.ContainsKey (0)) { @@ -341,7 +341,7 @@ public override void Main () legendsOrientationSlider.OptionsChanged += (sender, e) => { - foreach (Slider s in app.Subviews.OfType ()) + foreach (RangeSlider s in app.Subviews.OfType ()) { if (e.Options.ContainsKey (0)) { @@ -404,7 +404,7 @@ public override void Main () X = Pos.Right (label) + 1 }; - innerSpacingUpDown.Value = app.Subviews.OfType ().First ().MinimumInnerSpacing; + innerSpacingUpDown.Value = app.Subviews.OfType ().First ().MinimumInnerSpacing; innerSpacingUpDown.ValueChanging += (sender, e) => { @@ -415,7 +415,7 @@ public override void Main () return; } - foreach (Slider s in app.Subviews.OfType ()) + foreach (RangeSlider s in app.Subviews.OfType ()) { s.MinimumInnerSpacing = e.NewValue; } @@ -430,7 +430,7 @@ public override void Main () #region Color Slider - foreach (Slider s in app.Subviews.OfType ()) + foreach (RangeSlider s in app.Subviews.OfType ()) { s.Style.OptionChar = s.Style.OptionChar with { Attribute = app.GetNormalColor () }; s.Style.SetChar = s.Style.SetChar with { Attribute = app.GetNormalColor () }; @@ -446,7 +446,7 @@ public override void Main () legendsOrientationSlider ) + 1, - Type = SliderType.Single, + Type = RangeSliderType.Single, BorderStyle = LineStyle.Single, AllowEmpty = false, Orientation = Orientation.Vertical, @@ -458,14 +458,14 @@ public override void Main () sliderFGColor.Style.SetChar = sliderFGColor.Style.SetChar with { Attribute = new Attribute (Color.BrightGreen, Color.Black) }; sliderFGColor.Style.LegendAttributes.SetAttribute = new Attribute (Color.Green, Color.Blue); - List> colorOptions = new (); + List> colorOptions = new (); foreach (ColorName16 colorIndex in Enum.GetValues ()) { var colorName = colorIndex.ToString (); colorOptions.Add ( - new SliderOption<(Color, Color)> + new RangeSliderOption<(Color, Color)> { Data = (new Color (colorIndex), new Color (colorIndex)), @@ -485,7 +485,7 @@ public override void Main () { (Color, Color) data = e.Options.First ().Value.Data; - foreach (Slider s in app.Subviews.OfType ()) + foreach (RangeSlider s in app.Subviews.OfType ()) { s.ColorScheme = new ColorScheme (s.ColorScheme); @@ -533,7 +533,7 @@ public override void Main () Title = "BG Color", X = Pos.Right (sliderFGColor), Y = Pos.Top (sliderFGColor), - Type = SliderType.Single, + Type = RangeSliderType.Single, BorderStyle = LineStyle.Single, AllowEmpty = false, Orientation = Orientation.Vertical, @@ -555,7 +555,7 @@ public override void Main () { (Color, Color) data = e.Options.First ().Value.Data; - foreach (Slider s in app.Subviews.OfType ()) + foreach (RangeSlider s in app.Subviews.OfType ()) { s.ColorScheme = new ColorScheme (s.ColorScheme) { @@ -585,7 +585,7 @@ public override void Main () configView.Add (eventLog); - foreach (Slider slider in app.Subviews.Where (v => v is Slider)!) + foreach (RangeSlider slider in app.Subviews.Where (v => v is RangeSlider)!) { slider.Accepting += (o, args) => { diff --git a/UICatalog/Scenarios/ViewportSettings.cs b/UICatalog/Scenarios/ViewportSettings.cs index 4842f1529f..f36e2beaa9 100644 --- a/UICatalog/Scenarios/ViewportSettings.cs +++ b/UICatalog/Scenarios/ViewportSettings.cs @@ -463,12 +463,12 @@ void AutoShowHorizontalScrollBarToggle (object sender, CancelEventArgs options = new () { "Option 1", "Option 2", "Option 3" }; - Slider slider = new (options) + RangeSlider slider = new (options) { X = 0, Y = Pos.Bottom (textField) + 1, Orientation = Orientation.Vertical, - Type = SliderType.Multiple, + Type = RangeSliderType.Multiple, AllowEmpty = false, BorderStyle = LineStyle.Double, Title = "_Slider" diff --git a/UnitTests/Views/SliderTests.cs b/UnitTests/Views/RangeSliderTests.cs similarity index 91% rename from UnitTests/Views/SliderTests.cs rename to UnitTests/Views/RangeSliderTests.cs index eaab6ba699..f4acfe536f 100644 --- a/UnitTests/Views/SliderTests.cs +++ b/UnitTests/Views/RangeSliderTests.cs @@ -8,7 +8,7 @@ public class SliderOptionTests public void OnChanged_Should_Raise_ChangedEvent () { // Arrange - SliderOption sliderOption = new (); + RangeSliderOption sliderOption = new (); var eventRaised = false; sliderOption.Changed += (sender, args) => eventRaised = true; @@ -23,7 +23,7 @@ public void OnChanged_Should_Raise_ChangedEvent () public void OnSet_Should_Raise_SetEvent () { // Arrange - SliderOption sliderOption = new (); + RangeSliderOption sliderOption = new (); var eventRaised = false; sliderOption.Set += (sender, args) => eventRaised = true; @@ -38,7 +38,7 @@ public void OnSet_Should_Raise_SetEvent () public void OnUnSet_Should_Raise_UnSetEvent () { // Arrange - SliderOption sliderOption = new (); + RangeSliderOption sliderOption = new (); var eventRaised = false; sliderOption.UnSet += (sender, args) => eventRaised = true; @@ -52,7 +52,7 @@ public void OnUnSet_Should_Raise_UnSetEvent () [Fact] public void Slider_Option_Default_Constructor () { - SliderOption o = new (); + RangeSliderOption o = new (); Assert.Null (o.Legend); Assert.Equal (default (Rune), o.LegendAbbr); Assert.Equal (default (int), o.Data); @@ -61,7 +61,7 @@ public void Slider_Option_Default_Constructor () [Fact] public void Slider_Option_Values_Constructor () { - SliderOption o = new ("1 thousand", new ('y'), 1000); + RangeSliderOption o = new ("1 thousand", new ('y'), 1000); Assert.Equal ("1 thousand", o.Legend); Assert.Equal (new ('y'), o.LegendAbbr); Assert.Equal (1000, o.Data); @@ -70,14 +70,14 @@ public void Slider_Option_Values_Constructor () [Fact] public void SliderOption_ToString_WhenEmpty () { - SliderOption sliderOption = new (); + RangeSliderOption sliderOption = new (); Assert.Equal ("{Legend=, LegendAbbr=\0, Data=}", sliderOption.ToString ()); } [Fact] public void SliderOption_ToString_WhenPopulated_WithInt () { - SliderOption sliderOption = new () { Legend = "Lord flibble", LegendAbbr = new ('l'), Data = 1 }; + RangeSliderOption sliderOption = new () { Legend = "Lord flibble", LegendAbbr = new ('l'), Data = 1 }; Assert.Equal ("{Legend=Lord flibble, LegendAbbr=l, Data=1}", sliderOption.ToString ()); } @@ -85,7 +85,7 @@ public void SliderOption_ToString_WhenPopulated_WithInt () [Fact] public void SliderOption_ToString_WhenPopulated_WithSizeF () { - SliderOption sliderOption = new () + RangeSliderOption sliderOption = new () { Legend = "Lord flibble", LegendAbbr = new ('l'), Data = new (32, 11) }; @@ -100,11 +100,11 @@ public class SliderEventArgsTests public void Constructor_Sets_Cancel_Default_To_False () { // Arrange - Dictionary> options = new (); + Dictionary> options = new (); var focused = 42; // Act - SliderEventArgs sliderEventArgs = new (options, focused); + RangeSliderEventArgs sliderEventArgs = new (options, focused); // Assert Assert.False (sliderEventArgs.Cancel); @@ -114,11 +114,11 @@ public void Constructor_Sets_Cancel_Default_To_False () public void Constructor_Sets_Focused () { // Arrange - Dictionary> options = new (); + Dictionary> options = new (); var focused = 42; // Act - SliderEventArgs sliderEventArgs = new (options, focused); + RangeSliderEventArgs sliderEventArgs = new (options, focused); // Assert Assert.Equal (focused, sliderEventArgs.Focused); @@ -128,17 +128,17 @@ public void Constructor_Sets_Focused () public void Constructor_Sets_Options () { // Arrange - Dictionary> options = new (); + Dictionary> options = new (); // Act - SliderEventArgs sliderEventArgs = new (options); + RangeSliderEventArgs sliderEventArgs = new (options); // Assert Assert.Equal (options, sliderEventArgs.Options); } } -public class SliderTests +public class RangeSliderTests { [Fact] public void Constructor_Default () @@ -154,7 +154,7 @@ public void Constructor_Default () Assert.False (slider.AllowEmpty); Assert.True (slider.ShowLegends); Assert.False (slider.ShowEndSpacing); - Assert.Equal (SliderType.Single, slider.Type); + Assert.Equal (RangeSliderType.Single, slider.Type); Assert.Equal (1, slider.MinimumInnerSpacing); Assert.True (slider.Width is DimAuto); Assert.True (slider.Height is DimAuto); @@ -225,7 +225,7 @@ public void OnOptionFocused_Event_Cancelled () // Create args with cancel set to false cancel = false; - SliderEventArgs args = + RangeSliderEventArgs args = new (new (), newFocusedOption) { Cancel = cancel }; Assert.Equal (0, slider.FocusedOption); @@ -260,7 +260,7 @@ public void OnOptionFocused_Event_Raised () var eventRaised = false; slider.OptionFocused += (sender, args) => eventRaised = true; var newFocusedOption = 1; - SliderEventArgs args = new (new (), newFocusedOption); + RangeSliderEventArgs args = new (new (), newFocusedOption); // Act slider.OnOptionFocused (newFocusedOption, args); @@ -506,10 +506,10 @@ private void DimAuto_Both_Respects_SuperView_ContentSize () List options = new () { "01234", "01234" }; - Slider slider = new (options) + RangeSlider slider = new (options) { Orientation = Orientation.Vertical, - Type = SliderType.Multiple, + Type = RangeSliderType.Multiple, }; view.Add (slider); view.BeginInit (); @@ -538,10 +538,10 @@ private void DimAuto_Width_Respects_SuperView_ContentSize () List options = new () { "01234", "01234" }; - Slider slider = new (options) + RangeSlider slider = new (options) { Orientation = Orientation.Vertical, - Type = SliderType.Multiple, + Type = RangeSliderType.Multiple, Height = 10 }; view.Add (slider); @@ -571,10 +571,10 @@ private void DimAuto_Height_Respects_SuperView_ContentSize () List options = new () { "01234", "01234" }; - Slider slider = new (options) + RangeSlider slider = new (options) { Orientation = Orientation.Vertical, - Type = SliderType.Multiple, + Type = RangeSliderType.Multiple, Width = 10, }; view.Add (slider); From 0cb1f73d2089a10bdd84d89f8d9c1ef5dc9ce1ba Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 18 Nov 2024 21:15:12 -0700 Subject: [PATCH 3/4] Tweaking RangeSlider --- Terminal.Gui/Views/RangeSlider/RangeSlider.cs | 12 +- .../RangeSlider/RangeSliderAttributes.cs | 2 +- .../RangeSlider/RangeSliderConfiguration.cs | 2 +- .../Views/RangeSlider/RangeSliderEventArgs.cs | 2 +- .../Views/RangeSlider/RangeSliderOption.cs | 4 +- .../RangeSlider/RangeSliderOptionEventArgs.cs | 2 +- .../Views/RangeSlider/RangeSliderStyle.cs | 2 +- .../Views/RangeSlider/RangeSliderType.cs | 2 +- Terminal.Gui/Views/ScrollBar/ScrollSlider.cs | 17 +- Terminal.Gui/Views/ScrollBar/Slider.cs | 361 ++++++++++++++++++ .../Scenarios/Editors/ArrangementEditor.cs | 20 +- UICatalog/Scenarios/Mouse.cs | 2 +- UICatalog/Scenarios/RangeSliders.cs | 12 +- UICatalog/Scenarios/Shortcuts.cs | 10 +- UnitTests/Views/RangeSliderTests.cs | 36 +- 15 files changed, 437 insertions(+), 49 deletions(-) create mode 100644 Terminal.Gui/Views/ScrollBar/Slider.cs diff --git a/Terminal.Gui/Views/RangeSlider/RangeSlider.cs b/Terminal.Gui/Views/RangeSlider/RangeSlider.cs index 08526ad3bf..114f31374f 100644 --- a/Terminal.Gui/Views/RangeSlider/RangeSlider.cs +++ b/Terminal.Gui/Views/RangeSlider/RangeSlider.cs @@ -3,7 +3,7 @@ namespace Terminal.Gui; /// Slider control. -public class RangeSlider : Slider +public class RangeSlider : RangeSlider { /// Initializes a new instance of the class. public RangeSlider () { } @@ -21,7 +21,7 @@ public RangeSlider (List options, Orientation orientation = Orientation. /// keyboard or mouse. /// /// -public class Slider : View, IOrientation +public class RangeSlider : View, IOrientation { private readonly RangeSliderConfiguration _config = new (); @@ -118,12 +118,12 @@ private void SetDefaultStyle () #region Constructors /// Initializes a new instance of the class. - public Slider () : this (new ()) { } + public RangeSlider () : this (new ()) { } /// Initializes a new instance of the class. /// Initial slider options. /// Initial slider orientation. - public Slider (List options, Orientation orientation = Orientation.Horizontal) + public RangeSlider (List options, Orientation orientation = Orientation.Horizontal) { if (options is null) { @@ -841,7 +841,7 @@ private string AlignText (string text, int width, Alignment alignment) private void DrawSlider () { // TODO: be more surgical on clear - ClearViewport (); +// ClearViewport (); // Attributes @@ -1172,7 +1172,7 @@ private void DrawLegends () switch (_config._legendsOrientation) { case Orientation.Horizontal: - x = 1; + x = 2; break; case Orientation.Vertical: diff --git a/Terminal.Gui/Views/RangeSlider/RangeSliderAttributes.cs b/Terminal.Gui/Views/RangeSlider/RangeSliderAttributes.cs index f96bf5c075..e992710e11 100644 --- a/Terminal.Gui/Views/RangeSlider/RangeSliderAttributes.cs +++ b/Terminal.Gui/Views/RangeSlider/RangeSliderAttributes.cs @@ -1,6 +1,6 @@ namespace Terminal.Gui; -/// Legend Style +/// Legend Style public class RangeSliderAttributes { /// Attribute for the Legends Container. diff --git a/Terminal.Gui/Views/RangeSlider/RangeSliderConfiguration.cs b/Terminal.Gui/Views/RangeSlider/RangeSliderConfiguration.cs index 8c9bba1b87..ade230bae7 100644 --- a/Terminal.Gui/Views/RangeSlider/RangeSliderConfiguration.cs +++ b/Terminal.Gui/Views/RangeSlider/RangeSliderConfiguration.cs @@ -1,6 +1,6 @@ namespace Terminal.Gui; -/// All configuration are grouped in this class. +/// All configuration are grouped in this class. internal class RangeSliderConfiguration { internal bool _allowEmpty; diff --git a/Terminal.Gui/Views/RangeSlider/RangeSliderEventArgs.cs b/Terminal.Gui/Views/RangeSlider/RangeSliderEventArgs.cs index 52bf8acbec..d75271b90e 100644 --- a/Terminal.Gui/Views/RangeSlider/RangeSliderEventArgs.cs +++ b/Terminal.Gui/Views/RangeSlider/RangeSliderEventArgs.cs @@ -1,6 +1,6 @@ namespace Terminal.Gui; -/// for events. +/// for events. public class RangeSliderEventArgs : EventArgs { /// Initializes a new instance of diff --git a/Terminal.Gui/Views/RangeSlider/RangeSliderOption.cs b/Terminal.Gui/Views/RangeSlider/RangeSliderOption.cs index f191f4c5a9..72fc02ae15 100644 --- a/Terminal.Gui/Views/RangeSlider/RangeSliderOption.cs +++ b/Terminal.Gui/Views/RangeSlider/RangeSliderOption.cs @@ -1,6 +1,6 @@ namespace Terminal.Gui; -/// Represents an option in a . +/// Represents an option in a . /// Data type of the option. public class RangeSliderOption { @@ -25,7 +25,7 @@ public RangeSliderOption (string legend, Rune legendAbbr, T data) public string Legend { get; set; } /// - /// Abbreviation of the Legend. When the too small to fit + /// Abbreviation of the Legend. When the too small to fit /// . /// public Rune LegendAbbr { get; set; } diff --git a/Terminal.Gui/Views/RangeSlider/RangeSliderOptionEventArgs.cs b/Terminal.Gui/Views/RangeSlider/RangeSliderOptionEventArgs.cs index 37631324ac..15315f3be5 100644 --- a/Terminal.Gui/Views/RangeSlider/RangeSliderOptionEventArgs.cs +++ b/Terminal.Gui/Views/RangeSlider/RangeSliderOptionEventArgs.cs @@ -1,6 +1,6 @@ namespace Terminal.Gui; -/// for events. +/// for events. public class RangeSliderOptionEventArgs : EventArgs { /// Initializes a new instance of diff --git a/Terminal.Gui/Views/RangeSlider/RangeSliderStyle.cs b/Terminal.Gui/Views/RangeSlider/RangeSliderStyle.cs index 84f4a6ee2e..3bd3816716 100644 --- a/Terminal.Gui/Views/RangeSlider/RangeSliderStyle.cs +++ b/Terminal.Gui/Views/RangeSlider/RangeSliderStyle.cs @@ -1,6 +1,6 @@ namespace Terminal.Gui; -/// Style +/// Style public class RangeSliderStyle { /// Constructs a new instance. diff --git a/Terminal.Gui/Views/RangeSlider/RangeSliderType.cs b/Terminal.Gui/Views/RangeSlider/RangeSliderType.cs index eeaf6645aa..113c456a67 100644 --- a/Terminal.Gui/Views/RangeSlider/RangeSliderType.cs +++ b/Terminal.Gui/Views/RangeSlider/RangeSliderType.cs @@ -1,6 +1,6 @@ namespace Terminal.Gui; -/// Types +/// Types public enum RangeSliderType { /// diff --git a/Terminal.Gui/Views/ScrollBar/ScrollSlider.cs b/Terminal.Gui/Views/ScrollBar/ScrollSlider.cs index 899ee56e08..d3c4bc06f8 100644 --- a/Terminal.Gui/Views/ScrollBar/ScrollSlider.cs +++ b/Terminal.Gui/Views/ScrollBar/ScrollSlider.cs @@ -79,16 +79,29 @@ public void OnOrientationChanged (Orientation newOrientation) #endregion + public string Segment { get; set; } = Glyphs.ContinuousMeterSegment.ToString(); + /// protected override bool OnClearingViewport () { if (Orientation == Orientation.Vertical) { - FillRect (Viewport with { Height = Size }, Glyphs.ContinuousMeterSegment); + for (int y = 0; y < Viewport.Height; y++) + { + for (int x = 0; x < Viewport.Width; x += Segment.GetColumns()) + { + Move (x, y); + AddStr (Segment); + } + } } else { - FillRect (Viewport with { Width = Size }, Glyphs.ContinuousMeterSegment); + for (int x = 0; x < Viewport.Width; x++) + { + Move (x, 0); + AddStr (Segment); + } } return true; } diff --git a/Terminal.Gui/Views/ScrollBar/Slider.cs b/Terminal.Gui/Views/ScrollBar/Slider.cs new file mode 100644 index 0000000000..e5c2ce361e --- /dev/null +++ b/Terminal.Gui/Views/ScrollBar/Slider.cs @@ -0,0 +1,361 @@ +#nullable enable + +using System.ComponentModel; + +namespace Terminal.Gui; + +/// +/// +/// +/// +public class Slider : View, IOrientation, IDesignable +{ + private readonly ScrollSlider _slider; + + /// + public Slider () + { + // Set the default width and height based on the orientation - fill Viewport + Width = Dim.Auto ( + DimAutoStyle.Content, + Dim.Func (() => Orientation == Orientation.Vertical ? 2 : SuperView?.Viewport.Width ?? 0)); + + Height = Dim.Auto ( + DimAutoStyle.Content, + Dim.Func (() => Orientation == Orientation.Vertical ? SuperView?.Viewport.Height ?? 0 : 1)); + + + _slider = new () + { + Segment = $" {Glyphs.RightArrow}", + }; + _slider.Scrolled += SliderOnScroll; + _slider.PositionChanged += SliderOnPositionChanged; + _slider.Size = 1; + _slider.ColorScheme = Colors.ColorSchemes ["Error"]; + + Add (_slider); + + CanFocus = true; + + _orientationHelper = new (this); // Do not use object initializer! + _orientationHelper.Orientation = Orientation.Vertical; + + // This sets the width/height etc... + OnOrientationChanged (Orientation); + + return; + } + + private void PositionSubviews () + { + if (Orientation == Orientation.Vertical) + { + + _slider.X = 0; + _slider.Y = 0; + _slider.Width = Dim.Fill (); +} + else + { + _slider.Y = 0; + _slider.X = 0; + _slider.Height = Dim.Fill (); + } + } + + #region IOrientation members + + private readonly OrientationHelper _orientationHelper; + + /// + public Orientation Orientation + { + get => _orientationHelper.Orientation; + set => _orientationHelper.Orientation = value; + } + + /// + public event EventHandler>? OrientationChanging; + + /// + public event EventHandler>? OrientationChanged; + + /// + public void OnOrientationChanged (Orientation newOrientation) + { + TextDirection = Orientation == Orientation.Vertical ? TextDirection.TopBottom_LeftRight : TextDirection.LeftRight_TopBottom; + TextAlignment = Alignment.Center; + VerticalTextAlignment = Alignment.Center; + _slider.Orientation = newOrientation; + PositionSubviews (); + + OrientationChanged?.Invoke (this, new (newOrientation)); + } + + #endregion + + /// + /// Gets or sets the amount each mouse wheel event, or click on the increment/decrement buttons, will + /// incremenet/decrement the . + /// + /// + /// The default is 1. + /// + public int Increment { get; set; } = 1; + + + #region Position + + private int _position; + + /// + /// Gets or sets the position of the slider relative to . + /// + /// + /// + /// The content position is clamped to 0 and minus + /// . + /// + /// + /// Setting will result in the and + /// events being raised. + /// + /// + public int Position + { + get => _position; + set + { + if (value == _position || !Visible) + { + return; + } + + // Clamp the value between 0 and Size - VisibleContentSize + + if (OnPositionChanging (_position, value)) + { + return; + } + + CancelEventArgs args = new (ref _position, ref value); + PositionChanging?.Invoke (this, args); + + if (args.Cancel) + { + return; + } + + int distance = value - _position; + + if (_position == value) + { + return; + } + + _position = value; + + _sliderPosition = _position; + + if (_slider.Position != _sliderPosition) + { + _slider.Position = _sliderPosition.Value; + } + + OnPositionChanged (_position); + PositionChanged?.Invoke (this, new (in _position)); + SetNeedsLayout (); + } + } + + /// + /// Called when is changing. Return true to cancel the change. + /// + protected virtual bool OnPositionChanging (int currentPos, int newPos) { return false; } + + /// + /// Raised when the is changing. Set to + /// to prevent the position from being changed. + /// + public event EventHandler>? PositionChanging; + + /// Called when has changed. + protected virtual void OnPositionChanged (int position) { } + + /// Raised when the has changed. + public event EventHandler>? PositionChanged; + + + #endregion Position + + #region Slider Management + + private int? _sliderPosition; + + private void SliderOnPositionChanged (object? sender, EventArgs e) + { + RaiseSliderPositionChangeEvents (_sliderPosition, e.CurrentValue); + } + + private void SliderOnScroll (object? sender, EventArgs e) + { + if (_slider.VisibleContentSize == 0) + { + return; + } + + int calculatedSliderPos = _position; + + if (calculatedSliderPos == _sliderPosition) + { + return; + } + + int sliderScrolledAmount = e.CurrentValue; + int calculatedPosition = calculatedSliderPos + sliderScrolledAmount; + + Position = calculatedPosition; + } + + private void RaiseSliderPositionChangeEvents (int? currentSliderPosition, int newSliderPosition) + { + if (currentSliderPosition == newSliderPosition) + { + return; + } + + _sliderPosition = newSliderPosition; + + OnSliderPositionChanged (newSliderPosition); + SliderPositionChanged?.Invoke (this, new (in newSliderPosition)); + } + + /// Called when the slider position has changed. + protected virtual void OnSliderPositionChanged (int position) { } + + /// Raised when the slider position has changed. + public event EventHandler>? SliderPositionChanged; + + #endregion Slider Management + + /// + protected override bool OnClearingViewport () + { + //if (Orientation == Orientation.Vertical) + //{ + // FillRect (Viewport with { Y = Viewport.Y, Height = Viewport.Height }, Glyphs.Stipple); + //} + //else + //{ + // FillRect (Viewport with { X = Viewport.X, Width = Viewport.Width }, Glyphs.Stipple); + //} + + //SetNeedsDraw (); + + return true; + } + + // TODO: Change this to work OnMouseEvent with continuouse press and grab so it's continous. + /// + protected override bool OnMouseClick (MouseEventArgs args) + { + // Check if the mouse click is a single click + if (!args.IsSingleClicked) + { + return false; + } + + int sliderCenter; + int distanceFromCenter; + + if (Orientation == Orientation.Vertical) + { + sliderCenter = 1 + _slider.Frame.Y + _slider.Frame.Height / 2; + distanceFromCenter = args.Position.Y - sliderCenter; + } + else + { + sliderCenter = 1 + _slider.Frame.X + _slider.Frame.Width / 2; + distanceFromCenter = args.Position.X - sliderCenter; + } + + int jump = Increment; + + // Adjust the content position based on the distance + if (distanceFromCenter < 0) + { + Position = Math.Max (0, Position - jump); + } + else + { + Position = Math.Min (Viewport.Height - _slider.Size, Position + jump); + } + + return true; + } + + /// + protected override bool OnMouseEvent (MouseEventArgs mouseEvent) + { + if (SuperView is null) + { + return false; + } + + if (!mouseEvent.IsWheel) + { + return false; + } + + if (Orientation == Orientation.Vertical) + { + if (mouseEvent.Flags.HasFlag (MouseFlags.WheeledDown)) + { + Position += Increment; + } + + if (mouseEvent.Flags.HasFlag (MouseFlags.WheeledUp)) + { + Position -= Increment; + } + } + else + { + if (mouseEvent.Flags.HasFlag (MouseFlags.WheeledRight)) + { + Position += Increment; + } + + if (mouseEvent.Flags.HasFlag (MouseFlags.WheeledLeft)) + { + Position -= Increment; + } + } + + return true; + } + + /// + public bool EnableForDesign () + { + OrientationChanged += (sender, args) => + { + if (args.CurrentValue == Orientation.Vertical) + { + Width = 2; + Height = Dim.Fill (); + } + else + { + Width = Dim.Fill (); + Height = 2; + } + }; + + Width = 2; + Height = Dim.Fill(); + + return true; + } +} diff --git a/UICatalog/Scenarios/Editors/ArrangementEditor.cs b/UICatalog/Scenarios/Editors/ArrangementEditor.cs index 80fe328924..344473db3e 100644 --- a/UICatalog/Scenarios/Editors/ArrangementEditor.cs +++ b/UICatalog/Scenarios/Editors/ArrangementEditor.cs @@ -1,6 +1,7 @@ #nullable enable using System; using System.Collections.Generic; +using System.Text; using Terminal.Gui; namespace UICatalog.Scenarios; @@ -17,11 +18,13 @@ public ArrangementEditor () Initialized += ArrangementEditor_Initialized; + _arrangementSlider.MinimumInnerSpacing = 0; + _arrangementSlider.Options = [ new RangeSliderOption { - Legend = ViewArrangement.Movable.ToString (), + Legend = $"{ViewArrangement.Movable}", Data = ViewArrangement.Movable }, @@ -59,7 +62,7 @@ public ArrangementEditor () Add (_arrangementSlider); } - private readonly Slider _arrangementSlider = new() + private readonly RangeSlider _arrangementSlider = new() { Orientation = Orientation.Vertical, UseMinimumSize = true, @@ -88,7 +91,18 @@ protected override void OnViewToEditChanged () _arrangementSlider.OptionsChanged += ArrangementSliderOnOptionsChanged; } - private void ArrangementEditor_Initialized (object? sender, EventArgs e) { _arrangementSlider.OptionsChanged += ArrangementSliderOnOptionsChanged; } + private void ArrangementEditor_Initialized (object? sender, EventArgs e) + { + _arrangementSlider.OptionsChanged += ArrangementSliderOnOptionsChanged; + _arrangementSlider.Style.OptionChar = new Cell { Rune = CM.Glyphs.CheckStateUnChecked, Attribute = GetNormalColor () }; + _arrangementSlider.Style.SetChar = new Cell { Rune = CM.Glyphs.CheckStateChecked, Attribute = GetNormalColor () }; + _arrangementSlider.Style.StartRangeChar = new Cell { Rune = CM.Glyphs.CheckStateChecked, Attribute = GetNormalColor () }; + _arrangementSlider.Style.EndRangeChar = new Cell { Rune = CM.Glyphs.CheckStateChecked, Attribute = GetNormalColor () }; + _arrangementSlider.Style.EmptyChar = new Cell { Rune = (Rune)'e', Attribute = GetNormalColor () }; + _arrangementSlider.Style.RangeChar = new Cell { Rune = (Rune)'r', Attribute = GetNormalColor () }; + _arrangementSlider.Style.SpaceChar = new Cell { Rune = (Rune)'s', Attribute = GetNormalColor () }; + _arrangementSlider.Style.DragChar = new Cell { Rune = (Rune)'d', Attribute = GetNormalColor () }; + } private void ArrangementSliderOnOptionsChanged (object? sender, RangeSliderEventArgs e) { diff --git a/UICatalog/Scenarios/Mouse.cs b/UICatalog/Scenarios/Mouse.cs index 11e1d42cc2..aadccc08ff 100644 --- a/UICatalog/Scenarios/Mouse.cs +++ b/UICatalog/Scenarios/Mouse.cs @@ -19,7 +19,7 @@ public override void Main () Title = GetQuitKeyAndName () }; - Slider filterSlider = new () + RangeSlider filterSlider = new () { Title = "_Filter", X = 0, diff --git a/UICatalog/Scenarios/RangeSliders.cs b/UICatalog/Scenarios/RangeSliders.cs index 42dc8d5267..1168f7121a 100644 --- a/UICatalog/Scenarios/RangeSliders.cs +++ b/UICatalog/Scenarios/RangeSliders.cs @@ -28,7 +28,7 @@ public void MakeSliders (View v, List options) Type = type, AllowEmpty = true }; - //view.Padding.Thickness = new (0,1,0,0); + view.Style.OptionChar = new Cell { Rune = CM.Glyphs.Cross }; v.Add (view); prev = view; } @@ -163,7 +163,7 @@ public override void Main () #region Config Slider - Slider optionsSlider = new () + RangeSlider optionsSlider = new () { Title = "Options", X = 0, @@ -242,7 +242,7 @@ public override void Main () #region Slider Orientation Slider - Slider orientationSlider = new (new List { "Horizontal", "Vertical" }) + RangeSlider orientationSlider = new (new List { "Horizontal", "Vertical" }) { Title = "Slider Orientation", X = 0, @@ -327,7 +327,7 @@ public override void Main () #region Legends Orientation Slider - Slider legendsOrientationSlider = new (new List { "Horizontal", "Vertical" }) + RangeSlider legendsOrientationSlider = new (new List { "Horizontal", "Vertical" }) { Title = "Legends Orientation", X = 0, @@ -438,7 +438,7 @@ public override void Main () s.Style.RangeChar = s.Style.RangeChar with { Attribute = app.GetNormalColor () }; } - Slider<(Color, Color)> sliderFGColor = new () + RangeSlider<(Color, Color)> sliderFGColor = new () { Title = "FG Color", X = 0, @@ -528,7 +528,7 @@ public override void Main () } }; - Slider<(Color, Color)> sliderBGColor = new () + RangeSlider<(Color, Color)> sliderBGColor = new () { Title = "BG Color", X = Pos.Right (sliderFGColor), diff --git a/UICatalog/Scenarios/Shortcuts.cs b/UICatalog/Scenarios/Shortcuts.cs index e1d1f171b1..774d30df0d 100644 --- a/UICatalog/Scenarios/Shortcuts.cs +++ b/UICatalog/Scenarios/Shortcuts.cs @@ -242,7 +242,7 @@ private void App_Loaded (object sender, EventArgs e) Width = Dim.Fill () - Dim.Width (eventLog), KeyBindingScope = KeyBindingScope.HotKey, HelpText = "Sliders work!", - CommandView = new Slider + CommandView = new RangeSlider { Orientation = Orientation.Horizontal, AllowEmpty = true @@ -250,12 +250,12 @@ private void App_Loaded (object sender, EventArgs e) Key = Key.F5, }; - ((Slider)sliderShortcut.CommandView).Options = new () { new () { Legend = "A" }, new () { Legend = "B" }, new () { Legend = "C" } }; - ((Slider)sliderShortcut.CommandView).SetOption (0); + ((RangeSlider)sliderShortcut.CommandView).Options = new () { new () { Legend = "A" }, new () { Legend = "B" }, new () { Legend = "C" } }; + ((RangeSlider)sliderShortcut.CommandView).SetOption (0); - ((Slider)sliderShortcut.CommandView).OptionsChanged += (o, args) => + ((RangeSlider)sliderShortcut.CommandView).OptionsChanged += (o, args) => { - eventSource.Add ($"OptionsChanged: {o.GetType ().Name} - {string.Join (",", ((Slider)o).GetSetOptions ())}"); + eventSource.Add ($"OptionsChanged: {o.GetType ().Name} - {string.Join (",", ((RangeSlider)o).GetSetOptions ())}"); eventLog.MoveDown (); }; diff --git a/UnitTests/Views/RangeSliderTests.cs b/UnitTests/Views/RangeSliderTests.cs index f4acfe536f..45faa7753f 100644 --- a/UnitTests/Views/RangeSliderTests.cs +++ b/UnitTests/Views/RangeSliderTests.cs @@ -144,7 +144,7 @@ public class RangeSliderTests public void Constructor_Default () { // Arrange & Act - Slider slider = new (); + RangeSlider slider = new (); // Assert Assert.NotNull (slider); @@ -168,7 +168,7 @@ public void Constructor_With_Options () List options = new () { 1, 2, 3 }; // Act - Slider slider = new (options); + RangeSlider slider = new (options); slider.SetRelativeLayout (new (100, 100)); // Assert @@ -186,7 +186,7 @@ public void Constructor_With_Options () public void MovePlus_Should_MoveFocusRight_When_OptionIsAvailable () { // Arrange - Slider slider = new (new () { 1, 2, 3, 4 }); + RangeSlider slider = new (new () { 1, 2, 3, 4 }); // Act bool result = slider.MovePlus (); @@ -200,7 +200,7 @@ public void MovePlus_Should_MoveFocusRight_When_OptionIsAvailable () public void MovePlus_Should_NotMoveFocusRight_When_AtEnd () { // Arrange - Slider slider = new (new () { 1, 2, 3, 4 }); + RangeSlider slider = new (new () { 1, 2, 3, 4 }); slider.FocusedOption = 3; @@ -216,7 +216,7 @@ public void MovePlus_Should_NotMoveFocusRight_When_AtEnd () public void OnOptionFocused_Event_Cancelled () { // Arrange - Slider slider = new (new () { 1, 2, 3 }); + RangeSlider slider = new (new () { 1, 2, 3 }); var eventRaised = false; var cancel = false; slider.OptionFocused += (sender, args) => eventRaised = true; @@ -256,7 +256,7 @@ public void OnOptionFocused_Event_Cancelled () public void OnOptionFocused_Event_Raised () { // Arrange - Slider slider = new (new () { 1, 2, 3 }); + RangeSlider slider = new (new () { 1, 2, 3 }); var eventRaised = false; slider.OptionFocused += (sender, args) => eventRaised = true; var newFocusedOption = 1; @@ -273,7 +273,7 @@ public void OnOptionFocused_Event_Raised () public void OnOptionsChanged_Event_Raised () { // Arrange - Slider slider = new (); + RangeSlider slider = new (); var eventRaised = false; slider.OptionsChanged += (sender, args) => eventRaised = true; @@ -288,7 +288,7 @@ public void OnOptionsChanged_Event_Raised () public void Set_Should_Not_UnSetFocusedOption_When_EmptyNotAllowed () { // Arrange - Slider slider = new (new () { 1, 2, 3, 4 }) { AllowEmpty = false }; + RangeSlider slider = new (new () { 1, 2, 3, 4 }) { AllowEmpty = false }; Assert.NotEmpty (slider.GetSetOptions ()); @@ -306,7 +306,7 @@ public void Set_Should_Not_UnSetFocusedOption_When_EmptyNotAllowed () public void Set_Should_SetFocusedOption () { // Arrange - Slider slider = new (new () { 1, 2, 3, 4 }); + RangeSlider slider = new (new () { 1, 2, 3, 4 }); // Act slider.FocusedOption = 2; @@ -322,7 +322,7 @@ public void Set_Should_SetFocusedOption () public void TryGetOptionByPosition_InvalidPosition_Failure () { // Arrange - Slider slider = new (new () { 1, 2, 3 }); + RangeSlider slider = new (new () { 1, 2, 3 }); var x = 10; var y = 10; var threshold = 2; @@ -346,7 +346,7 @@ public void TryGetOptionByPosition_InvalidPosition_Failure () public void TryGetOptionByPosition_ValidPositionHorizontal_Success (int x, int y, int threshold, int expectedData) { // Arrange - Slider slider = new (new () { 1, 2, 3, 4 }); + RangeSlider slider = new (new () { 1, 2, 3, 4 }); // 0123456789 // 1234 @@ -375,7 +375,7 @@ public void TryGetOptionByPosition_ValidPositionHorizontal_Success (int x, int y public void TryGetOptionByPosition_ValidPositionVertical_Success (int x, int y, int threshold, int expectedData) { // Arrange - Slider slider = new (new () { 1, 2, 3, 4 }); + RangeSlider slider = new (new () { 1, 2, 3, 4 }); slider.Orientation = Orientation.Vertical; // Set auto size to true to enable testing @@ -404,7 +404,7 @@ public void TryGetOptionByPosition_ValidPositionVertical_Success (int x, int y, public void TryGetPositionByOption_InvalidOption_Failure () { // Arrange - Slider slider = new (new () { 1, 2, 3 }); + RangeSlider slider = new (new () { 1, 2, 3 }); int option = -1; (int, int) expectedPosition = (-1, -1); @@ -423,7 +423,7 @@ public void TryGetPositionByOption_InvalidOption_Failure () public void TryGetPositionByOption_ValidOptionHorizontal_Success (int option, int expectedX, int expectedY) { // Arrange - Slider slider = new (new () { 1, 2, 3, 4 }); + RangeSlider slider = new (new () { 1, 2, 3, 4 }); // Set auto size to true to enable testing slider.MinimumInnerSpacing = 2; @@ -447,7 +447,7 @@ public void TryGetPositionByOption_ValidOptionHorizontal_Success (int option, in public void TryGetPositionByOption_ValidOptionVertical_Success (int option, int expectedX, int expectedY) { // Arrange - Slider slider = new (new () { 1, 2, 3, 4 }); + RangeSlider slider = new (new () { 1, 2, 3, 4 }); slider.Orientation = Orientation.Vertical; // Set auto size to true to enable testing @@ -467,7 +467,7 @@ public void TryGetPositionByOption_ValidOptionVertical_Success (int option, int private void One_Option_Does_Not_Throw () { // Arrange - Slider slider = new (); + RangeSlider slider = new (); slider.BeginInit (); slider.EndInit (); @@ -479,7 +479,7 @@ private void One_Option_Does_Not_Throw () private void Set_Options_No_Legend_Throws () { // Arrange - Slider slider = new (); + RangeSlider slider = new (); // Act/Assert Assert.Throws (() => slider.Options = null); @@ -489,7 +489,7 @@ private void Set_Options_No_Legend_Throws () private void Set_Options_Throws_If_Null () { // Arrange - Slider slider = new (); + RangeSlider slider = new (); // Act/Assert Assert.Throws (() => slider.Options = null); From a55fe6cd628cfeaa99d319ee8798117cc2f59962 Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 18 Nov 2024 21:21:17 -0700 Subject: [PATCH 4/4] Slider -> LinearRange --- .../LinearRange.cs} | 90 +++++++++---------- .../LinearRangeAttributes.cs} | 4 +- .../LinearRangeConfiguration.cs} | 6 +- .../LinearRangeEventArgs.cs} | 10 +-- .../LinearRangeOption.cs} | 22 ++--- .../LinearRange/LinearRangeOptionEventArgs.cs | 12 +++ .../LinearRangeStyle.cs} | 8 +- .../LinearRangeType.cs} | 4 +- .../RangeSlider/RangeSliderOptionEventArgs.cs | 12 --- UICatalog/Scenarios/DimAutoDemo.cs | 4 +- .../Scenarios/Editors/ArrangementEditor.cs | 20 ++--- .../{RangeSliders.cs => LinearRange.cs} | 62 ++++++------- UICatalog/Scenarios/Mouse.cs | 6 +- UICatalog/Scenarios/Shortcuts.cs | 10 +-- UICatalog/Scenarios/ViewportSettings.cs | 4 +- ...angeSliderTests.cs => LinearRangeTests.cs} | 84 ++++++++--------- 16 files changed, 179 insertions(+), 179 deletions(-) rename Terminal.Gui/Views/{RangeSlider/RangeSlider.cs => LinearRange/LinearRange.cs} (95%) rename Terminal.Gui/Views/{RangeSlider/RangeSliderAttributes.cs => LinearRange/LinearRangeAttributes.cs} (80%) rename Terminal.Gui/Views/{RangeSlider/RangeSliderConfiguration.cs => LinearRange/LinearRangeConfiguration.cs} (77%) rename Terminal.Gui/Views/{RangeSlider/RangeSliderEventArgs.cs => LinearRange/LinearRangeEventArgs.cs} (66%) rename Terminal.Gui/Views/{RangeSlider/RangeSliderOption.cs => LinearRange/LinearRangeOption.cs} (66%) create mode 100644 Terminal.Gui/Views/LinearRange/LinearRangeOptionEventArgs.cs rename Terminal.Gui/Views/{RangeSlider/RangeSliderStyle.cs => LinearRange/LinearRangeStyle.cs} (85%) rename Terminal.Gui/Views/{RangeSlider/RangeSliderType.cs => LinearRange/LinearRangeType.cs} (91%) delete mode 100644 Terminal.Gui/Views/RangeSlider/RangeSliderOptionEventArgs.cs rename UICatalog/Scenarios/{RangeSliders.cs => LinearRange.cs} (92%) rename UnitTests/Views/{RangeSliderTests.cs => LinearRangeTests.cs} (85%) diff --git a/Terminal.Gui/Views/RangeSlider/RangeSlider.cs b/Terminal.Gui/Views/LinearRange/LinearRange.cs similarity index 95% rename from Terminal.Gui/Views/RangeSlider/RangeSlider.cs rename to Terminal.Gui/Views/LinearRange/LinearRange.cs index 114f31374f..3930656742 100644 --- a/Terminal.Gui/Views/RangeSlider/RangeSlider.cs +++ b/Terminal.Gui/Views/LinearRange/LinearRange.cs @@ -3,15 +3,15 @@ namespace Terminal.Gui; /// Slider control. -public class RangeSlider : RangeSlider +public class LinearRange : LinearRange { - /// Initializes a new instance of the class. - public RangeSlider () { } + /// Initializes a new instance of the class. + public LinearRange () { } - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// Initial slider options. /// Initial slider options. - public RangeSlider (List options, Orientation orientation = Orientation.Horizontal) : + public LinearRange (List options, Orientation orientation = Orientation.Horizontal) : base (options, orientation) { } } @@ -21,22 +21,22 @@ public RangeSlider (List options, Orientation orientation = Orientation. /// keyboard or mouse. /// /// -public class RangeSlider : View, IOrientation +public class LinearRange : View, IOrientation { - private readonly RangeSliderConfiguration _config = new (); + private readonly LinearRangeConfiguration _config = new (); // List of the current set options. private readonly List _setOptions = new (); // Options - private List> _options; + private List> _options; private OrientationHelper _orientationHelper; #region Initialize private void SetInitialProperties ( - List> options, + List> options, Orientation orientation = Orientation.Horizontal ) { @@ -45,7 +45,7 @@ private void SetInitialProperties ( CanFocus = true; CursorVisibility = CursorVisibility.Default; - _options = options ?? new List> (); + _options = options ?? new List> (); _orientationHelper = new (this); // Do not use object initializer! _orientationHelper.Orientation = _config._sliderOrientation = orientation; @@ -117,13 +117,13 @@ private void SetDefaultStyle () #region Constructors - /// Initializes a new instance of the class. - public RangeSlider () : this (new ()) { } + /// Initializes a new instance of the class. + public LinearRange () : this (new ()) { } - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// Initial slider options. /// Initial slider orientation. - public RangeSlider (List options, Orientation orientation = Orientation.Horizontal) + public LinearRange (List options, Orientation orientation = Orientation.Horizontal) { if (options is null) { @@ -137,7 +137,7 @@ public RangeSlider (List options, Orientation orientation = Orientation.Horiz { var legend = e.ToString (); - return new RangeSliderOption + return new LinearRangeOption { Data = e, Legend = legend, @@ -180,7 +180,7 @@ public override string Text else { IEnumerable list = value.Split (',').Select (x => x.Trim ()); - Options = list.Select (x => new RangeSliderOption { Legend = x }).ToList (); + Options = list.Select (x => new LinearRangeOption { Legend = x }).ToList (); } } } @@ -212,8 +212,8 @@ public int MinimumInnerSpacing } } - /// Slider Type. - public RangeSliderType Type + /// Slider Type. + public LinearRangeType Type { get => _config._type; set @@ -278,11 +278,11 @@ public Orientation LegendsOrientation } } - /// Slider styles. - public RangeSliderStyle Style { get; set; } = new (); + /// Slider styles. + public LinearRangeStyle Style { get; set; } = new (); /// Set the slider options. - public List> Options + public List> Options { get => _options; @@ -347,7 +347,7 @@ public bool UseMinimumSize #region Events /// Event raised when the slider option/s changed. The dictionary contains: key = option index, value = T - public event EventHandler> OptionsChanged; + public event EventHandler> OptionsChanged; /// Overridable method called when the slider options have changed. Raises the event. public virtual void OnOptionsChanged () @@ -357,7 +357,7 @@ public virtual void OnOptionsChanged () } /// Event raised When the option is hovered with the keys or the mouse. - public event EventHandler> OptionFocused; + public event EventHandler> OptionFocused; private int _lastFocusedOption; // for Range type; the most recently focused option. Used to determine shrink direction @@ -366,7 +366,7 @@ private int /// /// if the focus change was cancelled. /// - public virtual bool OnOptionFocused (int newFocusedOption, RangeSliderEventArgs args) + public virtual bool OnOptionFocused (int newFocusedOption, LinearRangeEventArgs args) { if (newFocusedOption > _options.Count - 1 || newFocusedOption < 0) { @@ -500,7 +500,7 @@ void CalcSpacingConfig (int size) { _config._showLegendsAbbr = true; - foreach (RangeSliderOption o in _options.Where (op => op.LegendAbbr == default (Rune))) + foreach (LinearRangeOption o in _options.Where (op => op.LegendAbbr == default (Rune))) { o.LegendAbbr = (Rune)(o.Legend?.GetColumns () > 0 ? o.Legend [0] : ' '); } @@ -867,11 +867,11 @@ private void DrawSlider () if (_config._showEndSpacing && _config._startSpacing > 0) { SetAttribute ( - isSet && _config._type == RangeSliderType.LeftRange + isSet && _config._type == LinearRangeType.LeftRange ? Style.RangeChar.Attribute ?? normalAttr : Style.SpaceChar.Attribute ?? normalAttr ); - Rune rune = isSet && _config._type == RangeSliderType.LeftRange ? Style.RangeChar.Rune : Style.SpaceChar.Rune; + Rune rune = isSet && _config._type == LinearRangeType.LeftRange ? Style.RangeChar.Rune : Style.SpaceChar.Rune; for (var i = 0; i < _config._startSpacing; i++) { @@ -917,19 +917,19 @@ private void DrawSlider () { switch (_config._type) { - case RangeSliderType.LeftRange when i <= _setOptions [0]: + case LinearRangeType.LeftRange when i <= _setOptions [0]: drawRange = i < _setOptions [0]; break; - case RangeSliderType.RightRange when i >= _setOptions [0]: + case LinearRangeType.RightRange when i >= _setOptions [0]: drawRange = i >= _setOptions [0]; break; - case RangeSliderType.Range when _setOptions.Count == 1: + case LinearRangeType.Range when _setOptions.Count == 1: drawRange = false; break; - case RangeSliderType.Range when _setOptions.Count == 2: + case LinearRangeType.Range when _setOptions.Count == 2: if ((i >= _setOptions [0] && i <= _setOptions [1]) || (i >= _setOptions [1] && i <= _setOptions [0])) { @@ -1009,11 +1009,11 @@ private void DrawSlider () if (_config._showEndSpacing) { SetAttribute ( - isSet && _config._type == RangeSliderType.RightRange + isSet && _config._type == LinearRangeType.RightRange ? Style.RangeChar.Attribute ?? normalAttr : Style.SpaceChar.Attribute ?? normalAttr ); - Rune rune = isSet && _config._type == RangeSliderType.RightRange ? Style.RangeChar.Rune : Style.SpaceChar.Rune; + Rune rune = isSet && _config._type == LinearRangeType.RightRange ? Style.RangeChar.Rune : Style.SpaceChar.Rune; for (var i = 0; i < remaining; i++) { @@ -1100,36 +1100,36 @@ private void DrawLegends () // Check if the Option is Set. switch (_config._type) { - case RangeSliderType.Single: - case RangeSliderType.Multiple: + case LinearRangeType.Single: + case LinearRangeType.Multiple: if (isSet && _setOptions.Contains (i)) { isOptionSet = true; } break; - case RangeSliderType.LeftRange: + case LinearRangeType.LeftRange: if (isSet && i <= _setOptions [0]) { isOptionSet = true; } break; - case RangeSliderType.RightRange: + case LinearRangeType.RightRange: if (isSet && i >= _setOptions [0]) { isOptionSet = true; } break; - case RangeSliderType.Range when _setOptions.Count == 1: + case LinearRangeType.Range when _setOptions.Count == 1: if (isSet && i == _setOptions [0]) { isOptionSet = true; } break; - case RangeSliderType.Range: + case LinearRangeType.Range: if (isSet && ((i >= _setOptions [0] && i <= _setOptions [1]) || (i >= _setOptions [1] && i <= _setOptions [0]))) @@ -1466,7 +1466,7 @@ private void SetKeyBindings () KeyBindings.Add (Key.Space, Command.Select); } - private Dictionary> GetSetOptionDictionary () { return _setOptions.ToDictionary (e => e, e => _options [e]); } + private Dictionary> GetSetOptionDictionary () { return _setOptions.ToDictionary (e => e, e => _options [e]); } /// /// Sets or unsets based on . @@ -1505,9 +1505,9 @@ private bool SetFocusedOption () bool changed = false; switch (_config._type) { - case RangeSliderType.Single: - case RangeSliderType.LeftRange: - case RangeSliderType.RightRange: + case LinearRangeType.Single: + case LinearRangeType.LeftRange: + case LinearRangeType.RightRange: if (_setOptions.Count == 1) { @@ -1538,7 +1538,7 @@ private bool SetFocusedOption () changed = true; break; - case RangeSliderType.Multiple: + case LinearRangeType.Multiple: if (_setOptions.Contains (FocusedOption)) { if (!_config._allowEmpty && _setOptions.Count () == 1) @@ -1560,7 +1560,7 @@ private bool SetFocusedOption () break; - case RangeSliderType.Range: + case LinearRangeType.Range: if (_config._rangeAllowSingle) { if (_setOptions.Count == 1) diff --git a/Terminal.Gui/Views/RangeSlider/RangeSliderAttributes.cs b/Terminal.Gui/Views/LinearRange/LinearRangeAttributes.cs similarity index 80% rename from Terminal.Gui/Views/RangeSlider/RangeSliderAttributes.cs rename to Terminal.Gui/Views/LinearRange/LinearRangeAttributes.cs index e992710e11..62004a1189 100644 --- a/Terminal.Gui/Views/RangeSlider/RangeSliderAttributes.cs +++ b/Terminal.Gui/Views/LinearRange/LinearRangeAttributes.cs @@ -1,7 +1,7 @@ namespace Terminal.Gui; -/// Legend Style -public class RangeSliderAttributes +/// Legend Style +public class LinearRangeAttributes { /// Attribute for the Legends Container. public Attribute? EmptyAttribute { get; set; } diff --git a/Terminal.Gui/Views/RangeSlider/RangeSliderConfiguration.cs b/Terminal.Gui/Views/LinearRange/LinearRangeConfiguration.cs similarity index 77% rename from Terminal.Gui/Views/RangeSlider/RangeSliderConfiguration.cs rename to Terminal.Gui/Views/LinearRange/LinearRangeConfiguration.cs index ade230bae7..cc44159606 100644 --- a/Terminal.Gui/Views/RangeSlider/RangeSliderConfiguration.cs +++ b/Terminal.Gui/Views/LinearRange/LinearRangeConfiguration.cs @@ -1,7 +1,7 @@ namespace Terminal.Gui; -/// All configuration are grouped in this class. -internal class RangeSliderConfiguration +/// All configuration are grouped in this class. +internal class LinearRangeConfiguration { internal bool _allowEmpty; internal int _endSpacing; @@ -14,6 +14,6 @@ internal class RangeSliderConfiguration internal bool _showLegendsAbbr; internal Orientation _sliderOrientation = Orientation.Horizontal; internal int _startSpacing; - internal RangeSliderType _type = RangeSliderType.Single; + internal LinearRangeType _type = LinearRangeType.Single; internal bool _useMinimumSize; } \ No newline at end of file diff --git a/Terminal.Gui/Views/RangeSlider/RangeSliderEventArgs.cs b/Terminal.Gui/Views/LinearRange/LinearRangeEventArgs.cs similarity index 66% rename from Terminal.Gui/Views/RangeSlider/RangeSliderEventArgs.cs rename to Terminal.Gui/Views/LinearRange/LinearRangeEventArgs.cs index d75271b90e..3e329a292b 100644 --- a/Terminal.Gui/Views/RangeSlider/RangeSliderEventArgs.cs +++ b/Terminal.Gui/Views/LinearRange/LinearRangeEventArgs.cs @@ -1,12 +1,12 @@ namespace Terminal.Gui; -/// for events. -public class RangeSliderEventArgs : EventArgs +/// for events. +public class LinearRangeEventArgs : EventArgs { - /// Initializes a new instance of + /// Initializes a new instance of /// The current options. /// Index of the option that is focused. -1 if no option has the focus. - public RangeSliderEventArgs (Dictionary> options, int focused = -1) + public LinearRangeEventArgs (Dictionary> options, int focused = -1) { Options = options; Focused = focused; @@ -20,5 +20,5 @@ public RangeSliderEventArgs (Dictionary> options, int public int Focused { get; set; } /// Gets/sets whether the option is set or not. - public Dictionary> Options { get; set; } + public Dictionary> Options { get; set; } } \ No newline at end of file diff --git a/Terminal.Gui/Views/RangeSlider/RangeSliderOption.cs b/Terminal.Gui/Views/LinearRange/LinearRangeOption.cs similarity index 66% rename from Terminal.Gui/Views/RangeSlider/RangeSliderOption.cs rename to Terminal.Gui/Views/LinearRange/LinearRangeOption.cs index 72fc02ae15..5fd8d8a238 100644 --- a/Terminal.Gui/Views/RangeSlider/RangeSliderOption.cs +++ b/Terminal.Gui/Views/LinearRange/LinearRangeOption.cs @@ -1,14 +1,14 @@ namespace Terminal.Gui; -/// Represents an option in a . +/// Represents an option in a . /// Data type of the option. -public class RangeSliderOption +public class LinearRangeOption { - /// Creates a new empty instance of the class. - public RangeSliderOption () { } + /// Creates a new empty instance of the class. + public LinearRangeOption () { } - /// Creates a new instance of the class with values for each property. - public RangeSliderOption (string legend, Rune legendAbbr, T data) + /// Creates a new instance of the class with values for each property. + public LinearRangeOption (string legend, Rune legendAbbr, T data) { Legend = legend; LegendAbbr = legendAbbr; @@ -16,7 +16,7 @@ public RangeSliderOption (string legend, Rune legendAbbr, T data) } /// Event fired when an option has changed. - public event EventHandler Changed; + public event EventHandler Changed; /// Custom data of the option. public T Data { get; set; } @@ -25,19 +25,19 @@ public RangeSliderOption (string legend, Rune legendAbbr, T data) public string Legend { get; set; } /// - /// Abbreviation of the Legend. When the too small to fit + /// 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; + public event EventHandler Set; - /// Creates a human-readable string that represents this . + /// 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; + public event EventHandler UnSet; /// To Raise the event from the Slider. internal void OnChanged (bool isSet) { Changed?.Invoke (this, new (isSet)); } diff --git a/Terminal.Gui/Views/LinearRange/LinearRangeOptionEventArgs.cs b/Terminal.Gui/Views/LinearRange/LinearRangeOptionEventArgs.cs new file mode 100644 index 0000000000..d30f6a1e0f --- /dev/null +++ b/Terminal.Gui/Views/LinearRange/LinearRangeOptionEventArgs.cs @@ -0,0 +1,12 @@ +namespace Terminal.Gui; + +/// for events. +public class LinearRangeOptionEventArgs : EventArgs +{ + /// Initializes a new instance of + /// indicates whether the option is set + public LinearRangeOptionEventArgs (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/RangeSlider/RangeSliderStyle.cs b/Terminal.Gui/Views/LinearRange/LinearRangeStyle.cs similarity index 85% rename from Terminal.Gui/Views/RangeSlider/RangeSliderStyle.cs rename to Terminal.Gui/Views/LinearRange/LinearRangeStyle.cs index 3bd3816716..30baa20a1b 100644 --- a/Terminal.Gui/Views/RangeSlider/RangeSliderStyle.cs +++ b/Terminal.Gui/Views/LinearRange/LinearRangeStyle.cs @@ -1,10 +1,10 @@ namespace Terminal.Gui; -/// Style -public class RangeSliderStyle +/// Style +public class LinearRangeStyle { /// Constructs a new instance. - public RangeSliderStyle () { LegendAttributes = new (); } + public LinearRangeStyle () { LegendAttributes = new (); } /// The glyph and the attribute to indicate mouse dragging. public Cell DragChar { get; set; } @@ -16,7 +16,7 @@ public class RangeSliderStyle public Cell EndRangeChar { get; set; } /// Legend attributes - public RangeSliderAttributes LegendAttributes { get; set; } + public LinearRangeAttributes LegendAttributes { get; set; } /// The glyph and the attribute used for each option (tick) on the slider. public Cell OptionChar { get; set; } diff --git a/Terminal.Gui/Views/RangeSlider/RangeSliderType.cs b/Terminal.Gui/Views/LinearRange/LinearRangeType.cs similarity index 91% rename from Terminal.Gui/Views/RangeSlider/RangeSliderType.cs rename to Terminal.Gui/Views/LinearRange/LinearRangeType.cs index 113c456a67..d236d09c9d 100644 --- a/Terminal.Gui/Views/RangeSlider/RangeSliderType.cs +++ b/Terminal.Gui/Views/LinearRange/LinearRangeType.cs @@ -1,7 +1,7 @@ namespace Terminal.Gui; -/// Types -public enum RangeSliderType +/// Types +public enum LinearRangeType { /// /// diff --git a/Terminal.Gui/Views/RangeSlider/RangeSliderOptionEventArgs.cs b/Terminal.Gui/Views/RangeSlider/RangeSliderOptionEventArgs.cs deleted file mode 100644 index 15315f3be5..0000000000 --- a/Terminal.Gui/Views/RangeSlider/RangeSliderOptionEventArgs.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Terminal.Gui; - -/// for events. -public class RangeSliderOptionEventArgs : EventArgs -{ - /// Initializes a new instance of - /// indicates whether the option is set - public RangeSliderOptionEventArgs (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/UICatalog/Scenarios/DimAutoDemo.cs b/UICatalog/Scenarios/DimAutoDemo.cs index 525dd02f01..a574ae36b9 100644 --- a/UICatalog/Scenarios/DimAutoDemo.cs +++ b/UICatalog/Scenarios/DimAutoDemo.cs @@ -184,11 +184,11 @@ private static FrameView CreateSliderFrameView () }; List options = new () { "One", "Two", "Three", "Four" }; - RangeSlider slider = new (options) + LinearRange slider = new (options) { X = 0, Y = 0, - Type = RangeSliderType.Multiple, + Type = LinearRangeType.Multiple, AllowEmpty = false, BorderStyle = LineStyle.Double, Title = "_Slider" diff --git a/UICatalog/Scenarios/Editors/ArrangementEditor.cs b/UICatalog/Scenarios/Editors/ArrangementEditor.cs index 344473db3e..8dabc0730a 100644 --- a/UICatalog/Scenarios/Editors/ArrangementEditor.cs +++ b/UICatalog/Scenarios/Editors/ArrangementEditor.cs @@ -22,37 +22,37 @@ public ArrangementEditor () _arrangementSlider.Options = [ - new RangeSliderOption + new LinearRangeOption { Legend = $"{ViewArrangement.Movable}", Data = ViewArrangement.Movable }, - new RangeSliderOption + new LinearRangeOption { Legend = ViewArrangement.LeftResizable.ToString (), Data = ViewArrangement.LeftResizable }, - new RangeSliderOption + new LinearRangeOption { Legend = ViewArrangement.RightResizable.ToString (), Data = ViewArrangement.RightResizable }, - new RangeSliderOption + new LinearRangeOption { Legend = ViewArrangement.TopResizable.ToString (), Data = ViewArrangement.TopResizable }, - new RangeSliderOption + new LinearRangeOption { Legend = ViewArrangement.BottomResizable.ToString (), Data = ViewArrangement.BottomResizable }, - new RangeSliderOption + new LinearRangeOption { Legend = ViewArrangement.Overlapped.ToString (), Data = ViewArrangement.Overlapped @@ -62,11 +62,11 @@ public ArrangementEditor () Add (_arrangementSlider); } - private readonly RangeSlider _arrangementSlider = new() + private readonly LinearRange _arrangementSlider = new() { Orientation = Orientation.Vertical, UseMinimumSize = true, - Type = RangeSliderType.Multiple, + Type = LinearRangeType.Multiple, AllowEmpty = true, }; @@ -104,14 +104,14 @@ private void ArrangementEditor_Initialized (object? sender, EventArgs e) _arrangementSlider.Style.DragChar = new Cell { Rune = (Rune)'d', Attribute = GetNormalColor () }; } - private void ArrangementSliderOnOptionsChanged (object? sender, RangeSliderEventArgs e) + private void ArrangementSliderOnOptionsChanged (object? sender, LinearRangeEventArgs e) { if (ViewToEdit is { }) { // Set the arrangement based on the selected options var arrangement = ViewArrangement.Fixed; - foreach (KeyValuePair> option in e.Options) + foreach (KeyValuePair> option in e.Options) { arrangement |= option.Value.Data; } diff --git a/UICatalog/Scenarios/RangeSliders.cs b/UICatalog/Scenarios/LinearRange.cs similarity index 92% rename from UICatalog/Scenarios/RangeSliders.cs rename to UICatalog/Scenarios/LinearRange.cs index 1168f7121a..3d323477c8 100644 --- a/UICatalog/Scenarios/RangeSliders.cs +++ b/UICatalog/Scenarios/LinearRange.cs @@ -8,18 +8,18 @@ namespace UICatalog.Scenarios; -[ScenarioMetadata ("RangeSliders", "Demonstrates the RangeSlider view.")] +[ScenarioMetadata ("LinearRanges", "Demonstrates the LinearRange view.")] [ScenarioCategory ("Controls")] -public class RangeSliders : Scenario +public class LinearRanges : Scenario { public void MakeSliders (View v, List options) { - List types = Enum.GetValues (typeof (RangeSliderType)).Cast ().ToList (); - RangeSlider prev = null; + List types = Enum.GetValues (typeof (LinearRangeType)).Cast ().ToList (); + LinearRange prev = null; - foreach (RangeSliderType type in types) + foreach (LinearRangeType type in types) { - var view = new RangeSlider (options) + var view = new LinearRange (options) { Title = type.ToString (), X = 0, @@ -76,12 +76,12 @@ public void MakeSliders (View v, List options) 39 }; - var single = new RangeSlider (singleOptions) + var single = new LinearRange (singleOptions) { Title = "_Continuous", X = 0, Y = prev == null ? 0 : Pos.Bottom (prev), - Type = RangeSliderType.Single, + Type = LinearRangeType.Single, BorderStyle = LineStyle.Single, AllowEmpty = false }; @@ -111,12 +111,12 @@ public void MakeSliders (View v, List options) List oneOption = new () { "The Only Option" }; - var one = new RangeSlider (oneOption) + var one = new LinearRange (oneOption) { Title = "_One Option", X = 0, Y = prev == null ? 0 : Pos.Bottom (single), - Type = RangeSliderType.Single, + Type = LinearRangeType.Single, BorderStyle = LineStyle.Single, AllowEmpty = false }; @@ -163,13 +163,13 @@ public override void Main () #region Config Slider - RangeSlider optionsSlider = new () + LinearRange optionsSlider = new () { Title = "Options", X = 0, Y = 0, Width = Dim.Fill (), - Type = RangeSliderType.Multiple, + Type = LinearRangeType.Multiple, AllowEmpty = true, BorderStyle = LineStyle.Single }; @@ -177,7 +177,7 @@ public override void Main () optionsSlider.Style.SetChar = optionsSlider.Style.SetChar with { Attribute = new Attribute (Color.BrightGreen, Color.Black) }; optionsSlider.Style.LegendAttributes.SetAttribute = new Attribute (Color.Green, Color.Black); - optionsSlider.Options = new List> + optionsSlider.Options = new List> { new () { Legend = "Legends" }, new () { Legend = "RangeAllowSingle" }, @@ -189,7 +189,7 @@ public override void Main () optionsSlider.OptionsChanged += (sender, e) => { - foreach (RangeSlider s in app.Subviews.OfType ()) + foreach (LinearRange s in app.Subviews.OfType ()) { s.ShowLegends = e.Options.ContainsKey (0); s.RangeAllowSingle = e.Options.ContainsKey (1); @@ -233,7 +233,7 @@ public override void Main () dimAutoUsesMin.CheckedStateChanging += (sender, e) => { - foreach (RangeSlider s in app.Subviews.OfType ()) + foreach (LinearRange s in app.Subviews.OfType ()) { s.UseMinimumSize = !s.UseMinimumSize; } @@ -242,7 +242,7 @@ public override void Main () #region Slider Orientation Slider - RangeSlider orientationSlider = new (new List { "Horizontal", "Vertical" }) + LinearRange orientationSlider = new (new List { "Horizontal", "Vertical" }) { Title = "Slider Orientation", X = 0, @@ -258,7 +258,7 @@ public override void Main () { View prev = null; - foreach (RangeSlider s in app.Subviews.OfType ()) + foreach (LinearRange s in app.Subviews.OfType ()) { if (e.Options.ContainsKey (0)) { @@ -327,7 +327,7 @@ public override void Main () #region Legends Orientation Slider - RangeSlider legendsOrientationSlider = new (new List { "Horizontal", "Vertical" }) + LinearRange legendsOrientationSlider = new (new List { "Horizontal", "Vertical" }) { Title = "Legends Orientation", X = 0, @@ -341,7 +341,7 @@ public override void Main () legendsOrientationSlider.OptionsChanged += (sender, e) => { - foreach (RangeSlider s in app.Subviews.OfType ()) + foreach (LinearRange s in app.Subviews.OfType ()) { if (e.Options.ContainsKey (0)) { @@ -404,7 +404,7 @@ public override void Main () X = Pos.Right (label) + 1 }; - innerSpacingUpDown.Value = app.Subviews.OfType ().First ().MinimumInnerSpacing; + innerSpacingUpDown.Value = app.Subviews.OfType ().First ().MinimumInnerSpacing; innerSpacingUpDown.ValueChanging += (sender, e) => { @@ -415,7 +415,7 @@ public override void Main () return; } - foreach (RangeSlider s in app.Subviews.OfType ()) + foreach (LinearRange s in app.Subviews.OfType ()) { s.MinimumInnerSpacing = e.NewValue; } @@ -430,7 +430,7 @@ public override void Main () #region Color Slider - foreach (RangeSlider s in app.Subviews.OfType ()) + foreach (LinearRange s in app.Subviews.OfType ()) { s.Style.OptionChar = s.Style.OptionChar with { Attribute = app.GetNormalColor () }; s.Style.SetChar = s.Style.SetChar with { Attribute = app.GetNormalColor () }; @@ -438,7 +438,7 @@ public override void Main () s.Style.RangeChar = s.Style.RangeChar with { Attribute = app.GetNormalColor () }; } - RangeSlider<(Color, Color)> sliderFGColor = new () + LinearRange<(Color, Color)> sliderFGColor = new () { Title = "FG Color", X = 0, @@ -446,7 +446,7 @@ public override void Main () legendsOrientationSlider ) + 1, - Type = RangeSliderType.Single, + Type = LinearRangeType.Single, BorderStyle = LineStyle.Single, AllowEmpty = false, Orientation = Orientation.Vertical, @@ -458,14 +458,14 @@ public override void Main () sliderFGColor.Style.SetChar = sliderFGColor.Style.SetChar with { Attribute = new Attribute (Color.BrightGreen, Color.Black) }; sliderFGColor.Style.LegendAttributes.SetAttribute = new Attribute (Color.Green, Color.Blue); - List> colorOptions = new (); + List> colorOptions = new (); foreach (ColorName16 colorIndex in Enum.GetValues ()) { var colorName = colorIndex.ToString (); colorOptions.Add ( - new RangeSliderOption<(Color, Color)> + new LinearRangeOption<(Color, Color)> { Data = (new Color (colorIndex), new Color (colorIndex)), @@ -485,7 +485,7 @@ public override void Main () { (Color, Color) data = e.Options.First ().Value.Data; - foreach (RangeSlider s in app.Subviews.OfType ()) + foreach (LinearRange s in app.Subviews.OfType ()) { s.ColorScheme = new ColorScheme (s.ColorScheme); @@ -528,12 +528,12 @@ public override void Main () } }; - RangeSlider<(Color, Color)> sliderBGColor = new () + LinearRange<(Color, Color)> sliderBGColor = new () { Title = "BG Color", X = Pos.Right (sliderFGColor), Y = Pos.Top (sliderFGColor), - Type = RangeSliderType.Single, + Type = LinearRangeType.Single, BorderStyle = LineStyle.Single, AllowEmpty = false, Orientation = Orientation.Vertical, @@ -555,7 +555,7 @@ public override void Main () { (Color, Color) data = e.Options.First ().Value.Data; - foreach (RangeSlider s in app.Subviews.OfType ()) + foreach (LinearRange s in app.Subviews.OfType ()) { s.ColorScheme = new ColorScheme (s.ColorScheme) { @@ -585,7 +585,7 @@ public override void Main () configView.Add (eventLog); - foreach (RangeSlider slider in app.Subviews.Where (v => v is RangeSlider)!) + foreach (LinearRange slider in app.Subviews.Where (v => v is LinearRange)!) { slider.Accepting += (o, args) => { diff --git a/UICatalog/Scenarios/Mouse.cs b/UICatalog/Scenarios/Mouse.cs index aadccc08ff..a00f62499d 100644 --- a/UICatalog/Scenarios/Mouse.cs +++ b/UICatalog/Scenarios/Mouse.cs @@ -19,13 +19,13 @@ public override void Main () Title = GetQuitKeyAndName () }; - RangeSlider filterSlider = new () + LinearRange filterSlider = new () { Title = "_Filter", X = 0, Y = 0, BorderStyle = LineStyle.Single, - Type = RangeSliderType.Multiple, + Type = LinearRangeType.Multiple, Orientation = Orientation.Vertical, UseMinimumSize = true, MinimumInnerSpacing = 0 @@ -35,7 +35,7 @@ public override void Main () .Cast () .Where (value => !value.ToString ().Contains ("None") && !value.ToString ().Contains ("All")) .Select ( - value => new RangeSliderOption + value => new LinearRangeOption { Legend = value.ToString (), Data = value diff --git a/UICatalog/Scenarios/Shortcuts.cs b/UICatalog/Scenarios/Shortcuts.cs index 774d30df0d..ee15852645 100644 --- a/UICatalog/Scenarios/Shortcuts.cs +++ b/UICatalog/Scenarios/Shortcuts.cs @@ -242,7 +242,7 @@ private void App_Loaded (object sender, EventArgs e) Width = Dim.Fill () - Dim.Width (eventLog), KeyBindingScope = KeyBindingScope.HotKey, HelpText = "Sliders work!", - CommandView = new RangeSlider + CommandView = new LinearRange { Orientation = Orientation.Horizontal, AllowEmpty = true @@ -250,12 +250,12 @@ private void App_Loaded (object sender, EventArgs e) Key = Key.F5, }; - ((RangeSlider)sliderShortcut.CommandView).Options = new () { new () { Legend = "A" }, new () { Legend = "B" }, new () { Legend = "C" } }; - ((RangeSlider)sliderShortcut.CommandView).SetOption (0); + ((LinearRange)sliderShortcut.CommandView).Options = new () { new () { Legend = "A" }, new () { Legend = "B" }, new () { Legend = "C" } }; + ((LinearRange)sliderShortcut.CommandView).SetOption (0); - ((RangeSlider)sliderShortcut.CommandView).OptionsChanged += (o, args) => + ((LinearRange)sliderShortcut.CommandView).OptionsChanged += (o, args) => { - eventSource.Add ($"OptionsChanged: {o.GetType ().Name} - {string.Join (",", ((RangeSlider)o).GetSetOptions ())}"); + eventSource.Add ($"OptionsChanged: {o.GetType ().Name} - {string.Join (",", ((LinearRange)o).GetSetOptions ())}"); eventLog.MoveDown (); }; diff --git a/UICatalog/Scenarios/ViewportSettings.cs b/UICatalog/Scenarios/ViewportSettings.cs index f36e2beaa9..10bcdeafa4 100644 --- a/UICatalog/Scenarios/ViewportSettings.cs +++ b/UICatalog/Scenarios/ViewportSettings.cs @@ -463,12 +463,12 @@ void AutoShowHorizontalScrollBarToggle (object sender, CancelEventArgs options = new () { "Option 1", "Option 2", "Option 3" }; - RangeSlider slider = new (options) + LinearRange slider = new (options) { X = 0, Y = Pos.Bottom (textField) + 1, Orientation = Orientation.Vertical, - Type = RangeSliderType.Multiple, + Type = LinearRangeType.Multiple, AllowEmpty = false, BorderStyle = LineStyle.Double, Title = "_Slider" diff --git a/UnitTests/Views/RangeSliderTests.cs b/UnitTests/Views/LinearRangeTests.cs similarity index 85% rename from UnitTests/Views/RangeSliderTests.cs rename to UnitTests/Views/LinearRangeTests.cs index 45faa7753f..10fac689ca 100644 --- a/UnitTests/Views/RangeSliderTests.cs +++ b/UnitTests/Views/LinearRangeTests.cs @@ -8,7 +8,7 @@ public class SliderOptionTests public void OnChanged_Should_Raise_ChangedEvent () { // Arrange - RangeSliderOption sliderOption = new (); + LinearRangeOption sliderOption = new (); var eventRaised = false; sliderOption.Changed += (sender, args) => eventRaised = true; @@ -23,7 +23,7 @@ public void OnChanged_Should_Raise_ChangedEvent () public void OnSet_Should_Raise_SetEvent () { // Arrange - RangeSliderOption sliderOption = new (); + LinearRangeOption sliderOption = new (); var eventRaised = false; sliderOption.Set += (sender, args) => eventRaised = true; @@ -38,7 +38,7 @@ public void OnSet_Should_Raise_SetEvent () public void OnUnSet_Should_Raise_UnSetEvent () { // Arrange - RangeSliderOption sliderOption = new (); + LinearRangeOption sliderOption = new (); var eventRaised = false; sliderOption.UnSet += (sender, args) => eventRaised = true; @@ -52,7 +52,7 @@ public void OnUnSet_Should_Raise_UnSetEvent () [Fact] public void Slider_Option_Default_Constructor () { - RangeSliderOption o = new (); + LinearRangeOption o = new (); Assert.Null (o.Legend); Assert.Equal (default (Rune), o.LegendAbbr); Assert.Equal (default (int), o.Data); @@ -61,7 +61,7 @@ public void Slider_Option_Default_Constructor () [Fact] public void Slider_Option_Values_Constructor () { - RangeSliderOption o = new ("1 thousand", new ('y'), 1000); + LinearRangeOption o = new ("1 thousand", new ('y'), 1000); Assert.Equal ("1 thousand", o.Legend); Assert.Equal (new ('y'), o.LegendAbbr); Assert.Equal (1000, o.Data); @@ -70,14 +70,14 @@ public void Slider_Option_Values_Constructor () [Fact] public void SliderOption_ToString_WhenEmpty () { - RangeSliderOption sliderOption = new (); + LinearRangeOption sliderOption = new (); Assert.Equal ("{Legend=, LegendAbbr=\0, Data=}", sliderOption.ToString ()); } [Fact] public void SliderOption_ToString_WhenPopulated_WithInt () { - RangeSliderOption sliderOption = new () { Legend = "Lord flibble", LegendAbbr = new ('l'), Data = 1 }; + LinearRangeOption sliderOption = new () { Legend = "Lord flibble", LegendAbbr = new ('l'), Data = 1 }; Assert.Equal ("{Legend=Lord flibble, LegendAbbr=l, Data=1}", sliderOption.ToString ()); } @@ -85,7 +85,7 @@ public void SliderOption_ToString_WhenPopulated_WithInt () [Fact] public void SliderOption_ToString_WhenPopulated_WithSizeF () { - RangeSliderOption sliderOption = new () + LinearRangeOption sliderOption = new () { Legend = "Lord flibble", LegendAbbr = new ('l'), Data = new (32, 11) }; @@ -100,11 +100,11 @@ public class SliderEventArgsTests public void Constructor_Sets_Cancel_Default_To_False () { // Arrange - Dictionary> options = new (); + Dictionary> options = new (); var focused = 42; // Act - RangeSliderEventArgs sliderEventArgs = new (options, focused); + LinearRangeEventArgs sliderEventArgs = new (options, focused); // Assert Assert.False (sliderEventArgs.Cancel); @@ -114,11 +114,11 @@ public void Constructor_Sets_Cancel_Default_To_False () public void Constructor_Sets_Focused () { // Arrange - Dictionary> options = new (); + Dictionary> options = new (); var focused = 42; // Act - RangeSliderEventArgs sliderEventArgs = new (options, focused); + LinearRangeEventArgs sliderEventArgs = new (options, focused); // Assert Assert.Equal (focused, sliderEventArgs.Focused); @@ -128,23 +128,23 @@ public void Constructor_Sets_Focused () public void Constructor_Sets_Options () { // Arrange - Dictionary> options = new (); + Dictionary> options = new (); // Act - RangeSliderEventArgs sliderEventArgs = new (options); + LinearRangeEventArgs sliderEventArgs = new (options); // Assert Assert.Equal (options, sliderEventArgs.Options); } } -public class RangeSliderTests +public class LinearRangeTests { [Fact] public void Constructor_Default () { // Arrange & Act - RangeSlider slider = new (); + LinearRange slider = new (); // Assert Assert.NotNull (slider); @@ -154,7 +154,7 @@ public void Constructor_Default () Assert.False (slider.AllowEmpty); Assert.True (slider.ShowLegends); Assert.False (slider.ShowEndSpacing); - Assert.Equal (RangeSliderType.Single, slider.Type); + Assert.Equal (LinearRangeType.Single, slider.Type); Assert.Equal (1, slider.MinimumInnerSpacing); Assert.True (slider.Width is DimAuto); Assert.True (slider.Height is DimAuto); @@ -168,7 +168,7 @@ public void Constructor_With_Options () List options = new () { 1, 2, 3 }; // Act - RangeSlider slider = new (options); + LinearRange slider = new (options); slider.SetRelativeLayout (new (100, 100)); // Assert @@ -186,7 +186,7 @@ public void Constructor_With_Options () public void MovePlus_Should_MoveFocusRight_When_OptionIsAvailable () { // Arrange - RangeSlider slider = new (new () { 1, 2, 3, 4 }); + LinearRange slider = new (new () { 1, 2, 3, 4 }); // Act bool result = slider.MovePlus (); @@ -200,7 +200,7 @@ public void MovePlus_Should_MoveFocusRight_When_OptionIsAvailable () public void MovePlus_Should_NotMoveFocusRight_When_AtEnd () { // Arrange - RangeSlider slider = new (new () { 1, 2, 3, 4 }); + LinearRange slider = new (new () { 1, 2, 3, 4 }); slider.FocusedOption = 3; @@ -216,7 +216,7 @@ public void MovePlus_Should_NotMoveFocusRight_When_AtEnd () public void OnOptionFocused_Event_Cancelled () { // Arrange - RangeSlider slider = new (new () { 1, 2, 3 }); + LinearRange slider = new (new () { 1, 2, 3 }); var eventRaised = false; var cancel = false; slider.OptionFocused += (sender, args) => eventRaised = true; @@ -225,7 +225,7 @@ public void OnOptionFocused_Event_Cancelled () // Create args with cancel set to false cancel = false; - RangeSliderEventArgs args = + LinearRangeEventArgs args = new (new (), newFocusedOption) { Cancel = cancel }; Assert.Equal (0, slider.FocusedOption); @@ -256,11 +256,11 @@ public void OnOptionFocused_Event_Cancelled () public void OnOptionFocused_Event_Raised () { // Arrange - RangeSlider slider = new (new () { 1, 2, 3 }); + LinearRange slider = new (new () { 1, 2, 3 }); var eventRaised = false; slider.OptionFocused += (sender, args) => eventRaised = true; var newFocusedOption = 1; - RangeSliderEventArgs args = new (new (), newFocusedOption); + LinearRangeEventArgs args = new (new (), newFocusedOption); // Act slider.OnOptionFocused (newFocusedOption, args); @@ -273,7 +273,7 @@ public void OnOptionFocused_Event_Raised () public void OnOptionsChanged_Event_Raised () { // Arrange - RangeSlider slider = new (); + LinearRange slider = new (); var eventRaised = false; slider.OptionsChanged += (sender, args) => eventRaised = true; @@ -288,7 +288,7 @@ public void OnOptionsChanged_Event_Raised () public void Set_Should_Not_UnSetFocusedOption_When_EmptyNotAllowed () { // Arrange - RangeSlider slider = new (new () { 1, 2, 3, 4 }) { AllowEmpty = false }; + LinearRange slider = new (new () { 1, 2, 3, 4 }) { AllowEmpty = false }; Assert.NotEmpty (slider.GetSetOptions ()); @@ -306,7 +306,7 @@ public void Set_Should_Not_UnSetFocusedOption_When_EmptyNotAllowed () public void Set_Should_SetFocusedOption () { // Arrange - RangeSlider slider = new (new () { 1, 2, 3, 4 }); + LinearRange slider = new (new () { 1, 2, 3, 4 }); // Act slider.FocusedOption = 2; @@ -322,7 +322,7 @@ public void Set_Should_SetFocusedOption () public void TryGetOptionByPosition_InvalidPosition_Failure () { // Arrange - RangeSlider slider = new (new () { 1, 2, 3 }); + LinearRange slider = new (new () { 1, 2, 3 }); var x = 10; var y = 10; var threshold = 2; @@ -346,7 +346,7 @@ public void TryGetOptionByPosition_InvalidPosition_Failure () public void TryGetOptionByPosition_ValidPositionHorizontal_Success (int x, int y, int threshold, int expectedData) { // Arrange - RangeSlider slider = new (new () { 1, 2, 3, 4 }); + LinearRange slider = new (new () { 1, 2, 3, 4 }); // 0123456789 // 1234 @@ -375,7 +375,7 @@ public void TryGetOptionByPosition_ValidPositionHorizontal_Success (int x, int y public void TryGetOptionByPosition_ValidPositionVertical_Success (int x, int y, int threshold, int expectedData) { // Arrange - RangeSlider slider = new (new () { 1, 2, 3, 4 }); + LinearRange slider = new (new () { 1, 2, 3, 4 }); slider.Orientation = Orientation.Vertical; // Set auto size to true to enable testing @@ -404,7 +404,7 @@ public void TryGetOptionByPosition_ValidPositionVertical_Success (int x, int y, public void TryGetPositionByOption_InvalidOption_Failure () { // Arrange - RangeSlider slider = new (new () { 1, 2, 3 }); + LinearRange slider = new (new () { 1, 2, 3 }); int option = -1; (int, int) expectedPosition = (-1, -1); @@ -423,7 +423,7 @@ public void TryGetPositionByOption_InvalidOption_Failure () public void TryGetPositionByOption_ValidOptionHorizontal_Success (int option, int expectedX, int expectedY) { // Arrange - RangeSlider slider = new (new () { 1, 2, 3, 4 }); + LinearRange slider = new (new () { 1, 2, 3, 4 }); // Set auto size to true to enable testing slider.MinimumInnerSpacing = 2; @@ -447,7 +447,7 @@ public void TryGetPositionByOption_ValidOptionHorizontal_Success (int option, in public void TryGetPositionByOption_ValidOptionVertical_Success (int option, int expectedX, int expectedY) { // Arrange - RangeSlider slider = new (new () { 1, 2, 3, 4 }); + LinearRange slider = new (new () { 1, 2, 3, 4 }); slider.Orientation = Orientation.Vertical; // Set auto size to true to enable testing @@ -467,7 +467,7 @@ public void TryGetPositionByOption_ValidOptionVertical_Success (int option, int private void One_Option_Does_Not_Throw () { // Arrange - RangeSlider slider = new (); + LinearRange slider = new (); slider.BeginInit (); slider.EndInit (); @@ -479,7 +479,7 @@ private void One_Option_Does_Not_Throw () private void Set_Options_No_Legend_Throws () { // Arrange - RangeSlider slider = new (); + LinearRange slider = new (); // Act/Assert Assert.Throws (() => slider.Options = null); @@ -489,7 +489,7 @@ private void Set_Options_No_Legend_Throws () private void Set_Options_Throws_If_Null () { // Arrange - RangeSlider slider = new (); + LinearRange slider = new (); // Act/Assert Assert.Throws (() => slider.Options = null); @@ -506,10 +506,10 @@ private void DimAuto_Both_Respects_SuperView_ContentSize () List options = new () { "01234", "01234" }; - RangeSlider slider = new (options) + LinearRange slider = new (options) { Orientation = Orientation.Vertical, - Type = RangeSliderType.Multiple, + Type = LinearRangeType.Multiple, }; view.Add (slider); view.BeginInit (); @@ -538,10 +538,10 @@ private void DimAuto_Width_Respects_SuperView_ContentSize () List options = new () { "01234", "01234" }; - RangeSlider slider = new (options) + LinearRange slider = new (options) { Orientation = Orientation.Vertical, - Type = RangeSliderType.Multiple, + Type = LinearRangeType.Multiple, Height = 10 }; view.Add (slider); @@ -571,10 +571,10 @@ private void DimAuto_Height_Respects_SuperView_ContentSize () List options = new () { "01234", "01234" }; - RangeSlider slider = new (options) + LinearRange slider = new (options) { Orientation = Orientation.Vertical, - Type = RangeSliderType.Multiple, + Type = LinearRangeType.Multiple, Width = 10, }; view.Add (slider);