Browse Source

Code cleanup.

BDisp 11 months ago
parent
commit
7a1eb9846e

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

@@ -35,11 +35,10 @@ public class Scroll : View
         }
         }
     }
     }
 
 
-
     internal readonly ScrollBar? _host;
     internal readonly ScrollBar? _host;
-    internal bool _wasSliderLayoutComplete = true;
 
 
     internal readonly ScrollSlider _slider;
     internal readonly ScrollSlider _slider;
+    internal bool _wasSliderLayoutComplete = true;
     private Orientation _orientation;
     private Orientation _orientation;
     private int _position;
     private int _position;
     private int _size;
     private int _size;
@@ -173,6 +172,7 @@ public class Scroll : View
                 return _slider.OnMouseEvent (mouseEvent);
                 return _slider.OnMouseEvent (mouseEvent);
             }
             }
         }
         }
+
         // Flag as false until slider layout is completed
         // Flag as false until slider layout is completed
         _wasSliderLayoutComplete = false;
         _wasSliderLayoutComplete = false;
 
 

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

@@ -145,14 +145,6 @@ internal class ScrollSlider : View
         return base.OnMouseLeave (mouseEvent);
         return base.OnMouseLeave (mouseEvent);
     }
     }
 
 
-    /// <inheritdoc />
-    internal override void OnLayoutComplete (LayoutEventArgs args)
-    {
-        base.OnLayoutComplete (args);
-
-        _host._wasSliderLayoutComplete = true;
-    }
-
     internal int GetPositionFromSliderLocation (int location)
     internal int GetPositionFromSliderLocation (int location)
     {
     {
         if (_host.GetContentSize ().Height == 0 || _host.GetContentSize ().Width == 0)
         if (_host.GetContentSize ().Height == 0 || _host.GetContentSize ().Width == 0)
@@ -167,7 +159,7 @@ internal class ScrollSlider : View
         if ((_host.Orientation == Orientation.Vertical && location + Frame.Height >= scrollSize)
         if ((_host.Orientation == Orientation.Vertical && location + Frame.Height >= scrollSize)
             || (_host.Orientation == Orientation.Horizontal && location + Frame.Width >= scrollSize))
             || (_host.Orientation == Orientation.Horizontal && location + Frame.Width >= scrollSize))
         {
         {
-                return _host.Size - scrollSize;
+            return _host.Size - scrollSize;
         }
         }
 
 
         return (int)Math.Min (Math.Round ((double)(location * _host.Size + location) / scrollSize), _host.Size - scrollSize);
         return (int)Math.Min (Math.Round ((double)(location * _host.Size + location) / scrollSize), _host.Size - scrollSize);
@@ -210,6 +202,14 @@ internal class ScrollSlider : View
         return new (location, dimension);
         return new (location, dimension);
     }
     }
 
 
+    /// <inheritdoc/>
+    internal override void OnLayoutComplete (LayoutEventArgs args)
+    {
+        base.OnLayoutComplete (args);
+
+        _host._wasSliderLayoutComplete = true;
+    }
+
     // TODO: I think you should create a new `internal` view named "ScrollSlider" with an `Orientation` property. It should inherit from View and override GetNormalColor and the mouse events
     // TODO: I think you should create a new `internal` view named "ScrollSlider" with an `Orientation` property. It should inherit from View and override GetNormalColor and the mouse events
     // that can be moved within it's Superview, constrained to move only horizontally or vertically depending on Orientation.
     // that can be moved within it's Superview, constrained to move only horizontally or vertically depending on Orientation.
     // This will really simplify a lot of this.
     // This will really simplify a lot of this.

+ 1 - 0
UnitTests/Views/ScrollSliderTests.cs

@@ -67,6 +67,7 @@ public class ScrollSliderTests
 
 
             host.Width = host.Orientation == Orientation.Vertical ? 1 : randomScrollLength;
             host.Width = host.Orientation == Orientation.Vertical ? 1 : randomScrollLength;
             host.Height = host.Orientation == Orientation.Vertical ? randomScrollLength : 1;
             host.Height = host.Orientation == Orientation.Vertical ? randomScrollLength : 1;
+
             // Slider may have changed content size
             // Slider may have changed content size
             host.LayoutSubviews ();
             host.LayoutSubviews ();