use crate::canvas::event::{self, Event};
use crate::canvas::{Cursor, Geometry};
use iced_native::{mouse, Rectangle};
pub trait Program<Message> {
fn update(
&mut self,
_event: Event,
_bounds: Rectangle,
_cursor: Cursor,
) -> (event::Status, Option<Message>) {
(event::Status::Ignored, None)
}
fn draw(&self, bounds: Rectangle, cursor: Cursor) -> Vec<Geometry>;
fn mouse_interaction(
&self,
_bounds: Rectangle,
_cursor: Cursor,
) -> mouse::Interaction {
mouse::Interaction::default()
}
}
impl<T, Message> Program<Message> for &mut T
where
T: Program<Message>,
{
fn update(
&mut self,
event: Event,
bounds: Rectangle,
cursor: Cursor,
) -> (event::Status, Option<Message>) {
T::update(self, event, bounds, cursor)
}
fn draw(&self, bounds: Rectangle, cursor: Cursor) -> Vec<Geometry> {
T::draw(self, bounds, cursor)
}
fn mouse_interaction(
&self,
bounds: Rectangle,
cursor: Cursor,
) -> mouse::Interaction {
T::mouse_interaction(self, bounds, cursor)
}
}