summaryrefslogtreecommitdiffstats
path: root/src/tuice/component/base/row.rs
blob: 93c5b317ba3d918f9775552371a953bff061bf1d (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use tui::{backend::Backend, layout::Rect, Frame};

use crate::tuice::{Bounds, Event, FlexElement, LayoutNode, Size, Status, TmpComponent};

#[derive(Default)]
pub struct Row<'a, Message> {
    children: Vec<FlexElement<'a, Message>>,
}

impl<'a, Message> Row<'a, Message> {
    /// Creates a new [`Row`] with the given children.
    pub fn with_children<C>(children: Vec<C>) -> Self
    where
        C: Into<FlexElement<'a, Message>>,
    {
        Self {
            children: children.into_iter().map(Into::into).collect(),
        }
    }

    pub fn with_child(mut self) -> Self {
        self
    }

    pub fn with_flex_child(mut self) -> Self {
        self
    }
}

impl<'a, Message> TmpComponent<Message> for Row<'a, Message> {
    fn draw<B>(&mut self, area: Rect, frame: &mut Frame<'_, B>)
    where
        B: Backend,
    {
        self.children.iter_mut().for_each(|child| {
            child.draw(area, frame);
        })
    }

    fn on_event(&mut self, _area: Rect, _event: Event, _messages: &mut Vec<Message>) -> Status {
        Status::Ignored
    }

    fn layout(&self, bounds: Bounds, node: &mut LayoutNode) -> Size {
        let mut remaining_bounds = bounds;

        let child_nodes: Vec<LayoutNode> = self
            .children
            .iter()
            .map(|child| {
                let mut child_node = LayoutNode::default();
                let size = child.layout(remaining_bounds, &mut child_node);
                child_node
            })
            .collect();

        todo!()
    }
}