Browse Source

Replace local var with private getter field.

BDisp 1 year ago
parent
commit
7489d6ca89
1 changed files with 9 additions and 12 deletions
  1. 9 12
      Terminal.Gui/Views/Scroll.cs

+ 9 - 12
Terminal.Gui/Views/Scroll.cs

@@ -37,6 +37,8 @@ public class Scroll : View
 
 
     private bool _wasSliderMouse;
     private bool _wasSliderMouse;
 
 
+    private int _barSize => Orientation == Orientation.Vertical ? GetContentSize ().Height : GetContentSize ().Width;
+
     private Orientation _orientation;
     private Orientation _orientation;
     /// <summary>
     /// <summary>
     ///     Gets or sets if the Scroll is oriented vertically or horizontally.
     ///     Gets or sets if the Scroll is oriented vertically or horizontally.
@@ -60,9 +62,7 @@ public class Scroll : View
         get => _position;
         get => _position;
         set
         set
         {
         {
-            int barSize = Orientation == Orientation.Vertical ? GetContentSize ().Height : GetContentSize ().Width;
-
-            if (value < 0 || (value > 0 && value + barSize > Size))
+            if (value < 0 || (value > 0 && value + _barSize > Size))
             {
             {
                 return;
                 return;
             }
             }
@@ -74,7 +74,6 @@ public class Scroll : View
                 return;
                 return;
             }
             }
 
 
-
             if (!_wasSliderMouse)
             if (!_wasSliderMouse)
             {
             {
                 AdjustSlider ();
                 AdjustSlider ();
@@ -228,7 +227,6 @@ public class Scroll : View
     {
     {
         MouseEvent me = e.MouseEvent;
         MouseEvent me = e.MouseEvent;
         int location = Orientation == Orientation.Vertical ? me.Position.Y : me.Position.X;
         int location = Orientation == Orientation.Vertical ? me.Position.Y : me.Position.X;
-        int barSize = Orientation == Orientation.Vertical ? GetContentSize ().Height : GetContentSize ().Width;
 
 
         (int topLeft, int bottomRight) sliderPos = _orientation == Orientation.Vertical
         (int topLeft, int bottomRight) sliderPos = _orientation == Orientation.Vertical
                                                        ? new (_slider.Frame.Y, _slider.Frame.Bottom - 1)
                                                        ? new (_slider.Frame.Y, _slider.Frame.Bottom - 1)
@@ -236,16 +234,16 @@ public class Scroll : View
 
 
         if (me.Flags == MouseFlags.Button1Pressed && location < sliderPos.topLeft)
         if (me.Flags == MouseFlags.Button1Pressed && location < sliderPos.topLeft)
         {
         {
-            Position = Math.Max (Position - barSize, 0);
+            Position = Math.Max (Position - _barSize, 0);
         }
         }
         else if (me.Flags == MouseFlags.Button1Pressed && location > sliderPos.bottomRight)
         else if (me.Flags == MouseFlags.Button1Pressed && location > sliderPos.bottomRight)
         {
         {
-            Position = Math.Min (Position + barSize, Size - barSize);
+            Position = Math.Min (Position + _barSize, Size - _barSize);
         }
         }
         else if ((me.Flags == MouseFlags.WheeledDown && Orientation == Orientation.Vertical)
         else if ((me.Flags == MouseFlags.WheeledDown && Orientation == Orientation.Vertical)
                  || (me.Flags == MouseFlags.WheeledRight && Orientation == Orientation.Horizontal))
                  || (me.Flags == MouseFlags.WheeledRight && Orientation == Orientation.Horizontal))
         {
         {
-            Position = Math.Min (Position + 1, Size - barSize);
+            Position = Math.Min (Position + 1, Size - _barSize);
         }
         }
         else if ((me.Flags == MouseFlags.WheeledUp && Orientation == Orientation.Vertical)
         else if ((me.Flags == MouseFlags.WheeledUp && Orientation == Orientation.Vertical)
                  || (me.Flags == MouseFlags.WheeledLeft && Orientation == Orientation.Horizontal))
                  || (me.Flags == MouseFlags.WheeledLeft && Orientation == Orientation.Horizontal))
@@ -327,7 +325,6 @@ public class Scroll : View
     {
     {
         MouseEvent me = e.MouseEvent;
         MouseEvent me = e.MouseEvent;
         int location = Orientation == Orientation.Vertical ? me.Position.Y : me.Position.X;
         int location = Orientation == Orientation.Vertical ? me.Position.Y : me.Position.X;
-        int barSize = Orientation == Orientation.Vertical ? GetContentSize ().Height : GetContentSize ().Width;
         int offset = _lastLocation > -1 ? location - _lastLocation : 0;
         int offset = _lastLocation > -1 ? location - _lastLocation : 0;
 
 
         if (me.Flags == MouseFlags.Button1Pressed)
         if (me.Flags == MouseFlags.Button1Pressed)
@@ -342,7 +339,7 @@ public class Scroll : View
         {
         {
             if (Orientation == Orientation.Vertical)
             if (Orientation == Orientation.Vertical)
             {
             {
-                if (_slider.Frame.Y + offset >= 0 && _slider.Frame.Y + offset + _slider.Frame.Height <= barSize)
+                if (_slider.Frame.Y + offset >= 0 && _slider.Frame.Y + offset + _slider.Frame.Height <= _barSize)
                 {
                 {
                     _wasSliderMouse = true;
                     _wasSliderMouse = true;
                     _slider.Y = _slider.Frame.Y + offset;
                     _slider.Y = _slider.Frame.Y + offset;
@@ -351,7 +348,7 @@ public class Scroll : View
             }
             }
             else
             else
             {
             {
-                if (_slider.Frame.X + offset >= 0 && _slider.Frame.X + offset + _slider.Frame.Width <= barSize)
+                if (_slider.Frame.X + offset >= 0 && _slider.Frame.X + offset + _slider.Frame.Width <= _barSize)
                 {
                 {
                     _wasSliderMouse = true;
                     _wasSliderMouse = true;
                     _slider.X = _slider.Frame.X + offset;
                     _slider.X = _slider.Frame.X + offset;
@@ -371,7 +368,7 @@ public class Scroll : View
         else if ((me.Flags == MouseFlags.WheeledDown && Orientation == Orientation.Vertical)
         else if ((me.Flags == MouseFlags.WheeledDown && Orientation == Orientation.Vertical)
                  || (me.Flags == MouseFlags.WheeledRight && Orientation == Orientation.Horizontal))
                  || (me.Flags == MouseFlags.WheeledRight && Orientation == Orientation.Horizontal))
         {
         {
-            Position = Math.Min (Position + 1, Size - barSize);
+            Position = Math.Min (Position + 1, Size - _barSize);
         }
         }
         else if ((me.Flags == MouseFlags.WheeledUp && Orientation == Orientation.Vertical)
         else if ((me.Flags == MouseFlags.WheeledUp && Orientation == Orientation.Vertical)
                  || (me.Flags == MouseFlags.WheeledLeft && Orientation == Orientation.Horizontal))
                  || (me.Flags == MouseFlags.WheeledLeft && Orientation == Orientation.Horizontal))