Fixed latent bug in ScrollBarView

This commit is contained in:
Tig
2024-04-12 09:34:57 -06:00
parent 248bbe0afc
commit 1ffabac38b
2 changed files with 13 additions and 7 deletions

View File

@@ -273,7 +273,10 @@ public class ListView : View
}
}
/// <summary>Gets or sets the item that is displayed at the top of the <see cref="ListView"/>.</summary>
/// <summary>Gets or sets the index of the item that will appear at the top of the <see cref="View.Viewport"/>.</summary>
/// <remarks>
/// This a helper property for accessing <c>listView.Viewport.Y</c>.
/// </remarks>
/// <value>The top item.</value>
public int TopItem
{
@@ -285,13 +288,7 @@ public class ListView : View
return;
}
if (value < 0 || (_source.Count > 0 && value >= _source.Count))
{
throw new ArgumentException ("value");
}
Viewport = Viewport with { Y = value };
SetNeedsDisplay ();
}
}

View File

@@ -204,6 +204,11 @@ public class ScrollBarView : View
get => _position;
set
{
if (_position == value)
{
return;
}
_position = value;
if (IsInitialized)
@@ -900,6 +905,10 @@ public class ScrollBarView : View
// Helper to assist Initialized event handler
private void SetPosition (int newPosition)
{
if (newPosition < 0)
{
return;
}
if (CanScroll (newPosition - _position, out int max, _vertical))
{
if (max == newPosition - _position)