mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-15 13:43:08 +00:00
44 lines
995 B
Rust
44 lines
995 B
Rust
|
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;
|
||
|
|
||
|
fn wrap_draw(&self, printer: &Printer) {
|
||
|
self.get_view().draw(printer);
|
||
|
}
|
||
|
|
||
|
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 {
|
||
|
fn draw(&self, printer: &Printer) {
|
||
|
self.wrap_draw(printer);
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
}
|