pub struct PersistentState<'f, T>{ /* private fields */ }Expand description
State that outlives the app, saved with egui’s persisted memory.
eframe writes it to disk natively and to localStorage on the web. Like localStorage, there
is one value per type for the whole app, shared by every view that extracts it.
Use it for preferences: a theme, a sort order, a collapsed sidebar. It is created with
T::default(), read at the start of the view and written back when the view returns (the
last view to write wins), so keep it small. Outside of views, use
PersistentState::get and PersistentState::set.
Saving needs eframe’s persistence feature. Without it, the value still lives in egui’s
memory, for as long as the app runs.
use egui::Ui;
use egui_kit::extract::PersistentState;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Serialize, Deserialize)]
struct Preferences {
compact: bool,
}
fn view(ui: &mut Ui, mut preferences: PersistentState<Preferences>) {
ui.checkbox(&mut preferences.compact, "Compact");
}Implementations§
Source§impl<T> PersistentState<'_, T>
Outside of views, e.g. to apply a theme before the router draws.
impl<T> PersistentState<'_, T>
Outside of views, e.g. to apply a theme before the router draws.
Trait Implementations§
Source§impl<T> Debug for PersistentState<'_, T>
impl<T> Debug for PersistentState<'_, T>
Source§impl<T> Deref for PersistentState<'_, T>
impl<T> Deref for PersistentState<'_, T>
Source§impl<T> DerefMut for PersistentState<'_, T>
impl<T> DerefMut for PersistentState<'_, T>
Source§impl<T> Drop for PersistentState<'_, T>
impl<T> Drop for PersistentState<'_, T>
Source§impl<S: 'static, D, T> FromView<S, D> for PersistentState<'_, T>
impl<S: 'static, D, T> FromView<S, D> for PersistentState<'_, T>
type Item<'f> = PersistentState<'f, T>
fn from_view<'f>(cx: &'f ViewContext<'_, S>) -> PersistentState<'f, T>
Auto Trait Implementations§
impl<'f, T> !RefUnwindSafe for PersistentState<'f, T>
impl<'f, T> !UnwindSafe for PersistentState<'f, T>
impl<'f, T> Forget for PersistentState<'f, T>
impl<'f, T> Freeze for PersistentState<'f, T>
impl<'f, T> Move for PersistentState<'f, T>
impl<'f, T> Send for PersistentState<'f, T>
impl<'f, T> Sync for PersistentState<'f, T>
impl<'f, T> Unpin for PersistentState<'f, T>
impl<'f, T> UnsafeUnpin for PersistentState<'f, T>
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
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> ⓘ
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 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> ⓘ
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