Smooth out auto-scrolling speed scaling in scrollable
This commit is contained in:
parent
519e7ae414
commit
eadd7b8e81
2 changed files with 32 additions and 20 deletions
|
|
@ -275,7 +275,9 @@ impl Gallery {
|
|||
.height(grid::aspect_ratio(Preview::WIDTH, Preview::HEIGHT))
|
||||
.spacing(10);
|
||||
|
||||
let content = container(scrollable(gallery).spacing(10)).padding(10);
|
||||
let content =
|
||||
container(scrollable(gallery).spacing(10).auto_scroll(true))
|
||||
.padding(10);
|
||||
let viewer = self.viewer.view(self.now);
|
||||
|
||||
stack![content, viewer].into()
|
||||
|
|
|
|||
|
|
@ -579,7 +579,7 @@ where
|
|||
_viewport: &Rectangle,
|
||||
) {
|
||||
const AUTOSCROLL_DEADZONE: f32 = 20.0;
|
||||
const AUTOSCROLL_SPEED: f32 = 10.0;
|
||||
const AUTOSCROLL_SMOOTHNESS: f32 = 1.5;
|
||||
|
||||
let state = tree.state.downcast_mut::<State>();
|
||||
let bounds = layout.bounds();
|
||||
|
|
@ -764,6 +764,21 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
if matches!(state.interaction, Interaction::AutoScrolling { .. })
|
||||
&& matches!(
|
||||
event,
|
||||
Event::Mouse(
|
||||
mouse::Event::ButtonPressed(_)
|
||||
| mouse::Event::WheelScrolled { .. }
|
||||
) | Event::Touch(_)
|
||||
| Event::Keyboard(_)
|
||||
)
|
||||
{
|
||||
state.interaction = Interaction::None;
|
||||
shell.capture_event();
|
||||
return;
|
||||
}
|
||||
|
||||
if state.last_scrolled.is_none()
|
||||
|| !matches!(
|
||||
event,
|
||||
|
|
@ -820,20 +835,6 @@ where
|
|||
return;
|
||||
}
|
||||
|
||||
if matches!(state.interaction, Interaction::AutoScrolling { .. })
|
||||
&& matches!(
|
||||
event,
|
||||
Event::Mouse(
|
||||
mouse::Event::ButtonPressed(_)
|
||||
| mouse::Event::WheelScrolled { .. }
|
||||
) | Event::Touch(_)
|
||||
| Event::Keyboard(_)
|
||||
)
|
||||
{
|
||||
state.interaction = Interaction::None;
|
||||
return;
|
||||
}
|
||||
|
||||
if shell.is_event_captured() {
|
||||
return;
|
||||
}
|
||||
|
|
@ -1025,13 +1026,22 @@ where
|
|||
Duration::ZERO
|
||||
};
|
||||
|
||||
let scroll_factor =
|
||||
time_delta.as_secs_f32() * AUTOSCROLL_SPEED;
|
||||
let scroll_factor = time_delta.as_secs_f32();
|
||||
|
||||
state.scroll(
|
||||
self.direction.align(Vector::new(
|
||||
delta.x * scroll_factor,
|
||||
delta.y * scroll_factor,
|
||||
delta.x.signum()
|
||||
* delta
|
||||
.x
|
||||
.abs()
|
||||
.powf(AUTOSCROLL_SMOOTHNESS)
|
||||
* scroll_factor,
|
||||
delta.y.signum()
|
||||
* delta
|
||||
.y
|
||||
.abs()
|
||||
.powf(AUTOSCROLL_SMOOTHNESS)
|
||||
* scroll_factor,
|
||||
)),
|
||||
bounds,
|
||||
content_bounds,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue