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]]
|
||||
name = "async-executor"
|
||||
version = "1.7.1"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0de517d5a758a65a16d18d8f605e7a6beed477444cca270116af40fd3cd59d27"
|
||||
checksum = "4b0c4a4f319e45986f347ee47fef8bf5e81c9abc3f6f58dc2391439f30df65f0"
|
||||
dependencies = [
|
||||
"async-lock 3.1.0",
|
||||
"async-lock 2.8.0",
|
||||
"async-task",
|
||||
"concurrent-queue",
|
||||
"fastrand 2.0.1",
|
||||
"futures-lite 2.0.1",
|
||||
"futures-lite 1.13.0",
|
||||
"slab",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -533,12 +533,32 @@ where
|
|||
}
|
||||
Event::Mouse(MouseEvent::WheelScrolled { delta }) => match delta {
|
||||
ScrollDelta::Lines { x, y } => {
|
||||
editor.action(Action::Scroll {
|
||||
lines: (-y * 6.0) as i32,
|
||||
});
|
||||
//TODO: this adjustment is just a guess!
|
||||
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;
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
|
|
@ -566,6 +586,7 @@ pub struct State {
|
|||
modifiers: Modifiers,
|
||||
dragging: Option<Dragging>,
|
||||
scale_factor: Cell<f32>,
|
||||
scroll_pixels: f32,
|
||||
scrollbar_rect: Cell<Rectangle<f32>>,
|
||||
handle: Mutex<image::Handle>,
|
||||
}
|
||||
|
|
@ -577,6 +598,7 @@ impl State {
|
|||
modifiers: Modifiers::empty(),
|
||||
dragging: None,
|
||||
scale_factor: Cell::new(1.0),
|
||||
scroll_pixels: 0.0,
|
||||
scrollbar_rect: Cell::new(Rectangle::default()),
|
||||
//TODO: make option!
|
||||
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