Skip to main content

Viewport

Struct Viewport 

Source
pub struct Viewport {
    pub key: Option<KeyRef>,
    pub axis_direction: AxisDirection,
    pub cross_axis_direction: Option<AxisDirection>,
    pub anchor: f64,
    pub offset: ViewportOffsetRef,
    pub center: Option<KeyRef>,
    pub cache_extent: Option<f64>,
    pub cache_extent_style: CacheExtentStyle,
    pub scroll_cache_extent: Option<ScrollCacheExtent>,
    pub paint_order: SliverPaintOrder,
    pub clip_behavior: Clip,
    pub slivers: Vec<WidgetRef>,
}
Expand description

A widget through which a portion of larger content can be viewed, typically in combination with a Scrollable.

Viewport is the visual workhorse of the scrolling machinery. It displays a subset of its children according to its own dimensions and the given offset. As the offset varies, different children are visible through the viewport.

Viewport hosts a bidirectional list of slivers, anchored on a center sliver, which is placed at the zero scroll offset. The center widget is displayed in the viewport according to the anchor property.

Slivers that are earlier in the child list than center are displayed in reverse order in the reverse axis_direction starting from the center. For example, if the axis direction is AxisDirection::Down, the first sliver before the center is placed above the center. The slivers that are later in the child list than the center are placed in order in the axis direction.

Viewport cannot contain box children directly. Instead, use a SliverList, SliverFixedExtentList, or a SliverToBoxAdapter, for example.

See also:

  • SliverToBoxAdapter, which allows a box widget to be placed inside a sliver context (the opposite of this widget).
  • ShrinkWrappingViewport, a variant of Viewport that shrink-wraps its contents along the main axis.
  • ViewportElementMixin, which should be mixed in to the Element type used by viewport-like widgets to correctly handle scroll notifications.

Fields§

§key: Option<KeyRef>§axis_direction: AxisDirection

The direction in which the offset’s ViewportOffset::pixels increases.

For example, if the axis direction is AxisDirection::Down, a scroll offset of zero is at the top of the viewport and increases towards the bottom of the viewport.

§cross_axis_direction: Option<AxisDirection>

The direction in which child should be laid out in the cross axis.

If the axis_direction is AxisDirection::Down or AxisDirection::Up, this property defaults to AxisDirection::Left if the ambient Directionality is right-to-left and AxisDirection::Right if it is left-to-right.

If the axis direction is AxisDirection::Left or AxisDirection::Right, this property defaults to AxisDirection::Down.

§anchor: f64

The relative position of the zero scroll offset.

For example, if the anchor is 0.5 and the axis_direction is AxisDirection::Down or AxisDirection::Up, then the zero scroll offset is vertically centered within the viewport. If the anchor is 1.0, and the axis direction is AxisDirection::Right, then the zero scroll offset is on the left edge of the viewport.

§offset: ViewportOffsetRef

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

The ViewportOffset::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.

Typically a ScrollPosition.

§center: Option<KeyRef>

The first child in the GrowthDirection::Forward growth direction.

Children after the center will be placed in the axis_direction relative to the center. Children before it will be placed in the opposite of the axis direction relative to the center.

The center must be the key of a child of the viewport.

§cache_extent: Option<f64>
👎Deprecated:

Use scroll_cache_extent instead.

The viewport has an area before and after the visible area to cache items that are about to become visible when the user scrolls.

See also:

§cache_extent_style: CacheExtentStyle
👎Deprecated:

Use scroll_cache_extent instead.

The unit of measurement of cache_extent.

§scroll_cache_extent: Option<ScrollCacheExtent>

The amount of additional content to display and lay out around the viewport.

§paint_order: SliverPaintOrder

The order in which to paint the slivers.

Defaults to SliverPaintOrder::FirstIsTop.

§clip_behavior: Clip

Defaults to Clip::HardEdge.

§slivers: Vec<WidgetRef>

The slivers to place inside the viewport.

Implementations§

Source§

impl Viewport

Source

pub fn new(offset: ViewportOffsetRef) -> Viewport

Creates a widget that is bigger on the inside.

The viewport listens to the offset, which means you do not need to rebuild this widget when the offset changes.

Source

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

Dart Viewport(key:).

Source

pub fn axis_direction(self, axis_direction: AxisDirection) -> Viewport

Dart Viewport(axisDirection:).

Source

