2020-04-19 21:55:23 +02:00
|
|
|
use crate::canvas::{Event, Geometry, Size};
|
|
|
|
|
|
2020-04-28 06:24:12 +02:00
|
|
|
pub trait Program<Message> {
|
2020-04-28 03:46:03 +02:00
|
|
|
fn update(&mut self, _event: Event, _bounds: Size) -> Option<Message> {
|
|
|
|
|
None
|
|
|
|
|
}
|
2020-04-19 21:55:23 +02:00
|
|
|
|
|
|
|
|
fn draw(&self, bounds: Size) -> Vec<Geometry>;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-28 06:24:12 +02:00
|
|
|
impl<T, Message> Program<Message> for &mut T
|
2020-04-19 21:55:23 +02:00
|
|
|
where
|
2020-04-28 06:24:12 +02:00
|
|
|
T: Program<Message>,
|
2020-04-19 21:55:23 +02:00
|
|
|
{
|
2020-04-28 03:46:03 +02:00
|
|
|
fn update(&mut self, event: Event, bounds: Size) -> Option<Message> {
|
|
|
|
|
T::update(self, event, bounds)
|
2020-04-19 21:55:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn draw(&self, bounds: Size) -> Vec<Geometry> {
|
|
|
|
|
T::draw(self, bounds)
|
|
|
|
|
}
|
|
|
|
|
}
|