Skip to main content

PageState

Struct PageState 

Source
pub struct PageState<'f, T: 'static> { /* private fields */ }
Expand description

State a view owns for as long as its page is shown.

Created with T::default() the first time it is extracted, then kept from frame to frame: use it for what the user does on the page (a form’s text, a toggle). Unlike the load’s data, it survives invalidations. It is dropped when the user navigates away, and starts over when they come back. For state that comes back with back/forward, use Snapshot.

In a page view, it belongs to the page instance, which shallow routing and invalidations keep. In a layout view, it belongs to the layout and lasts as long as the layout stays on screen, so it survives navigations between the pages below it.

Each type is one value per view: use a dedicated type, not String or bool.

use egui::Ui;
use egui_kit::extract::PageState;

#[derive(Default)]
struct Draft {
    title: String,
}

fn view(ui: &mut Ui, mut draft: PageState<Draft>) {
    ui.text_edit_singleline(&mut draft.title);
}

To start from the load’s data, see PageStateFrom.

Trait Implementations§

Source§

impl<T: Debug> Debug for PageState<'_, T>

Source§

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

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

impl<T> Deref for PageState<'_, T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T> DerefMut for PageState<'_, T>

Source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
Source§

impl<T> Drop for PageState<'_, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<S: 'static, D, T: Default + 'static> FromView<S, D> for PageState<'_, T>

Source§

type Item<'f> = PageState<'f, T>

Source§

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

Auto Trait Implementations§

§

impl<'f, T> !RefUnwindSafe for PageState<'f, T>

§

impl<'f, T> !Send for PageState<'f, T>

§

impl<'f, T> !Sync for PageState<'f, T>

§

impl<'f, T> !UnwindSafe for PageState<'f, T>

§

impl<'f, T> Forget for PageState<'f, T>

§

impl<'f, T> Freeze for PageState<'f, T>
where *const T is !null: Freeze, PhantomData<T>: Freeze, &'f TypeMap: Freeze,

§

impl<'f, T> Move for PageState<'f, T>

§

impl<'f, T> Unpin for PageState<'f, T>
where Box<T>: Unpin, &'f TypeMap: Unpin,

§

impl<'f, T> UnsafeUnpin for PageState<'f, T>
where *const T is !null: UnsafeUnpin, PhantomData<T>: UnsafeUnpin, &'f TypeMap: 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> ErasedDestructor for T
where T: 'static,

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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, 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.