pub enum Event {
MouseDown(MouseEvent),
MouseUp(MouseEvent),
MouseMove(MouseEvent),
MouseAuto(MouseEvent),
MouseWheel(MouseEvent),
KeyDown(KeyEvent),
Command(Command),
Broadcast {
command: Command,
source: Option<ViewId>,
},
Timer(TimerId),
Nothing,
Paste(String),
}Expand description
An event a View handles, matched arm-by-arm.
Match on an &Event in View::handle_event to
selectively react to the cases you care about; return the event unchanged to
let it propagate, or call Event::clear (or assign *ev = Event::Nothing)
to consume it. Event::Nothing serves dual duty: it is both “no pending
event” and the consumed-event sentinel.
The five mouse variants (MouseDown, MouseUp, MouseMove, MouseAuto,
MouseWheel) correspond one-to-one to the magiblot C++ event-class constants
(evMouseDown, evMouseUp, etc.), making each class independently matchable.
To handle any mouse event, match all five; to handle clicks only, match
MouseDown and MouseUp.
§Turbo Vision heritage
Replaces the TEvent tagged union (a bitmask tag plus a union of
mouse/key/message records; system.h) with a real Rust sum type, matched
arm-by-arm instead of masked (deviation D4).
Variants§
MouseDown(MouseEvent)
A mouse button was pressed. Deliver to focused view; position is in
screen coordinates. Check MouseEvent::buttons for which button.
MouseUp(MouseEvent)
A mouse button was released. Paired with MouseDown; arrives at the
view that captured the pointer.
MouseMove(MouseEvent)
The mouse moved without a button held (opt-in; see EventMask::mouse_move).
MouseAuto(MouseEvent)
Auto-repeat while a button is held (opt-in; see EventMask::mouse_auto).
MouseWheel(MouseEvent)
The mouse wheel was rotated. A distinct event class from MouseDown:
the wheel is not positional and not focused, so a
crate::view::Group broadcasts it to every child until one consumes it —
the active window’s scrollbar gets it regardless of cursor position.
Carries a MouseEvent whose MouseEvent::wheel is
Up/Down/Left/Right.
KeyDown(KeyEvent)
A key was pressed. Match Event::KeyDown(ke) and inspect ke.key and
ke.modifiers (see KeyEvent).
Command(Command)
A command targeted at a specific receiver. The event loop routes it
through the capture stack; the first view that recognises the command
should consume it via Event::clear.
Broadcast
A command broadcast to interested views. source names which view this
broadcast is about (e.g. which scrollbar changed), as a resolvable
ViewId. None for broadcasts about no particular view.
Timer(TimerId)
A timer fired, carrying which TimerId expired.
The timer id is an integer payload, not a view subject, so it gets its own
typed variant rather than reusing Event::Broadcast’s source field
(which is for the view-subject case only). Delivered to all views.
Nothing
No pending event, or the consumed-event sentinel after Event::clear.
Both “the queue is empty” and “a handler consumed this event” map to
this variant. To consume an event inside a handler: call
ev.clear() or assign *ev = Event::Nothing. To test whether an event
was consumed after returning from a sub-handler: call
Event::is_nothing.
Paste(String)
Terminal bracketed-paste — the whole pasted string as delivered by the
terminal. Routed identically to a key press — delivered only to the focused
view, not broadcast. Handle it alongside KeyDown in input widgets that
accept text.
Implementations§
Source§impl Event
impl Event
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Mark this event as handled by setting it to Event::Nothing.
Call this inside a View::handle_event
implementation when your view has fully processed the event and no other
view should see it. After clear() the caller can call
is_nothing to confirm the event was consumed.
Prefer clear() over assigning Event::Nothing directly — it makes the
intent explicit.
Sourcepub fn is_nothing(&self) -> bool
pub fn is_nothing(&self) -> bool
Returns true if this event is Event::Nothing — either no event was
produced or a prior handler consumed it via clear.
Use this to check, after dispatching to a sub-handler, whether the event was consumed (so you can skip further routing).
Trait Implementations§
impl Eq for Event
impl StructuralPartialEq for Event
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.