Skip to main content

Nav

Struct Nav 

Source
pub struct Nav<'f> { /* private fields */ }
Expand description

The router, as seen by a view: navigating, loading, shallow routing and blocking.

An extractor: add a nav: Nav argument to any view. It is Copy, so it can be used in nested closures. Requests are queued and applied after the frame.

Implementations§

Source§

impl<'f> Nav<'f>

Where we are.

Source

pub fn url(&self) -> &'f str

The url of the current history entry. Differs from the page’s Request after Nav::push_state / Nav::replace_state with a new url.

Source

pub fn is_active(&self, href: &str) -> bool

Whether href is the current path, or (for anything but /) a parent of it. The path is Nav::url’s, so it follows shallow routing.

Source

pub fn is_outgoing(&self) -> bool

Whether this is the previous page, rendered while a ViewTransition animates it out. Its Ui is disabled (without looking so), and its navigation calls are ignored. Skip things that live outside the page’s Ui (windows, modals, popups), which the transition can’t fade, clip or disable.

Source§

impl Nav<'_>

Navigating.

Source

pub fn goto(&self, url: impl Into<String>)

Navigates to url, adding a history entry.

The current page stays visible until all hooks and load handlers of the new route finished. Going to the current url does nothing (the page keeps its state), unless GotoOptions::invalidate_all asks for a reload. Going to the url that is already loading, with the same options, keeps that navigation going, so a view may ask for it every frame until it is done.

Source

pub fn goto_with(&self, url: impl Into<String>, options: GotoOptions)

Nav::goto with options.

Source

pub fn replace(&self, url: impl Into<String>)

Navigates to url, replacing the current history entry. Like Nav::goto, going to the current url does nothing, unless GotoOptions::invalidate_all asks for a reload.

Source

pub fn back(&self)

Source

pub fn forward(&self)

Source

pub fn can_go_back(&self) -> bool

Source

pub fn can_go_forward(&self) -> bool

A hyperlink that navigates within the app. Preloads the target while hovered, unless disabled.

A selectable label that is highlighted when href is active.

Source

pub fn follow(&self, response: &Response, href: &str)

Makes any widget behave like a link to href: a click navigates there, hovering preloads it and lets the browser show it (see BrowserHistory::link_preview), which then also opens Ctrl/Cmd/Shift-clicks in a new tab.

fn card(ui: &mut egui::Ui, nav: Nav, title: &str, href: &str) {
    let response = egui::Frame::group(ui.style())
        .show(ui, |ui| ui.heading(title))
        .response
        .interact(egui::Sense::click());
    nav.follow(&response, href);
}
Source§

impl Nav<'_>

Loading.

Source

pub fn is_loading(&self) -> bool

Whether a navigation is in progress.

Source

pub fn loading_url(&self) -> Option<String>

The url currently being loaded, if any.

Source

pub fn preload(&self, url: impl Into<String>)

Starts loading url (hooks and loads) in the background, so that navigating there is instant. Preloads are dropped once any navigation finishes.

Source

pub fn invalidate(&self, key: impl Into<String>)

Reruns the loads of the current page that depend on key, and the loads below them that use Parent. Queries that depend on it refetch too.

Source

pub fn invalidate_all(&self)

Reruns all loads of the current page, and refetches all queries.

Source§

impl Nav<'_>

Shallow routing.

Source

pub fn push_state<T: Any>(&self, url: impl Into<String>, state: T)

Adds a history entry with url ("" keeps the current url) and attaches state to it, without running hooks or loads. The page stays as it is and can read the state with the HistoryState extractor.

Going back and forward between entries of the same page only swaps the page state. Entries of a page that is no longer shown are loaded normally, and get their state back. A browser reload loses all page state, so url should also work on its own, e.g. for a photo opened in a modal, the photo’s own page.

Source

pub fn replace_state<T: Any>(&self, url: impl Into<String>, state: T)

Like Nav::push_state, but replaces the state (and url) of the current entry.

Source

pub fn replace_url(&self, url: impl Into<String>)

Changes the url of the current entry, keeping its state: to keep the address in step with the page (another day in a calendar, another tab) without a navigation. Like Nav::replace_state, the url should also work on its own.

Source

pub fn clear_history_state(&self)

Removes the state of the current entry, keeping its url.

Source§

impl Nav<'_>

Blocking navigation.

Source

pub fn block_navigation(&self)

Call every frame while leaving the page would lose something (e.g. unsaved changes). Navigations away from the page (links, goto, back/forward) are then held back until you confirm or cancel them; see Nav::blocked_navigation. Shallow routing and invalidation are not affected.

Closing the browser tab or reloading it can’t be blocked this way.

Source

pub fn blocked_navigation(&self) -> Option<Navigation>

The navigation being held back, to ask the user what to do.

Source

pub fn confirm_navigation(&self)

Lets the blocked navigation happen.

Source

pub fn cancel_navigation(&self)

Drops the blocked navigation.

Trait Implementations§

Source§

impl<'f> Clone for Nav<'f>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'f> Copy for Nav<'f>

Source§

impl<S: 'static, D> FromView<S, D> for Nav<'_>

Source§

type Item<'f> = Nav<'f>

Source§

fn from_view<'f>(cx: &'f ViewContext<'_, S>) -> Nav<'f>

Auto Trait Implementations§

§

impl<'f> !RefUnwindSafe for Nav<'f>

§

impl<'f> !Send for Nav<'f>

§

impl<'f> !Sync for Nav<'f>

§

impl<'f> !UnwindSafe for Nav<'f>

§

impl<'f> Freeze for Nav<'f>

§

impl<'f> Unpin for Nav<'f>

§

impl<'f> UnsafeUnpin for Nav<'f>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromRef<S> for S

Source§

fn from_ref(state: &S) -> &S

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.