pub trait HandleEvent<Event, Qualifier, Return>where
Return: ConsumedEvent,{
// Required method
fn handle(&mut self, event: &Event, qualifier: Qualifier) -> Return;
}Expand description
A very broad trait for an event handler.
Ratatui widgets have two separate structs, one that implements Widget/StatefulWidget and the associated State. As the StatefulWidget has a lifetime and is not meant to be kept, HandleEvent should be implemented for the state struct. It can then modify some state and the tui can be rendered anew with that changed state.
HandleEvent is not limited to State structs of course, any Type that wants to interact with events can implement it.
-
Event - The actual event type.
-
Qualifier - The qualifier allows creating more than one event-handler for a widget.
This can be used as a variant of type-state, where the type given selects the widget’s behaviour, or to give some external context to the widget, or to write your own key-bindings for a widget.
-
R - Result of event-handling. This can give information to the application what changed due to handling the event. This can be very specific for each widget, but there is one general Outcome that describes a minimal set of results.
There should be one value that indicates ‘I don’t know this event’. This is expressed with the ConsumedEvent trait.
Required Methods§
Implementations on Foreign Types§
Source§impl<E, Q> HandleEvent<E, Q, Outcome> for ()
Catch all event-handler for the null state ().
impl<E, Q> HandleEvent<E, Q, Outcome> for ()
Catch all event-handler for the null state ().