Trait vizia_core::context::EmitContext

source ·
pub trait EmitContext {
    // Required methods
    fn emit<M: Any + Send>(&mut self, message: M);
    fn emit_to<M: Any + Send>(&mut self, target: Entity, message: M);
    fn emit_custom(&mut self, event: Event);
    fn schedule_emit<M: Any + Send>(
        &mut self,
        message: M,
        at: Instant,
    ) -> TimedEventHandle;
    fn schedule_emit_to<M: Any + Send>(
        &mut self,
        target: Entity,
        message: M,
        at: Instant,
    ) -> TimedEventHandle;
    fn schedule_emit_custom(
        &mut self,
        event: Event,
        at: Instant,
    ) -> TimedEventHandle;
    fn cancel_scheduled(&mut self, handle: TimedEventHandle);
}

Required Methods§

source

fn emit<M: Any + Send>(&mut self, message: M)

Send an event containing the provided message up the tree from the current entity.

§Example
cx.emit(AppEvent::Increment);
source

fn emit_to<M: Any + Send>(&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);
source

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)
);
source

fn schedule_emit<M: Any + Send>( &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));
source

fn schedule_emit_to<M: Any + Send>( &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));
source

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)
);
source

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);

Object Safety§

This trait is not object safe.

Implementors§