1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
pub mod base;
pub use base::*;
pub mod widget;
pub use widget::*;
pub mod stateful;
pub use stateful::*;
pub mod banner;
pub use banner::*;
// pub mod stateless;
// pub use stateless::*;
use enum_dispatch::enum_dispatch;
use tui::Frame;
use super::{Bounds, DrawContext, Event, LayoutNode, Size, StateContext, Status};
/// A component displays information and can be interacted with.
#[allow(unused_variables)]
#[enum_dispatch]
pub trait TmpComponent<Message> {
/// Draws the component.
fn draw<Backend>(
&mut self, state_ctx: &mut StateContext<'_>, draw_ctx: &DrawContext<'_>,
frame: &mut Frame<'_, Backend>,
) where
Backend: tui::backend::Backend;
/// How a component should react to an [`Event`](super::Event).
///
/// Defaults to just ignoring the event.
fn on_event(
&mut self, state_ctx: &mut StateContext<'_>, draw_ctx: &DrawContext<'_>, event: Event,
messages: &mut Vec<Message>,
) -> Status {
Status::Ignored
}
/// How a component should size itself and its children, given some [`Bounds`].
///
/// Defaults to returning a [`Size`] that fills up the bounds given.
fn layout(&self, bounds: Bounds, node: &mut LayoutNode) -> Size {
Size {
width: bounds.max_width,
height: bounds.max_height,
}
}
}
|