diff --git a/Terminal.Gui/Views/Scroll.cs b/Terminal.Gui/Views/Scroll.cs index 9ce5b14e1..3aa9f0e6b 100644 --- a/Terminal.Gui/Views/Scroll.cs +++ b/Terminal.Gui/Views/Scroll.cs @@ -1,4 +1,6 @@ -namespace Terminal.Gui; +using System.ComponentModel; + +namespace Terminal.Gui; /// /// Provides a proportional control for scrolling through content. Used within a . @@ -73,7 +75,7 @@ public class Scroll : View return; } - StateEventArgs args = OnPositionChanging (_position, value); + CancelEventArgs args = OnPositionChanging (_position, value); if (args.Cancel) { @@ -85,25 +87,24 @@ public class Scroll : View AdjustSlider (); } - int oldPos = _position; _position = value; - OnPositionChanged (oldPos); + OnPositionChanged (_position); } } /// Raised when the has changed. - public event EventHandler> PositionChanged; + public event EventHandler> PositionChanged; - /// Raised when the is changing. Set to to prevent the position from being changed. - public event EventHandler> PositionChanging; + /// Raised when the is changing. Set to to prevent the position from being changed. + public event EventHandler> PositionChanging; - /// Virtual method called when has changed. Fires . - protected virtual void OnPositionChanged (int oldPos) { PositionChanged?.Invoke (this, new (oldPos, Position)); } + /// Virtual method called when has changed. Raises . + protected virtual void OnPositionChanged (int position) { PositionChanged?.Invoke (this, new (ref position)); } - /// Virtual method called when is changing. Fires , which is cancelable. - protected virtual StateEventArgs OnPositionChanging (int oldPos, int newPos) + /// Virtual method called when is changing. Raises , which is cancelable. + protected virtual CancelEventArgs OnPositionChanging (int currentPos, int newPos) { - StateEventArgs args = new (oldPos, newPos); + CancelEventArgs args = new (ref currentPos, ref newPos); PositionChanging?.Invoke (this, args); return args; @@ -118,18 +119,17 @@ public class Scroll : View get => _size; set { - int oldSize = _size; _size = value; - OnSizeChanged (oldSize); + OnSizeChanged (_size); AdjustSlider (); } } /// Raised when has changed. - public event EventHandler> SizeChanged; + public event EventHandler> SizeChanged; - /// Virtual method called when has changed. Fires . - protected void OnSizeChanged (int oldSize) { SizeChanged?.Invoke (this, new (oldSize, Size)); } + /// Virtual method called when has changed. Raises . + protected void OnSizeChanged (int size) { SizeChanged?.Invoke (this, new (ref size)); } private int GetPositionFromSliderLocation (int location) { diff --git a/UICatalog/Scenarios/ScrollDemo.cs b/UICatalog/Scenarios/ScrollDemo.cs index 955fa91b2..6412f6112 100644 --- a/UICatalog/Scenarios/ScrollDemo.cs +++ b/UICatalog/Scenarios/ScrollDemo.cs @@ -181,11 +181,11 @@ public class ScrollDemo : Scenario scroll.SizeChanged += (s, e) => { - lblSizeChanged.Text = $"SizeChanged event - OldValue: {e.OldValue}; NewValue: {e.NewValue}"; + lblSizeChanged.Text = $"SizeChanged event - CurrentValue: {e.CurrentValue}"; - if (scrollSize.Value != e.NewValue) + if (scrollSize.Value != e.CurrentValue) { - scrollSize.Value = e.NewValue; + scrollSize.Value = e.CurrentValue; } }; @@ -195,7 +195,7 @@ public class ScrollDemo : Scenario }; view.Add (lblPosChanging); - scroll.PositionChanging += (s, e) => { lblPosChanging.Text = $"PositionChanging event - OldValue: {e.OldValue}; NewValue: {e.NewValue}"; }; + scroll.PositionChanging += (s, e) => { lblPosChanging.Text = $"PositionChanging event - CurrentValue: {e.CurrentValue}; NewValue: {e.NewValue}"; }; var lblPositionChanged = new Label { @@ -205,8 +205,8 @@ public class ScrollDemo : Scenario scroll.PositionChanged += (s, e) => { - lblPositionChanged.Text = $"PositionChanged event - OldValue: {e.OldValue}; NewValue: {e.NewValue}"; - scrollPosition.Value = e.NewValue; + lblPositionChanged.Text = $"PositionChanged event - CurrentValue: {e.CurrentValue}"; + scrollPosition.Value = e.CurrentValue; }; var lblScrollFrame = new Label diff --git a/UnitTests/Views/ScrollTests.cs b/UnitTests/Views/ScrollTests.cs index 19b3d98e8..f39091c26 100644 --- a/UnitTests/Views/ScrollTests.cs +++ b/UnitTests/Views/ScrollTests.cs @@ -899,13 +899,13 @@ public class ScrollTests scroll.PositionChanged -= Scroll_PositionChanged; - void Scroll_PositionChanging (object sender, StateEventArgs e) + void Scroll_PositionChanging (object sender, CancelEventArgs e) { changing++; e.Cancel = cancel; } - void Scroll_PositionChanged (object sender, StateEventArgs e) => changed++; + void Scroll_PositionChanged (object sender, EventArgs e) => changed++; void Reset () {