Browse Source

Fix merge errors.

BDisp 1 year ago
parent
commit
f9aa619162
3 changed files with 25 additions and 25 deletions
  1. 17 17
      Terminal.Gui/Views/Scroll.cs
  2. 6 6
      UICatalog/Scenarios/ScrollDemo.cs
  3. 2 2
      UnitTests/Views/ScrollTests.cs

+ 17 - 17
Terminal.Gui/Views/Scroll.cs

@@ -1,4 +1,6 @@
-namespace Terminal.Gui;
+using System.ComponentModel;
+
+namespace Terminal.Gui;
 
 
 /// <summary>
 /// <summary>
 ///     Provides a proportional control for scrolling through content. Used within a <see cref="ScrollBar"/>.
 ///     Provides a proportional control for scrolling through content. Used within a <see cref="ScrollBar"/>.
@@ -73,7 +75,7 @@ public class Scroll : View
                 return;
                 return;
             }
             }
 
 
-            StateEventArgs<int> args = OnPositionChanging (_position, value);
+            CancelEventArgs<int> args = OnPositionChanging (_position, value);
 
 
             if (args.Cancel)
             if (args.Cancel)
             {
             {
@@ -85,25 +87,24 @@ public class Scroll : View
                 AdjustSlider ();
                 AdjustSlider ();
             }
             }
 
 
-            int oldPos = _position;
             _position = value;
             _position = value;
-            OnPositionChanged (oldPos);
+            OnPositionChanged (_position);
         }
         }
     }
     }
 
 
     /// <summary>Raised when the <see cref="Position"/> has changed.</summary>
     /// <summary>Raised when the <see cref="Position"/> has changed.</summary>
-    public event EventHandler<StateEventArgs<int>> PositionChanged;
+    public event EventHandler<EventArgs<int>> PositionChanged;
 
 
-    /// <summary>Raised when the <see cref="Position"/> is changing. Set <see cref="StateEventArgs{T}.Cancel"/> to <see langword="true"/> to prevent the position from being changed.</summary>
-    public event EventHandler<StateEventArgs<int>> PositionChanging;
+    /// <summary>Raised when the <see cref="Position"/> is changing. Set <see cref="CancelEventArgs.Cancel"/> to <see langword="true"/> to prevent the position from being changed.</summary>
+    public event EventHandler<CancelEventArgs<int>> PositionChanging;
 
 
-    /// <summary>Virtual method called when <see cref="Position"/> has changed. Fires <see cref="PositionChanged"/>.</summary>
-    protected virtual void OnPositionChanged (int oldPos) { PositionChanged?.Invoke (this, new (oldPos, Position)); }
+    /// <summary>Virtual method called when <see cref="Position"/> has changed. Raises <see cref="PositionChanged"/>.</summary>
+    protected virtual void OnPositionChanged (int position) { PositionChanged?.Invoke (this, new (ref position)); }
 
 
-    /// <summary>Virtual method called when <see cref="Position"/> is changing. Fires <see cref="PositionChanging"/>, which is cancelable.</summary>
-    protected virtual StateEventArgs<int> OnPositionChanging (int oldPos, int newPos)
+    /// <summary>Virtual method called when <see cref="Position"/> is changing. Raises <see cref="PositionChanging"/>, which is cancelable.</summary>
+    protected virtual CancelEventArgs<int> OnPositionChanging (int currentPos, int newPos)
     {
     {
-        StateEventArgs<int> args = new (oldPos, newPos);
+        CancelEventArgs<int> args = new (ref currentPos, ref newPos);
         PositionChanging?.Invoke (this, args);
         PositionChanging?.Invoke (this, args);
 
 
         return args;
         return args;
@@ -118,18 +119,17 @@ public class Scroll : View
         get => _size;
         get => _size;
         set
         set
         {
         {
-            int oldSize = _size;
             _size = value;
             _size = value;
-            OnSizeChanged (oldSize);
+            OnSizeChanged (_size);
             AdjustSlider ();
             AdjustSlider ();
         }
         }
     }
     }
 
 
     /// <summary>Raised when <see cref="Size"/> has changed.</summary>
     /// <summary>Raised when <see cref="Size"/> has changed.</summary>
-    public event EventHandler<StateEventArgs<int>> SizeChanged;
+    public event EventHandler<EventArgs<int>> SizeChanged;
 
 
-    /// <summary>Virtual method called when <see cref="Size"/> has changed. Fires <see cref="SizeChanged"/>.</summary>
-    protected void OnSizeChanged (int oldSize) { SizeChanged?.Invoke (this, new (oldSize, Size)); }
+    /// <summary>Virtual method called when <see cref="Size"/> has changed. Raises <see cref="SizeChanged"/>.</summary>
+    protected void OnSizeChanged (int size) { SizeChanged?.Invoke (this, new (ref size)); }
 
 
     private int GetPositionFromSliderLocation (int location)
     private int GetPositionFromSliderLocation (int location)
     {
     {

+ 6 - 6
UICatalog/Scenarios/ScrollDemo.cs

@@ -181,11 +181,11 @@ public class ScrollDemo : Scenario
 
 
         scroll.SizeChanged += (s, e) =>
         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);
         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
         var lblPositionChanged = new Label
         {
         {
@@ -205,8 +205,8 @@ public class ScrollDemo : Scenario
 
 
         scroll.PositionChanged += (s, e) =>
         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
         var lblScrollFrame = new Label

+ 2 - 2
UnitTests/Views/ScrollTests.cs

@@ -899,13 +899,13 @@ public class ScrollTests
         scroll.PositionChanged -= Scroll_PositionChanged;
         scroll.PositionChanged -= Scroll_PositionChanged;
 
 
 
 
-        void Scroll_PositionChanging (object sender, StateEventArgs<int> e)
+        void Scroll_PositionChanging (object sender, CancelEventArgs<int> e)
         {
         {
             changing++;
             changing++;
             e.Cancel = cancel;
             e.Cancel = cancel;
         }
         }
 
 
-        void Scroll_PositionChanged (object sender, StateEventArgs<int> e) => changed++;
+        void Scroll_PositionChanged (object sender, EventArgs<int> e) => changed++;
 
 
         void Reset ()
         void Reset ()
         {
         {