ez_tui/components/concrete/
render_indicator.rs1use crate::types::palette::EzPalette;
2use crate::{Component, EzArgs, EzCptIds, EzEvent, EzMsg, EzState, IndicatorMock, State};
3use eztui_derive::MockComponent;
4use ratatui::style::palette::tailwind::SLATE;
5use std::fmt::Debug;
6use std::marker::PhantomData;
7
8#[derive(MockComponent, Debug)]
10pub struct RenderIndicatorCpt<CA, CM>
11where
12 CA: EzArgs,
13 CM: EzMsg,
14{
15 component: IndicatorMock,
16 phantom_args: PhantomData<CA>,
17 phantom_msg: PhantomData<CM>,
18}
19
20impl<CA, CM> Default for RenderIndicatorCpt<CA, CM>
21where
22 CA: EzArgs,
23 CM: EzMsg,
24{
25 fn default() -> Self {
26 Self {
27 component: IndicatorMock::with_palette("FPS".into(), &(SLATE.into())),
28 phantom_args: PhantomData,
29 phantom_msg: PhantomData,
30 }
31 }
32}
33impl<CA, CM> RenderIndicatorCpt<CA, CM>
34where
35 CA: EzArgs,
36 CM: EzMsg,
37{
38 #[must_use]
40 pub fn with_palette(palette: &EzPalette) -> Self {
41 Self {
42 component: IndicatorMock::with_palette("FPS".into(), palette),
43 phantom_args: PhantomData,
44 phantom_msg: PhantomData,
45 }
46 }
47 #[must_use]
49 pub fn with_palettes(palette_a: &EzPalette, palette_b: &EzPalette) -> Self {
50 Self {
51 component: IndicatorMock::with_palettes("FPS".into(), palette_a, palette_b),
52 phantom_args: PhantomData,
53 phantom_msg: PhantomData,
54 }
55 }
56}
57impl<CID, CA, CS, CM> Component<CID, CA, CS, CM> for RenderIndicatorCpt<CA, CM>
58where
59 CID: EzCptIds,
60 CA: EzArgs,
61 CS: EzState,
62 CM: EzMsg,
63{
64 fn on_event(&mut self, ev: EzEvent<CID, CM>, _: &mut State<CS>) -> Vec<EzEvent<CID, CM>> {
65 if EzEvent::Render == ev {
66 self.component.cycle();
67 }
68 vec![]
69 }
70}