Crates.io | rat-event |
lib.rs | rat-event |
version | 0.26.1 |
source | src |
created_at | 2024-05-08 17:46:50.85988 |
updated_at | 2024-12-12 16:47:23.272088 |
description | ratatui event handler trait for widgets |
homepage | |
repository | https://github.com/thscharler/rat-event |
max_upload_size | |
id | 1234002 |
size | 62,191 |
This crate is a part of rat-salsa.
This crate defines the trait HandleEvent to help with composability of event-handling for ratatui widgets.
Objectives are
pub trait HandleEvent<Event, Qualifier, Return>
where
Return: ConsumedEvent
{
fn handle(
&mut self,
event: &Event,
qualifier: Qualifier
) -> Return;
}
Can be anything.
There are predefined qualifiers
Regular - Do what is considered 'normal' behaviour. Can vary depending on the actual state of the widget (e.g. focus)
MouseOnly - Splitting off mouse interaction helps when you only want to redefine the key bindings. And handling mouse events is usually more involved/complicated/specific.
DoubleClick - Double clicks are a bit special for widgets, often it requires a distinct return type and it's not as generally needed as other mouse behaviour.
Popup, Dialog - Specialized event-handlers, but they tend to popup again and again.
The return type can be anything at all.
To be useful it is required to implement ConsumedEvent to indicate if the event has been handled by the widget and further event-handling can stop.
To set a baseline for the return type this crate defines the enum Outcome which can indicate if a render is necessary or not.
For interop all return types in rat-salsa are convertible to/from Outcome.