Trait zng_app::widget::VarSubscribe
source · pub trait VarSubscribe<T: VarValue>: Var<T> + AnyVarSubscribe {
// Required method
fn subscribe_when(
&self,
op: UpdateOp,
widget_id: WidgetId,
predicate: impl Fn(&T) -> bool + Send + Sync + 'static
) -> VarHandle;
// Provided methods
fn on_pre_new<H>(&self, handler: H) -> VarHandle
where H: AppHandler<OnVarArgs<T>> { ... }
fn on_new<H>(&self, handler: H) -> VarHandle
where H: AppHandler<OnVarArgs<T>> { ... }
}Expand description
Extension methods to subscribe any widget to a variable or app handlers to a variable.
Also see WIDGET methods for the primary way to subscribe from inside a widget.
Required Methods§
sourcefn subscribe_when(
&self,
op: UpdateOp,
widget_id: WidgetId,
predicate: impl Fn(&T) -> bool + Send + Sync + 'static
) -> VarHandle
fn subscribe_when( &self, op: UpdateOp, widget_id: WidgetId, predicate: impl Fn(&T) -> bool + Send + Sync + 'static ) -> VarHandle
Register the widget to receive an UpdateOp when this variable is new and the predicate approves the new value.
Variables without the NEW capability return VarHandle::dummy.
Provided Methods§
sourcefn on_pre_new<H>(&self, handler: H) -> VarHandlewhere
H: AppHandler<OnVarArgs<T>>,
fn on_pre_new<H>(&self, handler: H) -> VarHandlewhere
H: AppHandler<OnVarArgs<T>>,
Add a preview handler that is called every time this variable updates,
the handler is called before UI update.
Note that the handler runs on the app context, all ContextVar<T> used inside will have the default value.
sourcefn on_new<H>(&self, handler: H) -> VarHandlewhere
H: AppHandler<OnVarArgs<T>>,
fn on_new<H>(&self, handler: H) -> VarHandlewhere
H: AppHandler<OnVarArgs<T>>,
Add a handler that is called every time this variable updates,
the handler is called after UI update.
Note that the handler runs on the app context, all ContextVar<T> used inside will have the default value.