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

Scroll step in Firefox is too small #159

Closed
akhilman opened this issue Feb 5, 2021 · 4 comments
Closed

Scroll step in Firefox is too small #159

akhilman opened this issue Feb 5, 2021 · 4 comments
Labels
bug Something is broken good first issue Good for newcomers help wanted Extra attention is needed web Related to running Egui on the web

Comments

@akhilman
Copy link

akhilman commented Feb 5, 2021

Describe the bug
Scrolling step and speed are too small. The area scroll by only 3 pixels per click of the scroll wheel.
WebKit and Blink based browsers scroll 60 pixels in one click.

To Reproduce
Steps to reproduce the behavior:

  1. Open https://emilk.github.io/egui/index.html#demo in Firefox.
  2. Scroll any scroll area with mouse wheel.
  3. The area scroll by 3 pixel per click.

Expected behavior
The area should scroll about 60 pixels in single click.

Screenshots
https://user-images.githubusercontent.com/180812/106979999-03b4d180-6792-11eb-8b99-04938d175cfe.mp4

Desktop (please complete the following information):

  • OS: Debian Sid
  • Browser: Firefox
  • Version: 84.0.2 (64-bit)
@akhilman akhilman added the bug Something is broken label Feb 5, 2021
@emilk emilk added the web Related to running Egui on the web label Feb 5, 2021
@follower
Copy link
Contributor

follower commented Feb 10, 2021

TL;DR: Probably need to account for the "scale"/units indicated by delta_mode when using delta_* scroll wheel values.

Context

I also observed this behaviour in Firefox on ElementaryOS on a laptop with a trackpad.

Relevant code

From a brief investigation it appears this may be the relevant code:

egui/egui_web/src/lib.rs

Lines 809 to 820 in 0f33bc7

let event_name = "wheel";
let runner_ref = runner_ref.clone();
let closure = Closure::wrap(Box::new(move |event: web_sys::WheelEvent| {
let mut runner_lock = runner_ref.0.lock();
runner_lock.input.raw.scroll_delta.x -= event.delta_x() as f32;
runner_lock.input.raw.scroll_delta.y -= event.delta_y() as f32;
runner_lock.needs_repaint.set_true();
event.stop_propagation();
event.prevent_default();
}) as Box<dyn FnMut(_)>);
canvas.add_event_listener_with_callback(event_name, closure.as_ref().unchecked_ref())?;
closure.forget();

Specifically, the code that appears to read the delta change per axis from a WheelEvent:

egui/egui_web/src/lib.rs

Lines 813 to 814 in 0f33bc7

runner_lock.input.raw.scroll_delta.x -= event.delta_x() as f32;
runner_lock.input.raw.scroll_delta.y -= event.delta_y() as f32;

Underlying cause?

The MDN WheelEvent docs mention the delta* (a.k.a delta_*) values are:

a double representing the [axis] scroll amount.

But the docs also mention a deltaMode (a.k.a delta_mode) which is:

an unsigned long representing the unit of the delta* values' scroll amount

with valid values for:

  • DOM_DELTA_PIXEL (0x00)
  • DOM_DELTA_LINE (0x01)
  • DOM_DELTA_PAGE (0x02)

Thus, the underlying cause of the issue seems like it might be not taking the delta_mode value into account when performing calculations with the delta_* values.

I suspect the exact behaviour observed is probably dependent on the specific combination of:

  1. Browser.
  2. Input device. (e.g. mouse vs trackpad)
  3. OS configuration.

(Although the browsers may themselves handle some of the variance.)

Path to a solution

It seems like a solution to this issue would require:

  1. A design decision re: how egui handles scroll delta event data from backends. e.g. "backend must convert delta into egui units". (Maybe this is already specified somewhere already? I've not yet looked.)
  2. Patch to egui_web/src/lib.rs to account for the impact of delta_mode on the delta_* value.

Additional details

@follower
Copy link
Contributor

Approaches used by other Rust projects to handle scroll wheel delta issue, in no particular order (click to view):

@emilk emilk added good first issue Good for newcomers help wanted Extra attention is needed labels Feb 11, 2021
@emilk
Copy link
Owner

emilk commented Feb 11, 2021

@follower thanks for that detailed analysis! egui does indeed expect the scroll to be in logical pixels (what egui calls "points"). As you see from the glium version I just hacked in 24.0 there as "better than nothing" solution. Any improvements are very welcome!

On my mac egui_web works well with my trackpad, but poorly with my mouse scroll wheel (which I rarely use, which is why this went unnoticed).

@trusktr
Copy link

trusktr commented Mar 22, 2024

Too many inconsistencies across browsers. Related web spec issue:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken good first issue Good for newcomers help wanted Extra attention is needed web Related to running Egui on the web
Projects
None yet
Development

No branches or pull requests

4 participants