Skip to main content

EventHandler

Trait EventHandler 

Source
pub trait EventHandler<W>
where W: Window,
{ // Required methods fn on_resume(&mut self, window: &W) -> bool; fn on_event(&mut self, event: Event, window: &W); fn on_redraw(&mut self, window: &W); // Provided methods fn on_suspend(&mut self) { ... } fn accessibility(&self) -> Vec<AccessNode> { ... } fn on_accessibility_action(&mut self, _id: u64, _activate: bool) { ... } fn remount(&mut self, _window: &W) { ... } fn new_events(&mut self) { ... } fn about_to_wait(&mut self) -> Option<Duration> { ... } fn take_exit_request(&mut self) -> bool { ... } fn last_frame_rgba(&self) -> Option<Vec<u8>> { ... } fn interactive_rects(&self) -> Vec<Rect> { ... } }

Required Methods§

Source

fn on_resume(&mut self, window: &W) -> bool

Source

fn on_event(&mut self, event: Event, window: &W)

Source

fn on_redraw(&mut self, window: &W)

Provided Methods§

Source

fn on_suspend(&mut self)

Source

fn accessibility(&self) -> Vec<AccessNode>

The window’s accessibility tree as it stands, for the platform to hand to whatever is listening.

Asked for on demand rather than pushed every frame, because on every desktop accessibility API the answer is only wanted while an assistive technology is attached — which is almost never. A handler with no tree to describe leaves it empty and the platform publishes nothing.

Source

fn on_accessibility_action(&mut self, _id: u64, _activate: bool)

A screen reader asked to move to a control, or to activate it — id being the one the handler put in AccessNode::id.

Routed to the same focus and press the keyboard reaches, deliberately: a second activation path is a second thing to keep correct, and it is always the one nobody is testing that rots.

Source

fn remount(&mut self, _window: &W)

Rebuilds this handler’s UI from its app, on the surface it is already running on.

For a backend whose surfaces outlive the state they were built from — a shell whose bars are described by a config file the user edits — this is the difference between a reload and a restart: the window, its renderer and its place on screen are kept, and only the tree is built again. A handler with no tree to rebuild leaves it a no-op.

Source

fn new_events(&mut self)

Called by the platform at the start of each event-loop iteration, before dispatching any events. Pairs with about_to_wait to bracket all event processing within a reactive batch.

Source

fn about_to_wait(&mut self) -> Option<Duration>

Called by the platform after all events in the iteration have been dispatched, before idling. Must close the reactive batch opened by new_events; returning Some(duration) sets the idle timeout. Pairs with new_events — the platform guarantees these are called in matching pairs for each iteration.

Source

fn take_exit_request(&mut self) -> bool

Whether the handler asked to close this window (e.g. a custom title-bar close button pushed crate::WindowCommand::Close). The platform polls this after each dispatch; true exits the window’s run loop. Implementations clear the request when returning true. Defaults to false.

Source

fn last_frame_rgba(&self) -> Option<Vec<u8>>

The most recently rendered frame as premultiplied RGBA8888, if this handler renders to an offscreen target. Windowed handlers present to the screen and return None; an offscreen backend (e.g. Platform running headless) uses this to capture pixels after driving frames. Defaults to None.

Source

fn interactive_rects(&self) -> Vec<Rect>

The laid-out rects of this handler’s pointer targets, in logical surface coordinates.

A backend that carves a surface’s input region from its content — a click-through overlay that must still take input over its own cards — needs these, and cannot read them itself: they live in the handler’s per-surface world, which is only active inside the handler’s own calls. Read from outside, the ambient world answers instead, and it is always empty — which a backend then applies as “this surface takes no input anywhere”.

Defaults to empty, which is the honest answer for a handler that owns no surface world.

Trait Implementations§

Source§

impl<W> EventHandler<W> for Box<dyn EventHandler<W>>
where W: Window,

Source§

fn on_resume(&mut self, window: &W) -> bool

Source§

fn on_event(&mut self, event: Event, window: &W)

Source§

fn on_redraw(&mut self, window: &W)

Source§

fn on_suspend(&mut self)

Source§

fn accessibility(&self) -> Vec<AccessNode>

The window’s accessibility tree as it stands, for the platform to hand to whatever is listening. Read more
Source§

fn on_accessibility_action(&mut self, id: u64, activate: bool)

A screen reader asked to move to a control, or to activate it — id being the one the handler put in AccessNode::id. Read more
Source§

fn remount(&mut self, window: &W)

Rebuilds this handler’s UI from its app, on the surface it is already running on. Read more
Source§

fn new_events(&mut self)

Called by the platform at the start of each event-loop iteration, before dispatching any events. Pairs with about_to_wait to bracket all event processing within a reactive batch.
Source§

fn about_to_wait(&mut self) -> Option<Duration>

Called by the platform after all events in the iteration have been dispatched, before idling. Must close the reactive batch opened by new_events; returning Some(duration) sets the idle timeout. Pairs with new_events — the platform guarantees these are called in matching pairs for each iteration.
Source§

fn take_exit_request(&mut self) -> bool

Whether the handler asked to close this window (e.g. a custom title-bar close button pushed crate::WindowCommand::Close). The platform polls this after each dispatch; true exits the window’s run loop. Implementations clear the request when returning true. Defaults to false.
Source§

fn last_frame_rgba(&self) -> Option<Vec<u8>>

The most recently rendered frame as premultiplied RGBA8888, if this handler renders to an offscreen target. Windowed handlers present to the screen and return None; an offscreen backend (e.g. Platform running headless) uses this to capture pixels after driving frames. Defaults to None.
Source§

fn interactive_rects(&self) -> Vec<Rect>

The laid-out rects of this handler’s pointer targets, in logical surface coordinates. Read more

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<W> EventHandler<W> for Box<dyn EventHandler<W>>
where W: Window,

Source§

fn on_resume(&mut self, window: &W) -> bool

Source§

fn on_event(&mut self, event: Event, window: &W)

Source§

fn on_redraw(&mut self, window: &W)

Source§

fn on_suspend(&mut self)

Source§

fn accessibility(&self) -> Vec<AccessNode>

Source§

fn on_accessibility_action(&mut self, id: u64, activate: bool)

Source§

fn remount(&mut self, window: &W)

Source§

fn new_events(&mut self)

Source§

fn about_to_wait(&mut self) -> Option<Duration>

Source§

fn take_exit_request(&mut self) -> bool

Source§

fn last_frame_rgba(&self) -> Option<Vec<u8>>

Source§

fn interactive_rects(&self) -> Vec<Rect>

Implementors§