2015-05-19 02:41:35 +00:00
|
|
|
use vec::Vec2;
|
|
|
|
use view::{View,SizeRequest};
|
|
|
|
use printer::Printer;
|
|
|
|
use event::EventResult;
|
|
|
|
|
|
|
|
pub trait ViewWrapper {
|
|
|
|
fn get_view(&self) -> &View;
|
|
|
|
fn get_view_mut(&mut self) -> &mut View;
|
|
|
|
|
2015-05-19 22:54:11 +00:00
|
|
|
fn wrap_draw(&self, printer: &Printer, focused: bool) {
|
|
|
|
self.get_view().draw(printer, focused);
|
2015-05-19 02:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn wrap_get_min_size(&self, req: SizeRequest) -> Vec2 {
|
|
|
|
self.get_view().get_min_size(req)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn wrap_on_key_event(&mut self, ch: i32) -> EventResult {
|
|
|
|
self.get_view_mut().on_key_event(ch)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn wrap_layout(&mut self, size: Vec2) {
|
|
|
|
self.get_view_mut().layout(size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl <T: ViewWrapper> View for T {
|
2015-05-19 22:54:11 +00:00
|
|
|
fn draw(&self, printer: &Printer, focused: bool) {
|
|
|
|
self.wrap_draw(printer, focused);
|
2015-05-19 02:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn get_min_size(&self, req: SizeRequest) -> Vec2 {
|
|
|
|
self.wrap_get_min_size(req)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn on_key_event(&mut self, ch: i32) -> EventResult {
|
|
|
|
self.wrap_on_key_event(ch)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn layout(&mut self, size: Vec2) {
|
|
|
|
self.wrap_layout(size);
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 22:54:11 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! wrap_impl {
|
2015-05-19 23:40:32 +00:00
|
|
|
(self.$v:ident) => {
|
|
|
|
|
|
|
|
fn get_view(&self) -> &View {
|
|
|
|
&self.$v
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_view_mut(&mut self) -> &mut View {
|
|
|
|
&mut self.$v
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! wrap_impl_box {
|
|
|
|
(self.$v:ident) => {
|
2015-05-19 22:54:11 +00:00
|
|
|
|
|
|
|
fn get_view(&self) -> &View {
|
|
|
|
&*self.$v
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_view_mut(&mut self) -> &mut View {
|
|
|
|
&mut *self.$v
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|