DarkListView scrolls very slowly with small amount of items
istir opened this issue · comments
Hello,
I encountered a weird problem, that would indicate a connection between the total amount of items in a DarkListView and the scroll speed of said control.
If I'm using 20 items it takes around 5-6 "scrolls" with the wheel to scroll down by 1 item, however if I'm using 100 items it only takes around 1,5 "scrolls". This behavior doesn't occur in a standard ListView control - the scroll amount is always the same.
It obviously works as intended with more items, but I find it highly frustrating having to scroll 20 times to get down 3 items.
I downloaded the package from NuGet, but also cloned the repository and checked the Example project - the behavior is the same as in my project.
Hello,
In my case I've to solve this issue by adapting the UpdateThumb method into DarkScrollBar.cs
private void UpdateThumb(bool forceRefresh = false)
{
// Calculate size ratio
float maxsize = (float)((Minimum < Maximum) ? (Maximum - Minimum) : (Maximum - Minimum));
if (maxsize == 0)
_viewContentRatio = 1.0f;
else
_viewContentRatio = (_scrollOrientation == DarkScrollOrientation.Vertical) ? (Height / maxsize) : (Width / maxsize);
var viewAreaSize = Math.Max(maxsize, 1);
var positionRatio = ((float)Value - Minimum) / (float)viewAreaSize;
if (Minimum < 0)
{
positionRatio = (float) ((Minimum*-1) + (float) Value)/(float) viewAreaSize;
}
// Update area
if (_scrollOrientation == DarkScrollOrientation.Vertical)
{
var thumbSize = (int)(_trackArea.Height * _viewContentRatio);
_thumbArea = new Rectangle(_trackArea.Left + 3, _trackArea.Top + (int)(_trackArea.Height * positionRatio),
Consts.ScrollBarSize - 6, Math.Max(thumbSize, Consts.MinimumThumbSize));
}
else
{
var thumbSize = (int)(_trackArea.Width * _viewContentRatio);
_thumbArea = new Rectangle(_trackArea.Left + (int)(_trackArea.Width * positionRatio), _trackArea.Top + 3,
Math.Max(thumbSize, Consts.MinimumThumbSize), Consts.ScrollBarSize - 6);
}
if (forceRefresh)
{
Invalidate();
Update();
}
}
And OnMouseWheel into DarkScrollBase.cs
protected override void OnMouseWheel(MouseEventArgs e)
{
base.OnMouseWheel(e);
const int offset = 50;
var horizontal = false;
if (_hScrollBar.Visible && ModifierKeys == Keys.Control)
horizontal = true;
if (_hScrollBar.Visible && !_vScrollBar.Visible)
horizontal = true;
if (!horizontal)
{
if (e.Delta > 0)
_vScrollBar.ScrollBy(-offset);
else if (e.Delta < 0)
_vScrollBar.ScrollBy(offset);
}
else
{
if (e.Delta > 0)
_hScrollBar.ScrollBy(-offset);
else if (e.Delta < 0)
_hScrollBar.ScrollBy(offset);
}
}
You can also change the scroll speed by changing the offset value.