remy_widgets/widgets/
core.rs

1use ratatui::widgets::{StatefulWidgetRef, WidgetRef};
2
3pub trait RemyWidget: WidgetRef {
4}
5
6pub trait RemyWidgetCommandConverter<T> {
7    type Event;
8
9    fn convert(event: crate::events::Event, state: &T) -> Option<Self::Event>;
10}
11
12
13pub trait RemyWidgetState: Sized {
14    type Command;
15    type EventOutput;
16    
17    fn handle_events<T>(&mut self, event: crate::events::Event) -> Self::EventOutput
18    where T: RemyWidgetCommandConverter<Self, Event=Self::Command>
19    {
20        self.handle_native_event(T::convert(event, self))
21    }
22    
23    fn handle_native_event(&mut self, event: Option<Self::Command>) -> Self::EventOutput;
24}
25
26pub trait StatefulRemyWidget: StatefulWidgetRef<State=Self::Input> {
27    type Input: RemyWidgetState;
28}