Guide API
Skip to main content

Event

Enum Event 

Source
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.

Fields

§command: Command
§source: Option<ViewId>
§

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

Source

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.

Source

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§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

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
Source§

impl Eq for Event

Source§

impl PartialEq for Event

Source§

fn eq(&self, other: &Event) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> 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> CustomValue for T
where T: Any + Debug,

Source§

fn as_any_rc(self: Rc<T>) -> Rc<dyn Any>

Upcast Rc<Self> to Rc<dyn Any> so FieldValue::as_custom / FieldValue::value_as can downcast.
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

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

Convert &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)

Convert &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
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.