Skip to main content

NavStackState

Struct NavStackState 

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

Source§

impl NavStackState

Source

pub fn new() -> Self

Source

pub fn depth(&self) -> usize

The number of views on the stack.

Source

pub fn is_empty(&self) -> bool

Source

pub fn current(&self) -> Option<&AnyView>

The view on top of the stack, which is the one shown once any transition has finished.

Source

pub fn views(&self) -> impl ExactSizeIterator<Item = &AnyView>

Every view on the stack, root first.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn replace( &mut self, view: impl Into<AnyView>, motion: NavMotion, cx: &mut Context<'_, Self>, ) -> Option<AnyView>

Swaps the top view for view and returns the one replaced, starting a NavOperation::Replace transition. The forward views are kept. On an empty stack this is a push.

Source

pub fn clear(&mut self, cx: &mut Context<'_, Self>)

Empties the stack and the forward views immediately, abandoning any running transition.

Trait Implementations§

Source§

impl Default for NavStackState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl EventEmitter<NavStackEvent> for NavStackState

Auto Trait Implementations§

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more