pub trait Component<CID, CA, CS, CM>: MockComponent + MockProps{
// Provided methods
fn on_event(
&mut self,
_event: EzEvent<CID, CM>,
state: &mut State<CS>,
) -> Vec<EzEvent<CID, CM>> { ... }
fn init(&mut self, state: &mut State<CS>) -> Vec<EzEvent<CID, CM>> { ... }
fn tick(&mut self, state: &mut State<CS>) -> Vec<EzEvent<CID, CM>> { ... }
fn focusable(&self) -> bool { ... }
fn legend(&self) -> Option<Legend> { ... }
fn capture_focus(&mut self, forward: bool) -> bool { ... }
}Expand description
A type to describe a concrete component. In your app, every component should have it’s own struct implementing this trait.
Provided Methods§
Sourcefn on_event(
&mut self,
_event: EzEvent<CID, CM>,
state: &mut State<CS>,
) -> Vec<EzEvent<CID, CM>>
fn on_event( &mut self, _event: EzEvent<CID, CM>, state: &mut State<CS>, ) -> Vec<EzEvent<CID, CM>>
Method to implement to handle events. The component will receive any event if it is focused; but only events it is subscribed to otherwise.
Sourcefn init(&mut self, state: &mut State<CS>) -> Vec<EzEvent<CID, CM>>
fn init(&mut self, state: &mut State<CS>) -> Vec<EzEvent<CID, CM>>
Method called on first tick only.
Sourcefn tick(&mut self, state: &mut State<CS>) -> Vec<EzEvent<CID, CM>>
fn tick(&mut self, state: &mut State<CS>) -> Vec<EzEvent<CID, CM>>
Method called on every tick. You should implement it only if you need to save a reference to the state or if your business logic needs to execute some code on a regular basis.
Sourcefn capture_focus(&mut self, forward: bool) -> bool
fn capture_focus(&mut self, forward: bool) -> bool
Returns true if the focus is handled internally. Let’s say this component has two inner focusable area:
- on first call to
capture_focuswithforward = true, it’s your responsibility to focus the first area and return false. - on second call same; focus the second area and return false.
- on third call, unfocus all area and return false so the view can cycle to the next component.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".