pub struct StateHandle<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: State> StateHandle<S>
impl<S: State> StateHandle<S>
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: Clone + 'static>(
&self,
change: impl Fn(&mut S, T) + 'static,
) -> impl Fn(T) -> Callback + 'static
pub fn handler<T: Clone + 'static>( &self, change: impl Fn(&mut S, T) + 'static, ) -> impl Fn(T) -> Callback + '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.