summaryrefslogtreecommitdiffstats
path: root/src/hbox.rs
blob: 538edf5458f3ec7c3f2f07a9f47c256dc444a60d (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
60
61
62
63
64
65
66
67
68
69
70
71
72
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>>,
               dimensions: (u16, u16),
               position: (u16, u16),
               main: usize) -> HBox {
        HBox {
            dimensions: dimensions,
            position: position,
            children: widgets,
            main: main
        }
    }
}

impl Widget for HBox {
    fn render(&self) -> Vec<String> {
        // HBox doesnt' draw anything itself
        vec![]
    }

    fn render_header(&self) -> String {
        self.children[self.active].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 set_dimensions(&mut self, size: (u16, u16)) {
        self.dimensions = size;
    }
    fn set_position(&mut self, position: (u16, u16)) {
        self.position = position;
    }


    fn on_event(&mut self, event: Event) {
        self.children[self.active].on_event(event);
    }
}