pub struct NestedScrollConnection {
pub on_pre_scroll: Option<Rc<dyn Fn(Vec2) -> Vec2>>,
pub on_post_scroll: Option<Rc<dyn Fn(Vec2) -> Vec2>>,
}Expand description
A connection between a nested scrollable and its nearest ancestor scrollable. Allows coordinated scrolling: the parent can pre-consume deltas before the child processes them, and post-consume leftovers after the child is done.
This enables patterns like collapsing toolbars (parent pre-consumes upward scroll) and pull-to-refresh (parent post-consumes overscroll from child).
Fields§
§on_pre_scroll: Option<Rc<dyn Fn(Vec2) -> Vec2>>Called with the original delta before the child processes it. Return the delta remaining for the child after parent pre-consumption.
on_post_scroll: Option<Rc<dyn Fn(Vec2) -> Vec2>>Called with the leftover delta after the child has processed it. Return the final leftover (after parent post-consumption).
Implementations§
Source§impl NestedScrollConnection
impl NestedScrollConnection
pub fn new() -> Self
Sourcepub fn pre_scroll(self, f: impl Fn(Vec2) -> Vec2 + 'static) -> Self
pub fn pre_scroll(self, f: impl Fn(Vec2) -> Vec2 + 'static) -> Self
Pre-consume scroll before the child processes it.
f receives the original delta, returns what remains for the child.
Sourcepub fn post_scroll(self, f: impl Fn(Vec2) -> Vec2 + 'static) -> Self
pub fn post_scroll(self, f: impl Fn(Vec2) -> Vec2 + 'static) -> Self
Post-consume leftover scroll after the child has processed it.
f receives the leftover from the child, returns the final leftover.