Skip to main content

ViewportOffset

Trait ViewportOffset 

Source
pub trait ViewportOffset: ChangeNotifier + Sized {
    // Required methods
    fn pixels(self: Handle<Self>, app: &App) -> f64;
    fn has_pixels(self: Handle<Self>, app: &App) -> bool;
    fn apply_viewport_dimension(
        self: Handle<Self>,
        app: &mut App,
        viewport_dimension: f64,
    ) -> bool;
    fn apply_content_dimensions(
        self: Handle<Self>,
        app: &mut App,
        min_scroll_extent: f64,
        max_scroll_extent: f64,
    ) -> bool;
    fn correct_by(self: Handle<Self>, app: &mut App, correction: f64);
    fn jump_to(self: Handle<Self>, app: &mut App, pixels: f64);
    fn animate_to(
        self: Handle<Self>,
        app: &mut App,
        to: f64,
        duration: Duration,
        curve: Rc<dyn Curve>,
    ) -> CompleterFuture<()> ⓘ;
    fn user_scroll_direction(self: Handle<Self>, app: &App) -> ScrollDirection;
    fn allow_implicit_scrolling(self: Handle<Self>, app: &App) -> bool;

    // Provided methods
    fn move_to(
        self: Handle<Self>,
        app: &mut App,
        to: f64,
        duration: Option<Duration>,
        curve: Option<Rc<dyn Curve>>,
        clamp: Option<bool>,
    ) -> CompleterFuture<()> ⓘ { ... }
    fn debug_fill_description(
        self: Handle<Self>,
        app: &App,
        description: &mut Vec<String>,
    ) { ... }
    fn as_viewport_offset(self: Handle<Self>) -> AnyViewportOffset { ... }
}
Expand description

Which part of the content inside the viewport should be visible.

The pixels value determines the scroll offset that the viewport uses to select which part of its content to display. As the user scrolls the viewport, this value changes, which changes the content that is displayed.

This object is a Listenable that notifies its listeners when pixels changes.

See also:

Required Methods§

Source

fn pixels(self: Handle<Self>, app: &App) -> f64

The number of pixels to offset the children in the opposite of the axis direction.

For example, if the axis direction is down, then the pixel value represents the number of logical pixels to move the children up the screen. Similarly, if the axis direction is left, then the pixels value represents the number of logical pixels to move the children to right.

This object notifies its listeners when this value changes (except when the value changes due to correct_by).

Source

fn has_pixels(self: Handle<Self>, app: &App) -> bool

Whether the pixels property is available.

Source

fn apply_viewport_dimension( self: Handle<Self>, app: &mut App, viewport_dimension: f64, ) -> bool

Called when the viewport’s extents are established.

The argument is the dimension of the crate::RenderViewport in the main axis (e.g. the height, for a vertical viewport).

This may be called redundantly, with the same value, each frame. This is called during layout for the viewport. If the viewport is configured to shrink-wrap its contents, it may be called several times, since the layout is repeated each time the scroll offset is corrected.

If this is called, it is called before apply_content_dimensions, which will be called soon afterwards in the same layout phase.

If applying the viewport dimensions changes the scroll offset, return false. Otherwise, return true. If you return false, the viewport will be laid out again with the new scroll offset. This is expensive.

Source

fn apply_content_dimensions( self: Handle<Self>, app: &mut App, min_scroll_extent: f64, max_scroll_extent: f64, ) -> bool

Called when the viewport’s content extents are established.

The arguments are the minimum and maximum scroll extents respectively. The minimum will be equal to or less than the maximum. In the case of slivers, the minimum will be equal to or less than zero, the maximum will be equal to or greater than zero.

The maximum scroll extent has the viewport dimension subtracted from it. For instance, if there is 100.0 pixels of scrollable content, and the viewport is 80.0 pixels high, then the minimum scroll extent will typically be 0.0 and the maximum scroll extent will typically be 20.0, because there’s only 20.0 pixels of actual scroll slack.

If applying the content dimensions changes the scroll offset, return false. Otherwise, return true. If you return false, the viewport will be laid out again with the new scroll offset. This is expensive.

This is called at least once each time the viewport is laid out, even if the values have not changed. It may be called many times if the scroll offset is corrected (if this returns false). This is always called after apply_viewport_dimension, if that method is called.

Source

fn correct_by(self: Handle<Self>, app: &mut App, correction: f64)

Apply a layout-time correction to the scroll offset.

This method should change the pixels value by correction, but without notifying listeners. It is called during layout by the viewport, before apply_content_dimensions. After this method is called, the layout will be recomputed and that may result in this method being called again, though this should be very rare.

See also:

  • jump_to, for also changing the scroll position when not in layout. It applies the change immediately and notifies its listeners.
Source

fn jump_to(self: Handle<Self>, app: &mut App, pixels: f64)

Jumps pixels from its current value to the given value, without animation, and without checking if the new value is in range.

See also:

  • correct_by, for changing the current offset in the middle of layout and that defers the notification of its listeners until after layout.
Source

fn animate_to( self: Handle<Self>, app: &mut App, to: f64, duration: Duration, curve: Rc<dyn Curve>, ) -> CompleterFuture<()> ⓘ

Animates pixels from its current value to the given value.

The returned future will complete when the animation ends, whether it completed successfully or whether it was interrupted prematurely.

The duration must not be zero. To jump to a particular value without an animation, use jump_to.

Source

fn user_scroll_direction(self: Handle<Self>, app: &App) -> ScrollDirection

The direction in which the user is trying to change pixels, relative to the viewport’s axis_direction.

If the user is not scrolling, this will return ScrollDirection::Idle even if there is (for example) a scroll activity currently animating the position.

This is exposed in crate::SliverConstraints::user_scroll_direction, which is used by some slivers to determine how to react to a change in scroll offset. For example, crate::RenderSliverFloatingPersistentHeader will only expand a floating app bar when the user scroll direction is in the positive scroll offset direction.

Source

fn allow_implicit_scrolling(self: Handle<Self>, app: &App) -> bool

Whether a viewport is allowed to change pixels implicitly to respond to a call to crate::RenderObject::show_on_screen.

show_on_screen is, for example, used to bring a text field fully on screen after it has received focus. This property controls whether the viewport associated with this offset is allowed to change the offset’s pixels value to fulfill such a request.

Provided Methods§

Source

fn move_to( self: Handle<Self>, app: &mut App, to: f64, duration: Option<Duration>, curve: Option<Rc<dyn Curve>>, clamp: Option<bool>, ) -> CompleterFuture<()> ⓘ

Calls jump_to if duration is None or zero, otherwise animate_to is called.

If animate_to is called then curve defaults to Curves::ease. The clamp parameter is ignored by this stub implementation but implementors like ScrollPosition handle it by adjusting to to prevent over or underscroll.

Source

fn debug_fill_description( self: Handle<Self>, app: &App, description: &mut Vec<String>, )

Add additional information to the given description for use by Dart’s toString.

An implementor that adds its own lines calls this one where Dart writes super.debugFillDescription(description).

Source

fn as_viewport_offset(self: Handle<Self>) -> AnyViewportOffset

The type-erased ViewportOffset handle. Free: the vtable is a const, and the id is copied.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§