- 
                Notifications
    
You must be signed in to change notification settings  - Fork 767
 
feat: Add smooth scroll to Flickable #9440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
f92a728    to
    74fc84d      
    Compare
  
    | 
           After around ~50 minutes waiting (and wasting hours of machine-time) for CI, it may be improved with some cache like Swatinem/rust-cache. In another project, I have used a similar strategy but with nix-cache, and it helps a lot in CI times.  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
I haven't tried it yet, but it looks good at first glance.
I'm just wondering if the "smooth_scroll" property is really necessary or if we just want to always have smooth scroll.
If anything, it we could have properties in Flickable to configure the smooth scrolling, but I think it would be simpler to always have it.
          
 We do have that: 
 Let us know if you find something that is misconfigured. Regarding the listview tests, they are probably failing because they expect things to happen, fast. You can try to add   | 
    
          
 I think if someone already depends on no-smooth scrolling, there should be a way to disable it. I don't know a case for it, so if you think it's better to have a simpler API, then I remove it  | 
    
| 
           @ogoffart I'm working on tests and I have a big problem, maybe you know what to do. 
 // 19..21
flicked => {
    root.flicked += viewport_x/1phx * 100000 + viewport_y/1phx;
}Here the value flicked is updated every time the callback gets triggered, but my current implementation only calls it at the start of the scroll, that means that  // 258..263
// test scrolling behaviour
instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(175.0, 175.0), delta_x: -30.0, delta_y: -50.0 });
dbg!(instance.get_flicked());
assert_eq!(instance.get_flicked(), -3000050); //flicked got called after scrolling
instance.set_flicked(0);But the test expects to be the final state. I see many solutions: 
 
 // 454..473
let should_hook_x = old_pos.x_length() != new_pos.x_length();
let should_hook_y = old_pos.y_length() != new_pos.y_length();
let should_hook = should_hook_x || should_hook_y;
if should_hook {
    let hook = move || {
        (Flickable::FIELD_OFFSETS.flicked).apply_pin(flick).call(&());
    };
    if should_hook_x {
        viewport_x.set_animated_value_hooked(new_pos.x_length(), SMOOTH_SCROLL_ANIM, hook);
        viewport_y.set_animated_value(new_pos.y_length(), SMOOTH_SCROLL_ANIM);
    } else {
        viewport_x.set_animated_value(new_pos.x_length(), SMOOTH_SCROLL_ANIM);
        viewport_y.set_animated_value_hooked(new_pos.y_length(), SMOOTH_SCROLL_ANIM, hook);
    }
} else {
    viewport_x.set_animated_value(new_pos.x_length(), SMOOTH_SCROLL_ANIM);
    viewport_y.set_animated_value(new_pos.y_length(), SMOOTH_SCROLL_ANIM);
}I was trying to implement my fourth solution, with a new struct that calls any callback along the animation get evaluated, but  Do you know any way to implement this? Should I just implement another solution? Let me know your thoughts.  | 
    
| 
           This is a good question when should we emit the  
 Then it should be off by default.  | 
    
| 
           @ogoffart I found out how to solve the issue at my 4th solution, I just created a change tracker for viewport and attach its event to flicked callback, so now it is called every time viewport is updated, but now I'm facing another issue: The transition between the start and end value of  Is there a way to emit mouse events for a change tracker or any closure with ItemRc context?  | 
    
a8048b8    to
    130f7e5      
    Compare
  
    
Closes #4115
Also written as fluent scrolling, smooth scroll is one of the details that Slint needs to have a better user experience.
In this PR, I add the opt-out
smooth-scrollproperty toFlickableand platform-specificScrollViewthat enables the smooth scrolling.There's just one thing to resolve, in
ensure_updated_listviewI have to remove one line because it discards the running animated value, but I want some feedback to handle it better.If everything is right, then I will change the doc.