Skip to main content

Event

Struct Event 

Source
#[non_exhaustive]
pub struct Event { pub event_type: String, pub bubbles: bool, pub cancelable: bool, pub target: Option<NodeId>, pub current_target: Option<NodeId>, pub phase: EventPhase, pub detail: EventDetail, /* private fields */ }
Expand description

Minimal event — just routing state. Attach payload via a typed wrapper in rdom-tui or the caller’s crate.

Users typically build one with Event::new("click"), optionally call with_bubbles(false) / with_cancelable(true), then pass to Dom::dispatch_event(target, &mut event).

§Cloning

clone() is the web’s new Event(e.type, e): a fresh, undispatched event. It copies event_type, the init flags (bubbles, cancelable) and detail; everything a dispatch writes starts over — target and current_target are None, phase is EventPhase::None, the stop-propagation and canceled flags are clear, the dispatch flag is unset and redraw_requested is false. A copy is script-made, so it is not synthetic (a scripted copy has isTrusted false on the web). A clone taken inside a listener can therefore be dispatched or queued; the in-flight original still cannot (DOM §2.9 step 1).

Event has no timeStamp, so there is no creation time to copy or restart; should one be added, a copy takes its own creation time, as new Event() does (DOM §2.2).

Read what a listener needs from the dispatch state (target, phase, default_prevented()) inside the listener: a clone does not carry it.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§event_type: String

Event type string — “click”, “input”, etc. Case-sensitive.

§bubbles: bool

Whether the event bubbles after the target. Default: true.

§cancelable: bool

Whether prevent_default has meaning for this event. Default: true.

§target: Option<NodeId>

The node where dispatch was initiated. Set by dispatch_event; callers don’t need to fill this in.

§current_target: Option<NodeId>

The node currently being visited in dispatch. Updated per node so handlers see it.

§phase: EventPhase

Current phase of dispatch.

§detail: EventDetail

Typed payload for event types that carry semantic data. EventDetail::None for events that don’t carry detail (default on Event::new); EventDetail::String for CustomEvent-style ad-hoc author payloads; typed variants for events with structured payloads (transitions, inputs, submits, toggles, mouse, keyboard). Listeners read via the as_* accessors on EventDetail.

Implementations§

Source§

impl Event

Source

pub fn new(event_type: impl Into<String>) -> Self

Source

pub fn with_bubbles(self, bubbles: bool) -> Self

Source

pub fn with_cancelable(self, cancelable: bool) -> Self

Source

pub fn with_detail(self, detail: impl Into<String>) -> Self

Builder-style detail setter for string payloads — Event::new("custom").with_detail("hello"). Produces an EventDetail::String; for typed variants set event.detail directly to the relevant variant.

Source

pub fn with_synthetic(self, synthetic: bool) -> Self

Mark this event as synthesized by the runtime. Default is false (not synthesized). Use when composing higher-level events from lower-level ones — e.g., the runtime creates a synthetic click after matching mousedown+mouseup, so handlers firing during click can distinguish it from a handler-scripted dispatch_event("click", ...).

Source

pub fn is_synthetic(&self) -> bool

true iff this event was synthesized by the runtime. See Event::with_synthetic.

Source

pub fn stop_propagation(&mut self)

Stop bubbling/capturing on subsequent nodes. Listeners still registered at the current node and phase continue to fire (see stop_immediate_propagation for the harder stop); at the target, calling this from a capture listener suppresses the target’s bubble listeners, which belong to the next pass. The flag is cleared when the dispatch ends (DOM §2.9 step 5.9).

Source

pub fn stop_immediate_propagation(&mut self)

Stop this event immediately: no further listeners run on this node, no further propagation.

Source

pub fn prevent_default(&mut self)

Signal “please skip the default action”. Only meaningful if cancelable is true. The Dom itself has no notion of “default action”; higher layers check default_prevented() to decide.

Source

pub fn redraw_requested(&self) -> bool

true if any listener called EventCtx::request_redraw during this dispatch. The rendering host reads this after dispatch_event returns to decide whether to repaint.

Source

pub fn is_propagation_stopped(&self) -> bool

Source

pub fn is_immediate_propagation_stopped(&self) -> bool

Source

pub fn default_prevented(&self) -> bool

Trait Implementations§

Source§

impl Clone for Event

DOM §2.2 new Event(e.type, e) — see Event’s “Cloning”.

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Event

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnsafeUnpin for Event

§

impl UnwindSafe for Event

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.