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

[4.1] Add option to configure mouse-wheel-zoom-step-size in Blazor and Avalonia #2507

Merged
merged 9 commits into from
Feb 23, 2024

Conversation

pauldendulk
Copy link
Member

@pauldendulk pauldendulk commented Feb 21, 2024

These properties have been added to Blazor and Avalonia:

    /// <summary>
    /// This enables an alternative mouse wheel method where the step size on each mouse wheel event can be configured
    /// by setting the ContinuousMouseWheelZoomStepSize.
    /// </summary>
    public bool UseContinuousMouseWheelZoom { get; set; } = false;
    /// <summary>
    /// The size of the mouse wheel steps used when UseContinuousMouseWheelZoom = true. The default is 0.1. A step 
    /// size of 1 would doubling or halving the scale of the map on each event.    
    /// </summary>
    public double ContinuousMouseWheelZoomStepSize { get; set; } = 0.1;

@pauldendulk pauldendulk changed the base branch from main to develop/4.1 February 21, 2024 14:17
@pauldendulk pauldendulk changed the title Smaller steps in Blazor mouse wheel zoom [4.1] Smaller steps in Blazor mouse wheel zoom Feb 21, 2024
@RobertWatchful
Copy link

RobertWatchful commented Feb 21, 2024

I looked at the variable speed of the mouse wheel event, and while it is quite a good feature for the mouse wheel, It doesn't seem to be so good for the trackpad users -so it is just an idea.

    private DateTime lastScrollTime = DateTime.Now;
    private double accumulatedDeltaY = 0;
    protected void OnMouseWheel(WheelEventArgs e)
    {
        TimeSpan elapsed = DateTime.Now - lastScrollTime;

        // Check if the time elapsed is quick or not
        // This doesn't work well with a touchpad for some reason?
        if (elapsed.TotalMilliseconds < 500)
        {
            Console.WriteLine($"MouseWheel speed < 500 (: {elapsed.TotalMilliseconds}");
            Map.Navigator.MouseWheelZoomContinuous(Math.Pow(2, e.DeltaY > 0 ? 0.25 : -0.25), e.ToLocation(_clientRect));
        } else
        {
            Console.WriteLine($"MouseWheelDelta speed > 500: {elapsed.TotalMilliseconds}");
            Map.Navigator.MouseWheelZoomContinuous(Math.Pow(2, e.DeltaY > 0 ? 0.08 : -0.08), e.ToLocation(_clientRect));
        }

        // Update last scroll time for the next event
        lastScrollTime = DateTime.Now;

        //if (UseContinuousMouseWheelZoom)
        //{
        //    var mouseWheelDelta = Math.Pow(2, e.DeltaY);
        //    Console.WriteLine($"MouseWheelDelta: {mouseWheelDelta}");
        //    var currentMousePosition = e.ToLocation(_clientRect);
        //    Map.Navigator.MouseWheelZoomContinuous(mouseWheelDelta, currentMousePosition);
        //}
        //else
        //{
        //    var mouseWheelDelta = (int)e.DeltaY * -1; // so that it zooms like on windows
        //    var currentMousePosition = e.ToLocation(_clientRect);
        //    Map.Navigator.MouseWheelZoom(mouseWheelDelta, currentMousePosition);
        //}
    }

@pauldendulk pauldendulk added this to the 4.1 milestone Feb 23, 2024
@pauldendulk pauldendulk linked an issue Feb 23, 2024 that may be closed by this pull request
@pauldendulk
Copy link
Member Author

This fixes #2033.

It makes the mouse wheel step configurable, which makes touchpad on Mac usable. For touchpad Windows it is also an improvement. Pads simulate the mouse wheel by triggering an event but are more frequent than a real mouse wheel. By making is configurable it becomes manageable, better would be if we could detect if it is a real mouse wheel or a pad.

@pauldendulk pauldendulk changed the title [4.1] Smaller steps in Blazor mouse wheel zoom [4.1] Add option to configure mouse wheel zoom step size in Blazor and Avalonia Feb 23, 2024
@pauldendulk pauldendulk changed the title [4.1] Add option to configure mouse wheel zoom step size in Blazor and Avalonia [4.1] Add option to configure mouse-wheel-zoom-step-size in Blazor and Avalonia Feb 23, 2024
@pauldendulk pauldendulk merged commit b7ab399 into develop/4.1 Feb 23, 2024
6 checks passed
@pauldendulk pauldendulk deleted the feature/blazor-mouse-wheel branch February 23, 2024 16:00
@pauldendulk
Copy link
Member Author

This PR fixed touchpad but the mouse wheel now feels too slow. Perhaps we should use something to detect the device:
https://stackoverflow.com/questions/10744645/detect-touchpad-vs-mouse-in-javascript

@RobertWatchful
Copy link

RobertWatchful commented Mar 15, 2024 via email

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