Skip to main content

EventCtx

Struct EventCtx 

Source
pub struct EventCtx { /* private fields */ }
Expand description

The context passed to Widget::handle_event.

Widgets use it to queue the events they generate. Queueing, instead of calling application code from inside the Widget, lets callbacks later receive mutable access to both the application state and every Widget.

Implementations§

Source§

impl EventCtx

Source

pub fn emit(&mut self, event: Event)

Queues an event generated by a Widget.

Queued events are delivered to the application in the order in which they were emitted.

§Arguments
  • event - The event to queue, such as Event::Clicked { id, button, count }.
Source

pub fn post<T: Any>(&mut self, target: EventTarget, payload: T)

Posts a custom event, with the Widget currently handling an event as its source.

The event is queued behind the events already waiting and delivered later, in order, never from inside this call. See CustomEvent.

§Arguments
  • target - Which Widgets receive the event.
  • payload - The application’s data; receivers read it with Event::payload.
Source

pub fn request_animation(&mut self)

Asks for an Event::Tick on the next frame, for the Widget currently handling an event.

The request is for one frame, like a browser’s requestAnimationFrame: a Widget that keeps animating calls this again each time it handles a Tick, and stops by not calling it. Only Widgets with EventMask::TIMER in their mask receive the tick. Does nothing outside event handling.

Source

pub fn phase(&self) -> EventPhase

Returns the phase of delivery the current event is in.

§Returns

EventPhase::Target unless the event is being captured or bubbled.

Source

pub fn into_events(self) -> Vec<Event>

Consumes the context and returns the queued events.

§Returns

The queued events, in the order emitted.

Trait Implementations§

Source§

impl Default for EventCtx

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.