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
use Printer;
use std::cell::Cell;
use vec::Vec2;
use view::{View, ViewWrapper};
use views::IdView;
pub struct TrackedView<T: View> {
pub view: T,
offset: Cell<Vec2>,
}
impl<T: View> TrackedView<T> {
pub fn offset(&self) -> Vec2 {
self.offset.get()
}
}
impl<T: View> TrackedView<T> {
pub fn new(view: T) -> Self {
TrackedView {
view: view,
offset: Cell::new(Vec2::zero()),
}
}
pub fn with_id(self, id: &str) -> IdView<Self> {
IdView::new(id, self)
}
}
impl<T: View> ViewWrapper for TrackedView<T> {
wrap_impl!(self.view: T);
fn wrap_draw(&self, printer: &Printer) {
self.offset.set(printer.offset);
self.view.draw(printer);
}
}