Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DarkListView scrolls very slowly with small amount of items #43

Open
istir opened this issue Sep 27, 2020 · 1 comment
Open

DarkListView scrolls very slowly with small amount of items #43

istir opened this issue Sep 27, 2020 · 1 comment

Comments

@istir
Copy link

istir commented Sep 27, 2020

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.

@varandas79
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants