Skip to main content

NestedScrollConnection

Struct NestedScrollConnection 

Source
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

Source

pub fn new() -> Self

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for NestedScrollConnection

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.