Skip to main content

ScrollBehavior

Trait ScrollBehavior 

Source
pub trait ScrollBehavior: Debug + 'static {
    // Required method
    fn as_any(&self) -> &dyn Any;

    // Provided methods
    fn get_platform(
        &self,
        app: &mut App,
        context: BuildContext,
    ) -> TargetPlatform { ... }
    fn drag_devices(&self) -> HashSet<PointerDeviceKind> { ... }
    fn get_multitouch_drag_strategy(
        &self,
        app: &mut App,
        context: BuildContext,
    ) -> MultitouchDragStrategy { ... }
    fn pointer_axis_modifiers(&self) -> HashSet<LogicalKeyboardKey> { ... }
    fn build_scrollbar(
        &self,
        app: &mut App,
        context: BuildContext,
        child: WidgetRef,
        details: &ScrollableDetails,
    ) -> WidgetRef { ... }
    fn build_overscroll_indicator(
        &self,
        app: &mut App,
        context: BuildContext,
        child: WidgetRef,
        details: &ScrollableDetails,
    ) -> WidgetRef { ... }
    fn velocity_tracker_builder(
        &self,
        app: &mut App,
        context: BuildContext,
    ) -> GestureVelocityTrackerBuilder { ... }
    fn get_scroll_physics(
        &self,
        app: &mut App,
        context: BuildContext,
    ) -> ScrollPhysicsRef { ... }
    fn should_notify(&self, old_delegate: &dyn ScrollBehavior) -> bool { ... }
    fn get_keyboard_dismiss_behavior(
        &self,
        app: &mut App,
        context: BuildContext,
    ) -> ScrollViewKeyboardDismissBehavior { ... }
}
Expand description

Describes how Scrollable widgets should behave.

Used by ScrollConfiguration to configure the Scrollable widgets in a subtree.

This trait can be implemented to further customize a ScrollBehavior for a subtree. For example, overriding get_scroll_physics sets the default ScrollPhysics for Scrollables that inherit this ScrollConfiguration.

When looking to easily toggle the default decorations, use ScrollBehaviorRef::copy_with instead of writing a new ScrollBehavior. The scrollbars and overscroll flags can turn these decorations off.

See also:

  • ScrollConfiguration, the inherited widget that controls how Scrollable widgets behave in a subtree.

Required Methods§

Source

fn as_any(&self) -> &dyn Any

The value behind the erased behavior, for Dart’s behavior.runtimeType and the covariant oldDelegate a should_notify override casts.

Provided Methods§

Source

fn get_platform(&self, app: &mut App, context: BuildContext) -> TargetPlatform

The platform whose scroll physics should be implemented.

Defaults to the current platform.

Source

fn drag_devices(&self) -> HashSet<PointerDeviceKind>

The device kinds that the scrollable will accept drag gestures from.

By default only PointerDeviceKind::Touch, PointerDeviceKind::Stylus, PointerDeviceKind::InvertedStylus, and PointerDeviceKind::Trackpad are configured to create drag gestures. Enabling this for PointerDeviceKind::Mouse will make it difficult or impossible to select text in scrollable containers and is not recommended.

Source

fn get_multitouch_drag_strategy( &self, app: &mut App, context: BuildContext, ) -> MultitouchDragStrategy

The multi-finger drag strategy on multi-touch devices.

By default, MultitouchDragStrategy::LatestPointer is configured to create drag gestures for non-Apple platforms, and MultitouchDragStrategy::AverageBoundaryPointers for Apple platforms.

Source

fn pointer_axis_modifiers(&self) -> HashSet<LogicalKeyboardKey>

A set of LogicalKeyboardKeys that, when any or all are pressed in combination with a PointerDeviceKind::Mouse pointer scroll event, will flip the axes of the scroll input.

This will for example, result in the input of a vertical mouse wheel, to move the ScrollPosition of a ScrollView with an waft_painting::Axis::Horizontal scroll direction.

If other keys exclusive of this set are pressed during a scroll event, in conjunction with keys from this set, the scroll input will still be flipped.

Defaults to LogicalKeyboardKey::SHIFT_LEFT and LogicalKeyboardKey::SHIFT_RIGHT.

Source

fn build_scrollbar( &self, app: &mut App, context: BuildContext, child: WidgetRef, details: &ScrollableDetails, ) -> WidgetRef

Applies a RawScrollbar to the child widget on desktop platforms.

Source

fn build_overscroll_indicator( &self, app: &mut App, context: BuildContext, child: WidgetRef, details: &ScrollableDetails, ) -> WidgetRef

Source

fn velocity_tracker_builder( &self, app: &mut App, context: BuildContext, ) -> GestureVelocityTrackerBuilder

Specifies the type of velocity tracker to use in the descendant Scrollables’ drag gesture recognizers, for estimating the velocity of a drag gesture.

This can be used to, for example, apply different fling velocity estimation methods on different platforms, in order to match the platform’s native behavior.

The default implementation provides a new IOSScrollViewFlingVelocityTracker on iOS and macOS for each new pointer, and a new VelocityTracker on other platforms for each new pointer.

Source

fn get_scroll_physics( &self, app: &mut App, context: BuildContext, ) -> ScrollPhysicsRef

The scroll physics to use for the platform given by get_platform.

Defaults to RangeMaintainingScrollPhysics mixed with BouncingScrollPhysics on iOS and ClampingScrollPhysics on Android.

Source

fn should_notify(&self, old_delegate: &dyn ScrollBehavior) -> bool

Called whenever a ScrollConfiguration is rebuilt with a new ScrollBehavior of the same runtime type.

If the new instance represents different information than the old instance, then the method should return true, otherwise it should return false.

If this method returns true, all the widgets that inherit from the ScrollConfiguration will rebuild using the new ScrollBehavior. If this method returns false, the rebuilds might be optimized away.

Source

fn get_keyboard_dismiss_behavior( &self, app: &mut App, context: BuildContext, ) -> ScrollViewKeyboardDismissBehavior

The default keyboard dismissal behavior for ScrollView widgets.

Defaults to ScrollViewKeyboardDismissBehavior::Manual.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§