Trait egui_hooks::UseHookExt
source · pub trait UseHookExt {
// Required methods
fn use_hook_as<T: Hook<D>, D: Deps>(
&mut self,
id: Id,
hook: T,
deps: D
) -> T::Output;
fn use_hook<T: Hook<D>, D: Deps>(&mut self, hook: T, deps: D) -> T::Output;
fn use_state<T: Clone + Send + Sync + 'static, D: Deps>(
&mut self,
default: impl FnOnce() -> T,
deps: D
) -> State<T>;
fn use_persisted_state<T: SerializableAny, D: Deps>(
&mut self,
default: impl FnOnce() -> T,
deps: D
) -> State<T>;
fn use_memo<T: Clone + Send + Sync + 'static, F: FnMut() -> T, D: Deps>(
&mut self,
callback: F,
deps: D
) -> T;
fn use_effect<F: FnOnce() + Send + Sync, D: Deps>(
&mut self,
callback: F,
deps: D
);
fn use_cleanup<F: FnOnce() + Send + Sync + 'static, D: Deps>(
&mut self,
callback: F,
deps: D
);
fn use_kv<K: Send + Sync + 'static, V: Send + Sync + 'static>(
&mut self
) -> Kv<K, V>;
fn use_persisted_kv<K: SerializableAny + Eq + Hash, V: SerializableAny>(
&mut self
) -> Kv<K, V>;
fn use_2f_kv<K: Clone + Eq + Hash + Send + Sync + 'static, V: Send + Sync + 'static>(
&mut self
) -> TwoFrameKv<K, V>;
fn use_persisted_2f_kv<K: Clone + Eq + Hash + SerializableAny, V: SerializableAny>(
&mut self
) -> TwoFrameKv<K, V>;
fn use_ephemeral_kv<K: Eq + Hash + Send + Sync + 'static, V: Send + Sync + 'static>(
&mut self
) -> EphemeralKv<K, V>;
}
Required Methods§
fn use_hook_as<T: Hook<D>, D: Deps>( &mut self, id: Id, hook: T, deps: D ) -> T::Output
fn use_hook<T: Hook<D>, D: Deps>(&mut self, hook: T, deps: D) -> T::Output
fn use_state<T: Clone + Send + Sync + 'static, D: Deps>( &mut self, default: impl FnOnce() -> T, deps: D ) -> State<T>
fn use_persisted_state<T: SerializableAny, D: Deps>( &mut self, default: impl FnOnce() -> T, deps: D ) -> State<T>
fn use_memo<T: Clone + Send + Sync + 'static, F: FnMut() -> T, D: Deps>( &mut self, callback: F, deps: D ) -> T
fn use_effect<F: FnOnce() + Send + Sync, D: Deps>( &mut self, callback: F, deps: D )
fn use_cleanup<F: FnOnce() + Send + Sync + 'static, D: Deps>( &mut self, callback: F, deps: D )
fn use_kv<K: Send + Sync + 'static, V: Send + Sync + 'static>( &mut self ) -> Kv<K, V>
fn use_persisted_kv<K: SerializableAny + Eq + Hash, V: SerializableAny>( &mut self ) -> Kv<K, V>
fn use_2f_kv<K: Clone + Eq + Hash + Send + Sync + 'static, V: Send + Sync + 'static>( &mut self ) -> TwoFrameKv<K, V>
fn use_persisted_2f_kv<K: Clone + Eq + Hash + SerializableAny, V: SerializableAny>( &mut self ) -> TwoFrameKv<K, V>
fn use_ephemeral_kv<K: Eq + Hash + Send + Sync + 'static, V: Send + Sync + 'static>( &mut self ) -> EphemeralKv<K, V>
Object Safety§
This trait is not object safe.
Implementations on Foreign Types§
source§impl UseHookExt for Ui
impl UseHookExt for Ui
source§fn use_state<T: Clone + Send + Sync + 'static, D: Deps>(
&mut self,
default: impl FnOnce() -> T,
deps: D
) -> State<T>
fn use_state<T: Clone + Send + Sync + 'static, D: Deps>( &mut self, default: impl FnOnce() -> T, deps: D ) -> State<T>
Returns a state that is initialized with the given default value.
A state is resetted to new default value when the dependencies are changed.
If you need to mutabe the state as like normal variable, put .into_var()
after this.
Example
let ctx = egui::Context::default();
egui::Area::new("test").show(&ctx, |ui| {
use egui_hooks::UseHookExt as _;
let mut state = ui.use_state(|| 42, ());
let mut var_state = ui.use_state(|| 42, ()).into_var();
});