diff --git a/Terminal.Gui/Views/Slider.cs b/Terminal.Gui/Views/LinearRange/LinearRange.cs similarity index 94% rename from Terminal.Gui/Views/Slider.cs rename to Terminal.Gui/Views/LinearRange/LinearRange.cs index ff37d513c0..3930656742 100644 --- a/Terminal.Gui/Views/Slider.cs +++ b/Terminal.Gui/Views/LinearRange/LinearRange.cs @@ -3,15 +3,15 @@ namespace Terminal.Gui; /// Slider control. -public class Slider : Slider +public class LinearRange : LinearRange { - /// Initializes a new instance of the class. - public Slider () { } + /// 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 Slider (List options, Orientation orientation = Orientation.Horizontal) : + public LinearRange (List options, Orientation orientation = Orientation.Horizontal) : base (options, orientation) { } } @@ -21,22 +21,22 @@ public Slider (List options, Orientation orientation = Orientation.Horiz /// keyboard or mouse. /// /// -public class Slider : View, IOrientation +public class LinearRange : View, IOrientation { - private readonly SliderConfiguration _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 Slider () : 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 Slider (List options, Orientation orientation = Orientation.Horizontal) + public LinearRange (List options, Orientation orientation = Orientation.Horizontal) { if (options is null) { @@ -137,7 +137,7 @@ public Slider (List options, Orientation orientation = Orientation.Horizontal { var legend = e.ToString (); - return new SliderOption + 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 SliderOption { Legend = x }).ToList (); + Options = list.Select (x => new LinearRangeOption { Legend = x }).ToList (); } } } @@ -212,8 +212,8 @@ public int MinimumInnerSpacing } } - /// Slider Type. - public SliderType Type + /// Slider Type. + public LinearRangeType Type { get => _config._type; set @@ -278,11 +278,11 @@ public Orientation LegendsOrientation } } - /// Slider styles. - public SliderStyle 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, SliderEventArgs 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 (SliderOption 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] : ' '); } @@ -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 @@ -867,11 +867,11 @@ private void DrawSlider () if (_config._showEndSpacing && _config._startSpacing > 0) { SetAttribute ( - isSet && _config._type == SliderType.LeftRange + isSet && _config._type == LinearRangeType.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 == 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 SliderType.LeftRange when i <= _setOptions [0]: + case LinearRangeType.LeftRange when i <= _setOptions [0]: drawRange = i < _setOptions [0]; break; - case SliderType.RightRange when i >= _setOptions [0]: + case LinearRangeType.RightRange when i >= _setOptions [0]: drawRange = i >= _setOptions [0]; break; - case SliderType.Range when _setOptions.Count == 1: + case LinearRangeType.Range when _setOptions.Count == 1: drawRange = false; break; - case SliderType.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 == SliderType.RightRange + isSet && _config._type == LinearRangeType.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 == 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 SliderType.Single: - case SliderType.Multiple: + case LinearRangeType.Single: + case LinearRangeType.Multiple: if (isSet && _setOptions.Contains (i)) { isOptionSet = true; } break; - case SliderType.LeftRange: + case LinearRangeType.LeftRange: if (isSet && i <= _setOptions [0]) { isOptionSet = true; } break; - case SliderType.RightRange: + case LinearRangeType.RightRange: if (isSet && i >= _setOptions [0]) { isOptionSet = true; } break; - case SliderType.Range when _setOptions.Count == 1: + case LinearRangeType.Range when _setOptions.Count == 1: if (isSet && i == _setOptions [0]) { isOptionSet = true; } break; - case SliderType.Range: + case LinearRangeType.Range: if (isSet && ((i >= _setOptions [0] && i <= _setOptions [1]) || (i >= _setOptions [1] && i <= _setOptions [0]))) @@ -1172,7 +1172,7 @@ private void DrawLegends () switch (_config._legendsOrientation) { case Orientation.Horizontal: - x = 1; + x = 2; break; case Orientation.Vertical: @@ -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 LinearRangeType.Single: + case LinearRangeType.LeftRange: + case LinearRangeType.RightRange: if (_setOptions.Count == 1) { @@ -1538,7 +1538,7 @@ private bool SetFocusedOption () changed = true; break; - case SliderType.Multiple: + case LinearRangeType.Multiple: if (_setOptions.Contains (FocusedOption)) { if (!_config._allowEmpty && _setOptions.Count () == 1) @@ -1560,7 +1560,7 @@ private bool SetFocusedOption () break; - case SliderType.Range: + case LinearRangeType.Range: if (_config._rangeAllowSingle) { if (_setOptions.Count == 1) diff --git a/Terminal.Gui/Views/SliderAttributes.cs b/Terminal.Gui/Views/LinearRange/LinearRangeAttributes.cs similarity index 80% rename from Terminal.Gui/Views/SliderAttributes.cs rename to Terminal.Gui/Views/LinearRange/LinearRangeAttributes.cs index 6f75546dd3..62004a1189 100644 --- a/Terminal.Gui/Views/SliderAttributes.cs +++ b/Terminal.Gui/Views/LinearRange/LinearRangeAttributes.cs @@ -1,7 +1,7 @@ namespace Terminal.Gui; -/// Legend Style -public class SliderAttributes +/// Legend Style +public class LinearRangeAttributes { /// Attribute for the Legends Container. public Attribute? EmptyAttribute { get; set; } diff --git a/Terminal.Gui/Views/SliderConfiguration.cs b/Terminal.Gui/Views/LinearRange/LinearRangeConfiguration.cs similarity index 73% rename from Terminal.Gui/Views/SliderConfiguration.cs rename to Terminal.Gui/Views/LinearRange/LinearRangeConfiguration.cs index 3cadafd869..cc44159606 100644 --- a/Terminal.Gui/Views/SliderConfiguration.cs +++ b/Terminal.Gui/Views/LinearRange/LinearRangeConfiguration.cs @@ -1,7 +1,7 @@ namespace Terminal.Gui; -/// All configuration are grouped in this class. -internal class SliderConfiguration +/// All configuration are grouped in this class. +internal class LinearRangeConfiguration { 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 LinearRangeType _type = LinearRangeType.Single; internal bool _useMinimumSize; } \ No newline at end of file diff --git a/Terminal.Gui/Views/SliderEventArgs.cs b/Terminal.Gui/Views/LinearRange/LinearRangeEventArgs.cs similarity index 60% rename from Terminal.Gui/Views/SliderEventArgs.cs rename to Terminal.Gui/Views/LinearRange/LinearRangeEventArgs.cs index 76c4eed90a..3e329a292b 100644 --- a/Terminal.Gui/Views/SliderEventArgs.cs +++ b/Terminal.Gui/Views/LinearRange/LinearRangeEventArgs.cs @@ -1,12 +1,12 @@ namespace Terminal.Gui; -/// for events. -public class SliderEventArgs : 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 SliderEventArgs (Dictionary> options, int focused = -1) + public LinearRangeEventArgs (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/SliderOption.cs b/Terminal.Gui/Views/LinearRange/LinearRangeOption.cs similarity index 65% rename from Terminal.Gui/Views/SliderOption.cs rename to Terminal.Gui/Views/LinearRange/LinearRangeOption.cs index a3d10781dd..5fd8d8a238 100644 --- a/Terminal.Gui/Views/SliderOption.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 SliderOption +public class LinearRangeOption { - /// Creates a new empty instance of the class. - public SliderOption () { } + /// Creates a new empty instance of the class. + public LinearRangeOption () { } - /// 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 LinearRangeOption (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; } @@ -25,19 +25,19 @@ public SliderOption (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/SliderStyle.cs b/Terminal.Gui/Views/LinearRange/LinearRangeStyle.cs similarity index 85% rename from Terminal.Gui/Views/SliderStyle.cs rename to Terminal.Gui/Views/LinearRange/LinearRangeStyle.cs index e6429d6cb9..30baa20a1b 100644 --- a/Terminal.Gui/Views/SliderStyle.cs +++ b/Terminal.Gui/Views/LinearRange/LinearRangeStyle.cs @@ -1,10 +1,10 @@ namespace Terminal.Gui; -/// Style -public class SliderStyle +/// Style +public class LinearRangeStyle { /// Constructs a new instance. - public SliderStyle () { 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 SliderStyle public Cell EndRangeChar { get; set; } /// Legend attributes - public SliderAttributes 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/SliderType.cs b/Terminal.Gui/Views/LinearRange/LinearRangeType.cs similarity index 91% rename from Terminal.Gui/Views/SliderType.cs rename to Terminal.Gui/Views/LinearRange/LinearRangeType.cs index 7cbde908a6..d236d09c9d 100644 --- a/Terminal.Gui/Views/SliderType.cs +++ b/Terminal.Gui/Views/LinearRange/LinearRangeType.cs @@ -1,7 +1,7 @@ namespace Terminal.Gui; -/// Types -public enum SliderType +/// Types +public enum LinearRangeType { /// /// 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/Terminal.Gui/Views/SliderOptionEventArgs.cs b/Terminal.Gui/Views/SliderOptionEventArgs.cs deleted file mode 100644 index b4b5e69366..0000000000 --- a/Terminal.Gui/Views/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..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" }; - Slider slider = new (options) + LinearRange slider = new (options) { X = 0, Y = 0, - Type = SliderType.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 947c7b4d8d..8dabc0730a 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,39 +18,41 @@ public ArrangementEditor () Initialized += ArrangementEditor_Initialized; + _arrangementSlider.MinimumInnerSpacing = 0; + _arrangementSlider.Options = [ - new SliderOption + new LinearRangeOption { - Legend = ViewArrangement.Movable.ToString (), + Legend = $"{ViewArrangement.Movable}", Data = ViewArrangement.Movable }, - new SliderOption + new LinearRangeOption { Legend = ViewArrangement.LeftResizable.ToString (), Data = ViewArrangement.LeftResizable }, - new SliderOption + new LinearRangeOption { Legend = ViewArrangement.RightResizable.ToString (), Data = ViewArrangement.RightResizable }, - new SliderOption + new LinearRangeOption { Legend = ViewArrangement.TopResizable.ToString (), Data = ViewArrangement.TopResizable }, - new SliderOption + new LinearRangeOption { Legend = ViewArrangement.BottomResizable.ToString (), Data = ViewArrangement.BottomResizable }, - new SliderOption + new LinearRangeOption { Legend = ViewArrangement.Overlapped.ToString (), Data = ViewArrangement.Overlapped @@ -59,11 +62,11 @@ public ArrangementEditor () Add (_arrangementSlider); } - private readonly Slider _arrangementSlider = new() + private readonly LinearRange _arrangementSlider = new() { Orientation = Orientation.Vertical, UseMinimumSize = true, - Type = SliderType.Multiple, + Type = LinearRangeType.Multiple, AllowEmpty = true, }; @@ -88,16 +91,27 @@ 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, SliderEventArgs 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/Sliders.cs b/UICatalog/Scenarios/LinearRange.cs similarity index 91% rename from UICatalog/Scenarios/Sliders.cs rename to UICatalog/Scenarios/LinearRange.cs index 7645d1753a..3d323477c8 100644 --- a/UICatalog/Scenarios/Sliders.cs +++ b/UICatalog/Scenarios/LinearRange.cs @@ -8,18 +8,18 @@ namespace UICatalog.Scenarios; -[ScenarioMetadata ("Sliders", "Demonstrates the Slider view.")] +[ScenarioMetadata ("LinearRanges", "Demonstrates the LinearRange view.")] [ScenarioCategory ("Controls")] -public class Sliders : Scenario +public class LinearRanges : Scenario { public void MakeSliders (View v, List options) { - List types = Enum.GetValues (typeof (SliderType)).Cast ().ToList (); - Slider prev = null; + List types = Enum.GetValues (typeof (LinearRangeType)).Cast ().ToList (); + LinearRange prev = null; - foreach (SliderType type in types) + foreach (LinearRangeType type in types) { - var view = new Slider (options) + var view = new LinearRange (options) { Title = type.ToString (), X = 0, @@ -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; } @@ -76,12 +76,12 @@ public void MakeSliders (View v, List options) 39 }; - var single = new Slider (singleOptions) + var single = new LinearRange (singleOptions) { Title = "_Continuous", X = 0, Y = prev == null ? 0 : Pos.Bottom (prev), - Type = SliderType.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 Slider (oneOption) + var one = new LinearRange (oneOption) { Title = "_One Option", X = 0, Y = prev == null ? 0 : Pos.Bottom (single), - Type = SliderType.Single, + Type = LinearRangeType.Single, BorderStyle = LineStyle.Single, AllowEmpty = false }; @@ -163,13 +163,13 @@ public override void Main () #region Config Slider - Slider optionsSlider = new () + LinearRange optionsSlider = new () { Title = "Options", X = 0, Y = 0, Width = Dim.Fill (), - Type = SliderType.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 (Slider 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 (Slider 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 - Slider 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 (Slider 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 - Slider 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 (Slider 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 (Slider 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 (Slider 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 () }; } - Slider<(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 = SliderType.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 SliderOption<(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 (Slider 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 () } }; - Slider<(Color, Color)> sliderBGColor = new () + LinearRange<(Color, Color)> sliderBGColor = new () { Title = "BG Color", X = Pos.Right (sliderFGColor), Y = Pos.Top (sliderFGColor), - Type = SliderType.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 (Slider 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 (Slider slider in app.Subviews.Where (v => v is Slider)!) + 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 dd1a087895..a00f62499d 100644 --- a/UICatalog/Scenarios/Mouse.cs +++ b/UICatalog/Scenarios/Mouse.cs @@ -19,13 +19,13 @@ public override void Main () Title = GetQuitKeyAndName () }; - Slider filterSlider = new () + LinearRange filterSlider = new () { Title = "_Filter", X = 0, Y = 0, BorderStyle = LineStyle.Single, - Type = SliderType.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 SliderOption + value => new LinearRangeOption { Legend = value.ToString (), Data = value diff --git a/UICatalog/Scenarios/Shortcuts.cs b/UICatalog/Scenarios/Shortcuts.cs index 5390e015d8..8d4794b9c4 100644 --- a/UICatalog/Scenarios/Shortcuts.cs +++ b/UICatalog/Scenarios/Shortcuts.cs @@ -246,7 +246,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 LinearRange { Orientation = Orientation.Horizontal, AllowEmpty = true @@ -254,12 +254,12 @@ private void App_Loaded (object? sender, EventArgs e) Key = Key.F5, }; - ((Slider)sliderShortcut.CommandView).Options = [new () { Legend = "A" }, new () { Legend = "B" }, new () { Legend = "C" }]; - ((Slider)sliderShortcut.CommandView).SetOption (0); + ((LinearRange)sliderShortcut.CommandView).Options = new () { new () { Legend = "A" }, new () { Legend = "B" }, new () { Legend = "C" } }; + ((LinearRange)sliderShortcut.CommandView).SetOption (0); - ((Slider)sliderShortcut.CommandView).OptionsChanged += (o, args) => + ((LinearRange)sliderShortcut.CommandView).OptionsChanged += (o, args) => { - eventSource.Add ($"OptionsChanged: {o?.GetType ().Name} - {string.Join (",", ((Slider)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 4842f1529f..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" }; - Slider slider = new (options) + LinearRange slider = new (options) { X = 0, Y = Pos.Bottom (textField) + 1, Orientation = Orientation.Vertical, - Type = SliderType.Multiple, + Type = LinearRangeType.Multiple, AllowEmpty = false, BorderStyle = LineStyle.Double, Title = "_Slider" diff --git a/UnitTests/Views/SliderTests.cs b/UnitTests/Views/LinearRangeTests.cs similarity index 84% rename from UnitTests/Views/SliderTests.cs rename to UnitTests/Views/LinearRangeTests.cs index eaab6ba699..10fac689ca 100644 --- a/UnitTests/Views/SliderTests.cs +++ b/UnitTests/Views/LinearRangeTests.cs @@ -8,7 +8,7 @@ public class SliderOptionTests public void OnChanged_Should_Raise_ChangedEvent () { // Arrange - SliderOption 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 - SliderOption 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 - SliderOption 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 () { - SliderOption 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 () { - SliderOption 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 () { - SliderOption sliderOption = new (); + LinearRangeOption 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 }; + 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 () { - SliderOption 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 - SliderEventArgs 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 - SliderEventArgs 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 - SliderEventArgs sliderEventArgs = new (options); + LinearRangeEventArgs sliderEventArgs = new (options); // Assert Assert.Equal (options, sliderEventArgs.Options); } } -public class SliderTests +public class LinearRangeTests { [Fact] public void Constructor_Default () { // Arrange & Act - Slider 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 (SliderType.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 - Slider 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 - Slider 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 - Slider 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 - Slider 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; - SliderEventArgs 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 - Slider 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; - SliderEventArgs 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 - Slider 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 - Slider 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 - Slider 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 - Slider 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 - Slider 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 - Slider 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 - Slider 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 - Slider 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 - Slider 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 - Slider 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 - Slider 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 - Slider 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" }; - Slider slider = new (options) + LinearRange slider = new (options) { Orientation = Orientation.Vertical, - Type = SliderType.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" }; - Slider slider = new (options) + LinearRange slider = new (options) { Orientation = Orientation.Vertical, - Type = SliderType.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" }; - Slider slider = new (options) + LinearRange slider = new (options) { Orientation = Orientation.Vertical, - Type = SliderType.Multiple, + Type = LinearRangeType.Multiple, Width = 10, }; view.Add (slider);