Skip to main content

PrimaryScrollController

Struct PrimaryScrollController 

Source
pub struct PrimaryScrollController {
    pub key: Option<KeyRef>,
    pub controller: Option<ScrollControllerRef>,
    pub scroll_direction: Option<Axis>,
    pub automatically_inherit_for_platforms: HashSet<TargetPlatform>,
    pub child: WidgetRef,
}
Expand description

Associates a ScrollController with a subtree.

When a ScrollView has primary set to true, the ScrollView uses of to inherit the PrimaryScrollController associated with its subtree.

A scroll view that doesn’t have a controller or the primary flag set will inherit the primary scroll controller, if should_inherit allows it. By default should_inherit is true for mobile platforms when the scroll view has a scroll direction of Axis::Vertical. This automatic inheritance can be configured with automatically_inherit_for_platforms and scroll_direction.

Inheriting this scroll controller can provide default behavior for scroll views in a subtree. For example, the Scaffold uses this mechanism to implement the scroll-to-top gesture on iOS.

Another default behavior handled by the PrimaryScrollController is default crate::ScrollActions. If a scroll action is not handled by an otherwise focused part of the application, the scroll action will be evaluated using the scroll view associated with a PrimaryScrollController, for example, when executing Shortcuts key events like page up and down.

See also:

  • crate::ScrollAction, an crate::Action that scrolls the Scrollable that encloses the current primary focus or is attached to the primary scroll controller.
  • Shortcuts, a widget that establishes a ShortcutManager to be used by its descendants when invoking an crate::Action via a keyboard key combination that maps to an crate::Intent.

Fields§

§key: Option<KeyRef>§controller: Option<ScrollControllerRef>

The ScrollController associated with the subtree.

See also:

  • ScrollView.controller, which discusses the purpose of specifying a scroll controller.
§scroll_direction: Option<Axis>

The Axis this controller is configured for scroll views to automatically inherit.

Used in conjunction with automatically_inherit_for_platforms. If the current TargetPlatform is not included there, this is ignored.

When None, no scroll view in any axis will automatically inherit this controller. This is dissimilar to PrimaryScrollController::none. When a primary scroll controller is inherited, ScrollView will insert PrimaryScrollController::none into the tree to prevent further descendant scroll views from inheriting the current primary scroll controller.

For the direction in which active scrolling may be occurring, see waft_rendering::ScrollDirection.

Defaults to Axis::Vertical.

§automatically_inherit_for_platforms: HashSet<TargetPlatform>

The TargetPlatforms this controller is configured for scroll views to automatically inherit.

Used in conjunction with scroll_direction. If the Axis provided to should_inherit is not scroll_direction, this is ignored.

When empty, no scroll view in any axis will automatically inherit this controller. Defaults to the mobile platforms.

§child: WidgetRef

The widget below this widget in the tree.

Implementations§

Source§

impl PrimaryScrollController

Source

pub fn new<K>( controller: ScrollControllerRef, child: impl IntoWidget<K>, ) -> PrimaryScrollController

Creates a widget that associates a ScrollController with a subtree.

Source

pub fn none<K>(child: impl IntoWidget<K>) -> PrimaryScrollController

Creates a subtree without an associated ScrollController.

Source

pub fn key(self, key: KeyRef) -> PrimaryScrollController

Dart PrimaryScrollController(key:).

Source

pub fn scroll_direction(self, scroll_direction: Axis) -> PrimaryScrollController

Dart PrimaryScrollController(scrollDirection:).

Source

pub fn automatically_inherit_for_platforms( self, automatically_inherit_for_platforms: HashSet<TargetPlatform>, ) -> PrimaryScrollController

Dart PrimaryScrollController(automaticallyInheritForPlatforms:).

Source

pub fn should_inherit( app: &mut App, context: BuildContext, scroll_direction: Axis, ) -> bool

Returns true if this PrimaryScrollController is configured to be automatically inherited for the current TargetPlatform and the given Axis.

This method is typically not called directly. ScrollView will call this method if it has not been provided a ScrollController and ScrollView.primary is unset.

Source

pub fn maybe_of( app: &mut App, context: BuildContext, ) -> Option<ScrollControllerRef>

Returns the ScrollController most closely associated with the given context.

Returns None if there is no ScrollController associated with the given context.

Calling this method will create a dependency on the closest PrimaryScrollController in the context, if there is one.

See also:

Source

pub fn of(app: &mut App, context: BuildContext) -> ScrollControllerRef

Returns the ScrollController most closely associated with the given context.

Calling this method will create a dependency on the closest PrimaryScrollController in the context.

§Panics

If no PrimaryScrollController ancestor is found.

See also:

Trait Implementations§

Source§

impl Debug for PrimaryScrollController

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl InheritedWidget for PrimaryScrollController

Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn debug_fill_properties( &self, app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s debugFillProperties: the properties a dump shows for this widget, in Dart’s order. Dart’s Widget base only sets the dense tree style, which the framework does.
Source§

fn child(&self) -> &WidgetRef

The widget below this widget in the tree.
Source§

fn update_should_notify(&self, old_widget: &PrimaryScrollController) -> bool

Whether the framework should notify widgets that inherit from this widget. Read more
Source§

fn debug_check_constructor(&self)

Source§

fn as_inherited_theme(&self) -> Option<&dyn InheritedTheme>

Dart’s this is InheritedTheme: an inherited widget that is an InheritedTheme answers with itself, which is what InheritedTheme::capture collects.

Auto Trait Implementations§

§

impl !RefUnwindSafe for PrimaryScrollController

§

impl !Send for PrimaryScrollController

§

impl !Sync for PrimaryScrollController

§

impl !UnwindSafe for PrimaryScrollController

§

impl Forget for PrimaryScrollController

§

impl Freeze for PrimaryScrollController
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, NonZero<u32>: Freeze, &'static ScrollControllerVTable: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, *const u8 is !null: Freeze, PhantomData<(TargetPlatform, ())>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze,

§

impl Move for PrimaryScrollController

§

impl Unpin for PrimaryScrollController
where Rc<dyn Key>: Unpin, NonZero<u32>: Unpin, &'static ScrollControllerVTable: Unpin, Rc<Keep>: Unpin, *const u8 is !null: Unpin, Rc<dyn Widget>: Unpin,

§

impl UnsafeUnpin for PrimaryScrollController
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, &'static ScrollControllerVTable: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<(TargetPlatform, ())>: UnsafeUnpin, *const RcInner<dyn Widget> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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<W> IntoWidget<InheritedKind> for W
where W: InheritedWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>