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
35
src/main.rs
35
src/main.rs
|
|
@ -672,19 +672,20 @@ impl Application for App {
|
||||||
// Accumulate delta with a timer
|
// Accumulate delta with a timer
|
||||||
// TODO: Should x scroll be handled too?
|
// TODO: Should x scroll be handled too?
|
||||||
// Best time/pixel count?
|
// Best time/pixel count?
|
||||||
|
|
||||||
|
let previous_scroll = if let Some((scroll, last_scroll_time)) = self.scroll {
|
||||||
|
if last_scroll_time.elapsed() > Duration::from_millis(100) {
|
||||||
|
0.
|
||||||
|
} else {
|
||||||
|
scroll
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
0.
|
||||||
|
};
|
||||||
|
|
||||||
let direction = match delta {
|
let direction = match delta {
|
||||||
ScrollDelta::Pixels { x: _, mut y } => {
|
ScrollDelta::Pixels { x: _, mut y } => {
|
||||||
y = -y;
|
y = -y;
|
||||||
let previous_scroll = if let Some((scroll, last_scroll_time)) = self.scroll
|
|
||||||
{
|
|
||||||
if last_scroll_time.elapsed() > Duration::from_millis(100) {
|
|
||||||
0.
|
|
||||||
} else {
|
|
||||||
scroll
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
0.
|
|
||||||
};
|
|
||||||
|
|
||||||
let scroll = previous_scroll + y;
|
let scroll = previous_scroll + y;
|
||||||
if scroll <= -4. {
|
if scroll <= -4. {
|
||||||
|
|
@ -705,12 +706,20 @@ impl Application for App {
|
||||||
}
|
}
|
||||||
ScrollDelta::Lines { x: _, mut y } => {
|
ScrollDelta::Lines { x: _, mut y } => {
|
||||||
y = -y;
|
y = -y;
|
||||||
self.scroll = None;
|
|
||||||
if y < 0. {
|
let scroll = previous_scroll + y;
|
||||||
|
if scroll <= -1. {
|
||||||
|
self.scroll = None;
|
||||||
ScrollDirection::Prev
|
ScrollDirection::Prev
|
||||||
} else if y > 0. {
|
} else if scroll >= 1. {
|
||||||
|
self.scroll = None;
|
||||||
ScrollDirection::Next
|
ScrollDirection::Next
|
||||||
} else {
|
} else {
|
||||||
|
self.scroll = if y != 0. {
|
||||||
|
Some((scroll, Instant::now()))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
return Task::none();
|
return Task::none();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue