#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.event_type: StringEvent type string — “click”, “input”, etc. Case-sensitive.
bubbles: boolWhether the event bubbles after the target. Default: true.
cancelable: boolWhether 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: EventPhaseCurrent phase of dispatch.
detail: EventDetailTyped 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
impl Event
pub fn new(event_type: impl Into<String>) -> Self
pub fn with_bubbles(self, bubbles: bool) -> Self
pub fn with_cancelable(self, cancelable: bool) -> Self
Sourcepub fn with_detail(self, detail: impl Into<String>) -> Self
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.
Sourcepub fn with_synthetic(self, synthetic: bool) -> Self
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", ...).
Sourcepub fn is_synthetic(&self) -> bool
pub fn is_synthetic(&self) -> bool
true iff this event was synthesized by the runtime. See
Event::with_synthetic.
Sourcepub fn stop_propagation(&mut self)
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).
Sourcepub fn stop_immediate_propagation(&mut self)
pub fn stop_immediate_propagation(&mut self)
Stop this event immediately: no further listeners run on this node, no further propagation.
Sourcepub fn prevent_default(&mut self)
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.
Sourcepub fn redraw_requested(&self) -> bool
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.