Implement touchpad scroll
This commit is contained in:
parent
7170e64f4a
commit
18f2ca563f
2 changed files with 30 additions and 8 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
|
@ -258,15 +258,15 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-executor"
|
name = "async-executor"
|
||||||
version = "1.7.1"
|
version = "1.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0de517d5a758a65a16d18d8f605e7a6beed477444cca270116af40fd3cd59d27"
|
checksum = "4b0c4a4f319e45986f347ee47fef8bf5e81c9abc3f6f58dc2391439f30df65f0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-lock 3.1.0",
|
"async-lock 2.8.0",
|
||||||
"async-task",
|
"async-task",
|
||||||
"concurrent-queue",
|
"concurrent-queue",
|
||||||
"fastrand 2.0.1",
|
"fastrand 2.0.1",
|
||||||
"futures-lite 2.0.1",
|
"futures-lite 1.13.0",
|
||||||
"slab",
|
"slab",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -533,12 +533,32 @@ where
|
||||||
}
|
}
|
||||||
Event::Mouse(MouseEvent::WheelScrolled { delta }) => match delta {
|
Event::Mouse(MouseEvent::WheelScrolled { delta }) => match delta {
|
||||||
ScrollDelta::Lines { x, y } => {
|
ScrollDelta::Lines { x, y } => {
|
||||||
editor.action(Action::Scroll {
|
//TODO: this adjustment is just a guess!
|
||||||
lines: (-y * 6.0) as i32,
|
state.scroll_pixels = 0.0;
|
||||||
});
|
let lines = (-y * 6.0) as i32;
|
||||||
|
if lines != 0 {
|
||||||
|
editor.action(Action::Scroll { lines });
|
||||||
|
}
|
||||||
|
status = Status::Captured;
|
||||||
|
}
|
||||||
|
ScrollDelta::Pixels { x, y } => {
|
||||||
|
//TODO: this adjustment is just a guess!
|
||||||
|
state.scroll_pixels -= y * 6.0;
|
||||||
|
let mut lines = 0;
|
||||||
|
let metrics = editor.buffer().metrics();
|
||||||
|
while state.scroll_pixels <= -metrics.line_height {
|
||||||
|
lines -= 1;
|
||||||
|
state.scroll_pixels += metrics.line_height;
|
||||||
|
}
|
||||||
|
while state.scroll_pixels >= metrics.line_height {
|
||||||
|
lines += 1;
|
||||||
|
state.scroll_pixels -= metrics.line_height;
|
||||||
|
}
|
||||||
|
if lines != 0 {
|
||||||
|
editor.action(Action::Scroll { lines });
|
||||||
|
}
|
||||||
status = Status::Captured;
|
status = Status::Captured;
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
@ -566,6 +586,7 @@ pub struct State {
|
||||||
modifiers: Modifiers,
|
modifiers: Modifiers,
|
||||||
dragging: Option<Dragging>,
|
dragging: Option<Dragging>,
|
||||||
scale_factor: Cell<f32>,
|
scale_factor: Cell<f32>,
|
||||||
|
scroll_pixels: f32,
|
||||||
scrollbar_rect: Cell<Rectangle<f32>>,
|
scrollbar_rect: Cell<Rectangle<f32>>,
|
||||||
handle: Mutex<image::Handle>,
|
handle: Mutex<image::Handle>,
|
||||||
}
|
}
|
||||||
|
|
@ -577,6 +598,7 @@ impl State {
|
||||||
modifiers: Modifiers::empty(),
|
modifiers: Modifiers::empty(),
|
||||||
dragging: None,
|
dragging: None,
|
||||||
scale_factor: Cell::new(1.0),
|
scale_factor: Cell::new(1.0),
|
||||||
|
scroll_pixels: 0.0,
|
||||||
scrollbar_rect: Cell::new(Rectangle::default()),
|
scrollbar_rect: Cell::new(Rectangle::default()),
|
||||||
//TODO: make option!
|
//TODO: make option!
|
||||||
handle: Mutex::new(image::Handle::from_pixels(1, 1, vec![0, 0, 0, 0])),
|
handle: Mutex::new(image::Handle::from_pixels(1, 1, vec![0, 0, 0, 0])),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue