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
60
61
62
63
64
65
66
67
68
|
use tui::{backend::Backend, layout::Rect, Frame};
use crate::tuice::{Bounds, Component, DrawContext, Event, Length, Size, Status, LayoutNode};
pub struct Container<'a, Message, B>
where
B: Backend,
{
width: Length,
height: Length,
child: Box<dyn Component<Message, B> + 'a>,
}
impl<'a, Message, B> Container<'a, Message, B>
where
B: Backend,
{
pub fn new(child: Box<dyn Component<Message, B> + 'a>) -> Self {
Self {
width: Length::Flex,
height: Length::Flex,
child,
}
}
}
impl<'a, Message, B> Component<Message, B> for Container<'a, Message, B>
where
B: Backend,
{
fn draw(&mut self, area: Rect, _context: &DrawContext, _frame: &mut Frame<'_, B>) {
todo!()
}
fn on_event(&mut self, _area: Rect, _event: Event, _messages: &mut Vec<Message>) -> Status {
todo!()
}
fn layout(&self, bounds: Bounds, node: &mut LayoutNode) -> Size {
let width = match self.width {
Length::Flex => {
todo!()
}
Length::FlexRatio(ratio) => {
todo!()
}
Length::Fixed(length) => length.clamp(bounds.min_width, bounds.max_width),
Length::Child => {
todo!()
}
};
let height = match self.height {
Length::Flex => {
todo!()
}
Length::FlexRatio(ratio) => {
todo!()
}
Length::Fixed(length) => length.clamp(bounds.min_height, bounds.max_height),
Length::Child => {
todo!()
}
};
Size { height, width }
}
}
|