pub trait EventHandler {
type Context;
type Event;
// Required methods
fn handle_event(event: &Self::Event, ctx: &mut Self::Context);
fn key_event_mappings(ctx: &Self::Context) -> Vec<(KeyEvent, Self::Event)>;
// Provided methods
fn pass_through_key_events(_: &KeyEvent, _: &mut Self::Context) { ... }
fn pass_through_mouse_events(_: &MouseEvent, _: &mut Self::Context) { ... }
fn handle_key_event<T: Into<KeyEvent>>(ctx: &mut Self::Context, event: T) { ... }
fn handle_mouse_event<T: Into<MouseEvent>>(
ctx: &mut Self::Context,
event: T,
) { ... }
fn format_event_mappings_as_strings(
ctx: &Self::Context,
) -> Vec<(String, String)>
where Self::Event: Display { ... }
}
Expand description
A trait for handling events with associated contexts.
Required Associated Types§
Required Methods§
Sourcefn handle_event(event: &Self::Event, ctx: &mut Self::Context)
fn handle_event(event: &Self::Event, ctx: &mut Self::Context)
Handles a specific app event with the given context.
§Arguments
event
- The event to handle.ctx
- The context in which the event is handled.
Provided Methods§
Sourcefn pass_through_key_events(_: &KeyEvent, _: &mut Self::Context)
fn pass_through_key_events(_: &KeyEvent, _: &mut Self::Context)
Passes through key events without any specific handling.
This method is optional and can be used to simply pass through character events without registering any specific handling logic.
Sourcefn pass_through_mouse_events(_: &MouseEvent, _: &mut Self::Context)
fn pass_through_mouse_events(_: &MouseEvent, _: &mut Self::Context)
Passes through key events without any specific handling.
This method is optional and can be used to simply pass through character events without registering any specific handling logic.
Sourcefn handle_key_event<T: Into<KeyEvent>>(ctx: &mut Self::Context, event: T)
fn handle_key_event<T: Into<KeyEvent>>(ctx: &mut Self::Context, event: T)
Handles a key event by dispatching it to the corresponding application event handler.
§Arguments
ctx
- The context in which the key event is handled.event
- The key event to handle.
Sourcefn handle_mouse_event<T: Into<MouseEvent>>(ctx: &mut Self::Context, event: T)
fn handle_mouse_event<T: Into<MouseEvent>>(ctx: &mut Self::Context, event: T)
Handles a mouse event by dispatching it to the corresponding application event handler.
§Arguments
ctx
- The context in which the key event is handled.event
- The mouse event to handle.
Sourcefn format_event_mappings_as_strings(
ctx: &Self::Context,
) -> Vec<(String, String)>
fn format_event_mappings_as_strings( ctx: &Self::Context, ) -> Vec<(String, String)>
Converts the key event mappings into a vector of string representations, i.e. (app event as string, key event as string).
This method formats each key event and corresponding app event as strings and returns them as a vector of tuples. If multiple key events map to the same app event, they are merged into a single entry where the keys are concatenated together.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.