15 releases (5 breaking)
new 0.14.1 | May 30, 2024 |
---|---|
0.14.0 | May 30, 2024 |
0.13.3 | May 30, 2024 |
0.12.5 | May 29, 2024 |
0.9.0 | May 8, 2024 |
#572 in Command-line interface
1,143 downloads per month
Used in 5 crates
(4 directly)
27KB
429 lines
Rat-Event
Rationale
This crate defines a general event-handling trait, that can be used to create ratatui widgets.
The main idea here is not to try to unify the different event sources.
Instead, provide a trait that can be implemented once per event-type. And as there seem to be widely diverging opinions on what the right key-bindings should be, we add a marker type to allow for more than one key-binding.
If the widget is designed in a way, that each key binding only needs to call a function or two, the code duplication is negligible.
This accomplishes:
- Widget author can support different event types.
- Widget author can supply several key bindings.
- Application author can define ves own key bindings, and as the widget is designed this way it's possible to do this.
- As there is a trait for this, widgets can be composed generically.
For examples see rat-input
Composition
To allow a minimal level of composition of different return types, there is the trait ConsumedEvent. This allows for early returns, even if the details of the return type are not known.
Utilities
ct_event!
A neat little thing, that generates pattern matches for mouse events. Has a much terser syntax than composing struct patterns.
selectors
The functions row_at_clicked
, column_at_clicked
, row_at_drag
and
column_at_drag
allow easier identification which of a slice of Rect
is actually meant.
Outcome
Reference result type for event-handling. This is just a minimal baseline. Feel free to define your own; maybe add a conversion to Outcome.
Mouseflags
Identifying double-clicks and mouse-drag is not trivial. This struct helps, add it to your widget state.
Dependencies
~6–12MB
~119K SLoC