pub struct StateHandle<S>where
S: State,{ /* private fields */ }Expand description
A way to reach a widget’s state from outside its build: from a handler, a listener, a
timer. Cheap to clone.
Implementations§
Source§impl<S> StateHandle<S>where
S: State,
impl<S> StateHandle<S>where
S: State,
Sourcepub fn set_state(&self, change: impl FnOnce(&mut S))
pub fn set_state(&self, change: impl FnOnce(&mut S))
Changes the state, and asks for a rebuild.
Does nothing once the widget has left the tree: a timer that outlives its widget finds nothing to change.
Sourcepub fn is_mounted(&self) -> bool
pub fn is_mounted(&self) -> bool
Whether the widget is still in the tree.
Sourcepub fn callback(&self, change: impl Fn(&mut S) + 'static) -> Callback
pub fn callback(&self, change: impl Fn(&mut S) + 'static) -> Callback
A handler that changes the state, for anything that takes a Callback.
Sourcepub fn handler<T>(
&self,
change: impl Fn(&mut S, T) + 'static,
) -> impl Fn(T) + 'staticwhere
T: Clone + 'static,
pub fn handler<T>(
&self,
change: impl Fn(&mut S, T) + 'static,
) -> impl Fn(T) + 'staticwhere
T: Clone + 'static,
A handler for a widget that reports a value — a field’s text, a slider’s position, a
switch’s new setting: TextField::new(..).on_input(cx.handler(|s, text: String| s.name = text)).
It answers the value with a Callback that makes the change when it is delivered, which
is what every widget’s setter takes and what leaves no doubt about the message type — a
closure that returns nothing could be a handler for any.
Trait Implementations§
Source§impl<S> Clone for StateHandle<S>where
S: State,
impl<S> Clone for StateHandle<S>where
S: State,
Source§fn clone(&self) -> StateHandle<S>
fn clone(&self) -> StateHandle<S>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<S> !RefUnwindSafe for StateHandle<S>
impl<S> !Send for StateHandle<S>
impl<S> !Sync for StateHandle<S>
impl<S> !UnwindSafe for StateHandle<S>
impl<S> Freeze for StateHandle<S>
impl<S> Unpin for StateHandle<S>
impl<S> UnsafeUnpin for StateHandle<S>where
Rc<StateCell<S>>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.