pub fn cross_axis_direction( self, cross_axis_direction: AxisDirection, ) -> Viewport

Dart Viewport(crossAxisDirection:).

Source

pub fn anchor(self, anchor: f64) -> Viewport

Dart Viewport(anchor:).

Source

pub fn center(self, center: KeyRef) -> Viewport

Dart Viewport(center:).

Source

pub fn cache_extent(self, cache_extent: f64) -> Viewport

👎Deprecated:

Use scroll_cache_extent instead.

Dart Viewport(cacheExtent:).

Source

pub fn cache_extent_style( self, cache_extent_style: CacheExtentStyle, ) -> Viewport

👎Deprecated:

Use scroll_cache_extent instead.

Dart Viewport(cacheExtentStyle:).

Source

pub fn scroll_cache_extent( self, scroll_cache_extent: ScrollCacheExtent, ) -> Viewport

Dart Viewport(scrollCacheExtent:).

Source

pub fn paint_order(self, paint_order: SliverPaintOrder) -> Viewport

Dart Viewport(paintOrder:).

Source

pub fn clip_behavior(self, clip_behavior: Clip) -> Viewport

Dart Viewport(clipBehavior:).

Source

pub fn slivers(self, slivers: Vec<WidgetRef>) -> Viewport

Dart Viewport(slivers:).

Source

pub fn get_default_cross_axis_direction( app: &mut App, context: BuildContext, axis_direction: AxisDirection, ) -> AxisDirection

Given a BuildContext and an AxisDirection, determine the correct cross axis direction.

This depends on the Directionality if the axis_direction is vertical; otherwise, the default cross axis direction is downwards.

Trait Implementations§

Source§

impl Debug for Viewport

Source§

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

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

impl MultiChildRenderObjectWidget for Viewport

Source§

fn children(&self) -> &[WidgetRef]

The widgets below this widget in the tree. Read more
Source§

fn create_element(&self, app: &mut App, this: WidgetRef) -> AnyElement

Creates the element that manages this widget’s children. Read more
Source§

impl RenderObjectWidget for Viewport

Source§

type RenderObject = RenderViewport

The render object this widget creates; Dart’s covariant RenderObject parameter type.
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 create_render_object( &self, app: &mut App, context: BuildContext, ) -> AnyRenderObject

Creates an instance of the RenderObject class that this widget represents, using the configuration described by this widget. Read more
Source§

fn update_render_object( &self, app: &mut App, context: BuildContext, render_object: RenderHandle<RenderViewport>, )

Copies the configuration described by this widget to the given render object, which will be of the same type as returned by this object’s create_render_object. Read more
Source§

fn to_string_short(&self) -> String

Dart’s toStringShort, for a widget that names itself apart from its type, as SizedBox.expand does; see Widget::to_string_short.
Source§

fn debug_check_constructor(&self)

Source§

fn debug_visit_onstage_children( &self, app: &App, children: &[AnyElement], visitor: &mut dyn FnMut(AnyElement), )

Dart’s debugVisitOnstageChildren of the element this widget makes, for a widget whose Dart element subclass overrides it only to hide children (_OffstageElement, _IndexedStackElement): calls visitor for each of children, in order, that is onstage. Waft’s generic single- and multi-child elements stand in for those subclasses and ask their widget here; an element of a widget’s own overrides Element::debug_visit_onstage_children instead.
Source§

fn did_unmount_render_object( &self, app: &mut App, render_object: RenderHandle<Self::RenderObject>, )

A render object previously associated with this widget has been removed from the tree. The given RenderObject will be of the same type as returned by this object’s create_render_object.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Viewport

§

impl !Send for Viewport

§

impl !Sync for Viewport

§

impl !UnwindSafe for Viewport

§

impl Forget for Viewport

§

impl Freeze for Viewport
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, NonZero<u32>: Freeze, &'static ViewportOffsetVTable: Freeze, *const RcInner<Keep> is !null: Freeze, PhantomData<RcInner<Keep>>: Freeze, *const u8 is !null: Freeze, PhantomData<Rc<dyn Widget>>: Freeze,

§

impl Move for Viewport

§

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

§

impl UnsafeUnpin for Viewport
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, &'static ViewportOffsetVTable: UnsafeUnpin, *const RcInner<Keep> is !null: UnsafeUnpin, PhantomData<RcInner<Keep>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<Rc<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<MultiChildRenderObjectKind> for W

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>