pub struct NavStackState { /* private fields */ }Expand description
A stack of views, one visible at a time, with the pages popped off it
kept for forward.
This is SwiftUI’s NavigationStack, Qt’s StackView and WinUI’s
Frame: navigation between pages. Underneath it is a History of
views from the root through the current page. A popped page becomes a
forward entry until a push discards that forward branch, which is what
WinUI’s BackStack and ForwardStack do.
The stack owns which view is current and the lifecycle of a change: after
a push, pop or replace, the outgoing view stays mounted until the
NavStack’s transition finishes, so the application can animate it.
The views themselves, and what a transition looks like, belong to the
application.
pop keeps the root, as Qt’s StackView and UIKit’s navigation controller
do; clear is the way to empty the stack. A back button is shown when
depth() > 1, a forward button when forward_views() is not empty.
Implementations§
pub fn new() -> Self
pub fn is_empty(&self) -> bool
Sourcepub fn current(&self) -> Option<&AnyView>
pub fn current(&self) -> Option<&AnyView>
The view on top of the stack, which is the one shown once any transition has finished.
Sourcepub fn views(&self) -> impl ExactSizeIterator<Item = &AnyView>
pub fn views(&self) -> impl ExactSizeIterator<Item = &AnyView>
Every view on the stack, root first.
Sourcepub fn forward_views(&self) -> impl ExactSizeIterator<Item = &AnyView>
pub fn forward_views(&self) -> impl ExactSizeIterator<Item = &AnyView>
The views popped since the last push, nearest first: the one
forward would bring back is the first.
Sourcepub fn push(
&mut self,
view: impl Into<AnyView>,
motion: NavMotion,
cx: &mut Context<'_, Self>,
)
pub fn push( &mut self, view: impl Into<AnyView>, motion: NavMotion, cx: &mut Context<'_, Self>, )
Pushes view on top of the stack and discards the forward views.
Into an empty stack this is immediate, like Qt’s initialItem. Over
an existing top it starts a NavOperation::Push transition, unless
motion is NavMotion::Immediate.
Sourcepub fn pop(
&mut self,
motion: NavMotion,
cx: &mut Context<'_, Self>,
) -> Option<AnyView>
pub fn pop( &mut self, motion: NavMotion, cx: &mut Context<'_, Self>, ) -> Option<AnyView>
Pops the top view and returns it, starting a NavOperation::Pop
transition to the view below. The view waits in forward_views.
The root is never popped: this returns None at a depth of one or
less.
Sourcepub fn pop_to_root(
&mut self,
motion: NavMotion,
cx: &mut Context<'_, Self>,
) -> Vec<AnyView>
pub fn pop_to_root( &mut self, motion: NavMotion, cx: &mut Context<'_, Self>, ) -> Vec<AnyView>
Pops every view above the root in one NavOperation::Pop
transition from the previous top, and returns them root-side first.
Sourcepub fn forward(
&mut self,
motion: NavMotion,
cx: &mut Context<'_, Self>,
) -> Option<AnyView>
pub fn forward( &mut self, motion: NavMotion, cx: &mut Context<'_, Self>, ) -> Option<AnyView>
Brings back the most recently popped view, starting a
NavOperation::Push transition over the current top, and returns
it. None when nothing has been popped since the last push.
Trait Implementations§
Auto Trait Implementations§
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().