Pārlūkot izejas kodu

Makes Scroll clicks move proportionally

Tig 11 mēneši atpakaļ
vecāks
revīzija
3701e2171a
1 mainītis faili ar 11 papildinājumiem un 7 dzēšanām
  1. 11 7
      Terminal.Gui/Views/Scroll/Scroll.cs

+ 11 - 7
Terminal.Gui/Views/Scroll/Scroll.cs

@@ -128,17 +128,21 @@ public class Scroll : View
         int location = Orientation == Orientation.Vertical ? mouseEvent.Position.Y : mouseEvent.Position.X;
         int barSize = BarSize;
 
-        (int topLeft, int bottomRight) sliderPos = _orientation == Orientation.Vertical
-                                                       ? new (_slider.Frame.Y, _slider.Frame.Bottom - 1)
-                                                       : new (_slider.Frame.X, _slider.Frame.Right - 1);
+        (int start, int end) sliderPos = _orientation == Orientation.Vertical
+                                             ? new (_slider.Frame.Y, _slider.Frame.Bottom - 1)
+                                             : new (_slider.Frame.X, _slider.Frame.Right - 1);
 
-        if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed) && location < sliderPos.topLeft)
+        if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed) && location < sliderPos.start)
         {
-            Position = Math.Max (Position - barSize, 0);
+            int distance = sliderPos.start - location;
+            int scrollAmount = (int)((double)distance / barSize * (Size - barSize));
+            Position = Math.Max (Position - scrollAmount, 0);
         }
-        else if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed) && location > sliderPos.bottomRight)
+        else if (mouseEvent.Flags.HasFlag (MouseFlags.Button1Pressed) && location > sliderPos.end)
         {
-            Position = Math.Min (Position + barSize, Size - barSize);
+            int distance = location - sliderPos.end;
+            int scrollAmount = (int)((double)distance / barSize * (Size - barSize));
+            Position = Math.Min (Position + scrollAmount, Size - barSize);
         }
         else if ((mouseEvent.Flags == MouseFlags.WheeledDown && Orientation == Orientation.Vertical)
                  || (mouseEvent.Flags == MouseFlags.WheeledRight && Orientation == Orientation.Horizontal))