emoon / rust_minifb

Cross platfrom window and framebuffer crate for Rust
MIT License
1k stars 95 forks source link

get_scroll_wheel should give you the current scroll position instead of last delta. #264

Closed NikoUY closed 2 years ago

NikoUY commented 2 years ago

I'm not sure how it works on other platforms but on MacOS you only get the delta, it's pretty useless without a way to get notified when someone uses the scroll wheel or a way to check for changes.

You can add the deltas to the current position here, that way you can check if the value changed.

emoon commented 2 years ago

The idea is that the application can determine what the current position is as this can be application specific. You can implement it something like this

   ...
   let mut scroll_pos = (0, 0);
   while window.open(...) {
      window.get_scroll_wheel().map(|scroll| {
        // user has now moved the scroll wheel/trackpad
        scroll_pos += scroll;
      });
   }
NikoUY commented 2 years ago

How would I know when the user stopped scrolling?, the value never resets to 0 and it's a constant depending on the direction and the speed of the scroll wheel (1 is slow and 4 is fast), I could check if the value changed but since it never resets to 0 I would only be able to know if the user changed direction but I won't be able to tell if the user scrolled more than once on the same direction or if the user stopped scrolling.

emoon commented 2 years ago

I see. I have only tested this with trackpad where it works correct, I will have to check how it differs with mouse wheel.

emoon commented 2 years ago

So the problem seems to be that the callback code for mouse wheel gets called all the time since the first time the user has done scrolling even when no scrolling is active. Not really sure why that is the case

emoon commented 2 years ago

Seems to be a macOS only problem. Works correct on Linux and Windows

emoon commented 2 years ago

I think I have found the problem. Looking into a fix

emoon commented 2 years ago

I have pushed a fix now. Give the git version a try and see if it solves your issue. If it does I will release a new version

NikoUY commented 2 years ago

Yep, that works! 😄, thanks for fixing it!

emoon commented 2 years ago

Great! Thanks for the report. I will release a new version in a bit :)

emoon commented 2 years ago

Version 0.20 has now been released with this fix