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 ofViewportthat shrink-wraps its contents along the main axis.ViewportElementMixin, which should be mixed in to theElementtype used by viewport-like widgets to correctly handle scroll notifications.
Fields§
§key: Option<KeyRef>§axis_direction: AxisDirectionThe 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: f64The 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: ViewportOffsetRefWhich 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>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, which controls the units of the cache extent.
cache_extent_style: CacheExtentStyleUse 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: SliverPaintOrderThe order in which to paint the slivers.
Defaults to SliverPaintOrder::FirstIsTop.
clip_behavior: ClipDefaults to Clip::HardEdge.
slivers: Vec<WidgetRef>The slivers to place inside the viewport.
Implementations§
Source§impl Viewport
impl Viewport
Sourcepub fn new(offset: ViewportOffsetRef) -> Viewport
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.
Sourcepub fn axis_direction(self, axis_direction: AxisDirection) -> Viewport
pub fn axis_direction(self, axis_direction: AxisDirection) -> Viewport
Dart Viewport(axisDirection:).
Sourcepub fn cross_axis_direction(
self,
cross_axis_direction: AxisDirection,
) -> Viewport
pub fn cross_axis_direction( self, cross_axis_direction: AxisDirection, ) -> Viewport
Dart Viewport(crossAxisDirection:).
Sourcepub fn cache_extent(self, cache_extent: f64) -> Viewport
👎Deprecated: Use scroll_cache_extent instead.
pub fn cache_extent(self, cache_extent: f64) -> Viewport
Use scroll_cache_extent instead.
Dart Viewport(cacheExtent:).
Sourcepub fn cache_extent_style(
self,
cache_extent_style: CacheExtentStyle,
) -> Viewport
👎Deprecated: Use scroll_cache_extent instead.
pub fn cache_extent_style( self, cache_extent_style: CacheExtentStyle, ) -> Viewport
Use scroll_cache_extent instead.
Dart Viewport(cacheExtentStyle:).
Sourcepub fn scroll_cache_extent(
self,
scroll_cache_extent: ScrollCacheExtent,
) -> Viewport
pub fn scroll_cache_extent( self, scroll_cache_extent: ScrollCacheExtent, ) -> Viewport
Dart Viewport(scrollCacheExtent:).
Sourcepub fn paint_order(self, paint_order: SliverPaintOrder) -> Viewport
pub fn paint_order(self, paint_order: SliverPaintOrder) -> Viewport
Dart Viewport(paintOrder:).
Sourcepub fn clip_behavior(self, clip_behavior: Clip) -> Viewport
pub fn clip_behavior(self, clip_behavior: Clip) -> Viewport
Dart Viewport(clipBehavior:).
Sourcepub fn get_default_cross_axis_direction(
app: &mut App,
context: BuildContext,
axis_direction: AxisDirection,
) -> AxisDirection
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 RenderObjectWidget for Viewport
impl RenderObjectWidget for Viewport
Source§type RenderObject = RenderViewport
type RenderObject = RenderViewport
covariant RenderObject parameter type.Source§fn debug_fill_properties(
&self,
app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, app: &App, properties: &mut DiagnosticPropertiesBuilder, )
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
fn create_render_object( &self, app: &mut App, context: BuildContext, ) -> AnyRenderObject
RenderObject class that this widget represents, using the
configuration described by this widget. Read moreSource§fn update_render_object(
&self,
app: &mut App,
context: BuildContext,
render_object: RenderHandle<RenderViewport>,
)
fn update_render_object( &self, app: &mut App, context: BuildContext, render_object: RenderHandle<RenderViewport>, )
create_render_object. Read moreSource§fn to_string_short(&self) -> String
fn to_string_short(&self) -> String
toStringShort, for a widget that names itself apart from its type, as
SizedBox.expand does; see Widget::to_string_short.Source§fn debug_visit_onstage_children(
&self,
app: &App,
children: &[AnyElement],
visitor: &mut dyn FnMut(AnyElement),
)
fn debug_visit_onstage_children( &self, app: &App, children: &[AnyElement], visitor: &mut dyn FnMut(AnyElement), )
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>,
)
fn did_unmount_render_object( &self, app: &mut App, render_object: RenderHandle<Self::RenderObject>, )
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
impl Move for Viewport
impl Unpin for Viewport
impl UnsafeUnpin for Viewportwhere
*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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<MultiChildRenderObjectKind> for Wwhere
W: MultiChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: ContainerRenderObjectMixin,
impl<W> IntoWidget<MultiChildRenderObjectKind> for Wwhere
W: MultiChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: ContainerRenderObjectMixin,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.