Accumulate line scrolling
Combined with https://github.com/pop-os/iced/pull/244, discrete value120 scrolling works better.
This commit is contained in:
parent
bd9e031912
commit
1e61881b4f
1 changed files with 22 additions and 13 deletions
23
src/main.rs
23
src/main.rs
|
|
@ -672,11 +672,8 @@ impl Application for App {
|
|||
// Accumulate delta with a timer
|
||||
// TODO: Should x scroll be handled too?
|
||||
// Best time/pixel count?
|
||||
let direction = match delta {
|
||||
ScrollDelta::Pixels { x: _, mut y } => {
|
||||
y = -y;
|
||||
let previous_scroll = if let Some((scroll, last_scroll_time)) = self.scroll
|
||||
{
|
||||
|
||||
let previous_scroll = if let Some((scroll, last_scroll_time)) = self.scroll {
|
||||
if last_scroll_time.elapsed() > Duration::from_millis(100) {
|
||||
0.
|
||||
} else {
|
||||
|
|
@ -686,6 +683,10 @@ impl Application for App {
|
|||
0.
|
||||
};
|
||||
|
||||
let direction = match delta {
|
||||
ScrollDelta::Pixels { x: _, mut y } => {
|
||||
y = -y;
|
||||
|
||||
let scroll = previous_scroll + y;
|
||||
if scroll <= -4. {
|
||||
self.scroll = None;
|
||||
|
|
@ -705,12 +706,20 @@ impl Application for App {
|
|||
}
|
||||
ScrollDelta::Lines { x: _, mut y } => {
|
||||
y = -y;
|
||||
|
||||
let scroll = previous_scroll + y;
|
||||
if scroll <= -1. {
|
||||
self.scroll = None;
|
||||
if y < 0. {
|
||||
ScrollDirection::Prev
|
||||
} else if y > 0. {
|
||||
} else if scroll >= 1. {
|
||||
self.scroll = None;
|
||||
ScrollDirection::Next
|
||||
} else {
|
||||
self.scroll = if y != 0. {
|
||||
Some((scroll, Instant::now()))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
return Task::none();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue