From 7a1eb9846e29e7119d36daf876064e77c482fa2b Mon Sep 17 00:00:00 2001 From: BDisp Date: Sun, 25 Aug 2024 21:00:59 +0100 Subject: [PATCH] Code cleanup. --- Terminal.Gui/Views/Scroll/Scroll.cs | 4 ++-- Terminal.Gui/Views/Scroll/ScrollSlider.cs | 18 +++++++++--------- UnitTests/Views/ScrollSliderTests.cs | 1 + 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Terminal.Gui/Views/Scroll/Scroll.cs b/Terminal.Gui/Views/Scroll/Scroll.cs index f96cc200c..9be2495e1 100644 --- a/Terminal.Gui/Views/Scroll/Scroll.cs +++ b/Terminal.Gui/Views/Scroll/Scroll.cs @@ -35,11 +35,10 @@ public class Scroll : View } } - internal readonly ScrollBar? _host; - internal bool _wasSliderLayoutComplete = true; internal readonly ScrollSlider _slider; + internal bool _wasSliderLayoutComplete = true; private Orientation _orientation; private int _position; private int _size; @@ -173,6 +172,7 @@ public class Scroll : View return _slider.OnMouseEvent (mouseEvent); } } + // Flag as false until slider layout is completed _wasSliderLayoutComplete = false; diff --git a/Terminal.Gui/Views/Scroll/ScrollSlider.cs b/Terminal.Gui/Views/Scroll/ScrollSlider.cs index 32032e303..01057cefa 100644 --- a/Terminal.Gui/Views/Scroll/ScrollSlider.cs +++ b/Terminal.Gui/Views/Scroll/ScrollSlider.cs @@ -145,14 +145,6 @@ internal class ScrollSlider : View return base.OnMouseLeave (mouseEvent); } - /// - internal override void OnLayoutComplete (LayoutEventArgs args) - { - base.OnLayoutComplete (args); - - _host._wasSliderLayoutComplete = true; - } - internal int GetPositionFromSliderLocation (int location) { 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) || (_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); @@ -210,6 +202,14 @@ internal class ScrollSlider : View return new (location, dimension); } + /// + 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 // 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. diff --git a/UnitTests/Views/ScrollSliderTests.cs b/UnitTests/Views/ScrollSliderTests.cs index 9e0f75702..665f5a98a 100644 --- a/UnitTests/Views/ScrollSliderTests.cs +++ b/UnitTests/Views/ScrollSliderTests.cs @@ -67,6 +67,7 @@ public class ScrollSliderTests host.Width = host.Orientation == Orientation.Vertical ? 1 : randomScrollLength; host.Height = host.Orientation == Orientation.Vertical ? randomScrollLength : 1; + // Slider may have changed content size host.LayoutSubviews ();