Trait EmitContext
pub trait EmitContext {
// Required methods
fn emit<M>(&mut self, message: M)
where M: Any + Send;
fn emit_to<M>(&mut self, target: Entity, message: M)
where M: Any + Send;
fn emit_custom(&mut self, event: Event);
fn schedule_emit<M>(&mut self, message: M, at: Instant) -> TimedEventHandle
where M: Any + Send;
fn schedule_emit_to<M>(
&mut self,
target: Entity,
message: M,
at: Instant,
) -> TimedEventHandle
where M: Any + Send;
fn schedule_emit_custom(
&mut self,
event: Event,
at: Instant,
) -> TimedEventHandle;
fn cancel_scheduled(&mut self, handle: TimedEventHandle);
}
Required Methods§
fn emit<M>(&mut self, message: M)
fn emit<M>(&mut self, message: M)
Send an event containing the provided message up the tree from the current entity.
§Example
cx.emit(AppEvent::Increment);
fn emit_to<M>(&mut self, target: Entity, message: M)
fn emit_to<M>(&mut self, target: Entity, message: M)
Send an event containing the provided message directly to a specified entity from the current entity.
§Example
cx.emit_to(Entity::root(), AppEvent::Increment);
fn emit_custom(&mut self, event: Event)
fn emit_custom(&mut self, event: Event)
Send a custom event with custom origin and propagation information.
§Example
cx.emit_custom(
Event::new(AppEvent::Increment)
.origin(cx.current())
.target(Entity::root())
.propagate(Propagation::Subtree)
);
fn schedule_emit<M>(&mut self, message: M, at: Instant) -> TimedEventHandle
fn schedule_emit<M>(&mut self, message: M, at: Instant) -> TimedEventHandle
Send an event containing the provided message up the tree at a particular time instant.
Returns a TimedEventHandle
which can be used to cancel the scheduled event.
§Example
Emit an event after a delay of 2 seconds:
cx.schedule_emit(AppEvent::Increment, Instant::now() + Duration::from_secs(2));
fn schedule_emit_to<M>(
&mut self,
target: Entity,
message: M,
at: Instant,
) -> TimedEventHandle
fn schedule_emit_to<M>( &mut self, target: Entity, message: M, at: Instant, ) -> TimedEventHandle
Send an event containing the provided message directly to a specified view at a particular time instant.
Returns a TimedEventHandle
which can be used to cancel the scheduled event.
§Example
Emit an event to the root view (window) after a delay of 2 seconds:
cx.schedule_emit_to(Entity::root(), AppEvent::Increment, Instant::now() + Duration::from_secs(2));
fn schedule_emit_custom(
&mut self,
event: Event,
at: Instant,
) -> TimedEventHandle
fn schedule_emit_custom( &mut self, event: Event, at: Instant, ) -> TimedEventHandle
Send a custom event with custom origin and propagation information at a particular time instant.
Returns a TimedEventHandle
which can be used to cancel the scheduled event.
§Example
Emit a custom event after a delay of 2 seconds:
cx.schedule_emit_custom(
Event::new(AppEvent::Increment)
.target(Entity::root())
.origin(cx.current())
.propagate(Propagation::Subtree),
Instant::now() + Duration::from_secs(2)
);
fn cancel_scheduled(&mut self, handle: TimedEventHandle)
fn cancel_scheduled(&mut self, handle: TimedEventHandle)
Cancel a scheduled event before it is sent.
§Example
let timed_event = cx.schedule_emit_to(Entity::root(), AppEvent::Increment, Instant::now() + Duration::from_secs(2));
cx.cancel_scheduled(timed_event);