Code cleanup.

This commit is contained in:
BDisp
2024-08-25 21:00:59 +01:00
parent d47188f1f0
commit 7a1eb9846e
3 changed files with 12 additions and 11 deletions

View File

@@ -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;

View File

@@ -145,14 +145,6 @@ internal class ScrollSlider : View
return base.OnMouseLeave (mouseEvent);
}
/// <inheritdoc />
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);
}
/// <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
// 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.

View File

@@ -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 ();