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
|
use termion::event::{Event};
use crate::widget::Widget;
// pub struct Child<T> {
// widget: T,
// position: (u16, u16),
// size: (u16, u16),
// active: bool
// }
pub struct HBox {
dimensions: (u16, u16),
position: (u16, u16),
children: Vec<Box<Widget>>,
main: usize
}
impl HBox {
pub fn new(widgets: Vec<Box<Widget>>) -> HBox {
HBox {
dimensions: (100, 100),
position: (1, 1),
children: widgets,
main: 0
}
}
}
impl Widget for HBox {
fn render(&self) -> Vec<String> {
// HBox doesnt' draw anything itself
vec![]
}
fn render_header(&self) -> String {
self.children[self.main].render_header()
}
fn refresh(&mut self) {
for child in &mut self.children {
child.refresh();
}
}
fn get_drawlist(&mut self) -> String {
self.children.iter_mut().map(|child| {
child.get_drawlist()
}).collect()
}
fn get_dimensions(&self) -> (u16, u16) {
self.dimensions
}
fn get_position(&self) -> (u16, u16) {
self.position
}
fn on_event(&mut self, event: Event) {
self.children[self.main].on_event(event);
}
}
|