Skip to content

Commit

Permalink
egui_web: Scroll faster when scrolling with mouse wheel
Browse files Browse the repository at this point in the history
Closes #159
  • Loading branch information
emilk committed Apr 24, 2021
1 parent 0f112db commit b69bc2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions egui_web/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to the `egui_web` integration will be noted in this file.

## Unreleased

### Fixed ⭐
* Scroll faster when scrolling with mouse wheel.


## 0.11.0 - 2021-04-05

Expand Down
15 changes: 13 additions & 2 deletions egui_web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,19 @@ fn install_canvas_events(runner_ref: &AppRunnerRef) -> Result<(), JsValue> {
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;

let scroll_multiplier = match event.delta_mode() {
web_sys::WheelEvent::DOM_DELTA_PAGE => {
canvas_size_in_points(runner_ref.0.lock().canvas_id()).y
}
web_sys::WheelEvent::DOM_DELTA_LINE => {
24.0 // TODO: tweak this
}
_ => 1.0,
};

runner_lock.input.raw.scroll_delta.x -= scroll_multiplier * event.delta_x() as f32;
runner_lock.input.raw.scroll_delta.y -= scroll_multiplier * event.delta_y() as f32;
runner_lock.needs_repaint.set_true();
event.stop_propagation();
event.prevent_default();
Expand Down

0 comments on commit b69bc2c

Please sign in to comment.