summaryrefslogtreecommitdiffstats
path: root/src/tuice/component.rs
blob: d479a188c7d832252ab8c51c9ab473b7e1109b5c (plain)
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
pub mod base;
pub use base::*;

pub mod widget;
pub use widget::*;

pub mod properties;
pub use properties::*;

use tui::{layout::Rect, Frame};

use super::{Bounds, DrawContext, Event, LayoutNode, Size, Status};

/// A component displays information and can be interacted with.
#[allow(unused_variables)]
pub trait Component<Message, Backend>
where
    Backend: tui::backend::Backend,
{
    /// Draws the component.
    fn draw(&mut self, context: DrawContext<'_>, frame: &mut Frame<'_, Backend>);

    /// How a component should react to an [`Event`].
    ///
    /// Defaults to just ignoring the event.
    fn on_event(&mut self, area: Rect, 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,
        }
    }
}