use crate::widget::pure::canvas::event::{self, Event};
use crate::widget::pure::canvas::mouse;
use crate::widget::pure::canvas::{Cursor, Geometry};
use crate::Rectangle;
pub trait Program<Message> {
type State: Default + 'static;
fn update(
&self,
_state: &mut Self::State,
_event: Event,
_bounds: Rectangle,
_cursor: Cursor,
) -> (event::Status, Option<Message>) {
(event::Status::Ignored, None)
}
fn draw(
&self,
state: &Self::State,
bounds: Rectangle,
cursor: Cursor,
) -> Vec<Geometry>;
fn mouse_interaction(
&self,
_state: &Self::State,
_bounds: Rectangle,
_cursor: Cursor,
) -> mouse::Interaction {
mouse::Interaction::default()
}
}
impl<Message, T> Program<Message> for &T
where
T: Program<Message>,
{
type State = T::State;
fn update(
&self,
state: &mut Self::State,
event: Event,
bounds: Rectangle,
cursor: Cursor,
) -> (event::Status, Option<Message>) {
T::update(self, state, event, bounds, cursor)
}
fn draw(
&self,
state: &Self::State,
bounds: Rectangle,
cursor: Cursor,
) -> Vec<Geometry> {
T::draw(self, state, bounds, cursor)
}
fn mouse_interaction(
&self,
state: &Self::State,
bounds: Rectangle,
cursor: Cursor,
) -> mouse::Interaction {
T::mouse_interaction(self, state, bounds, cursor)
}
}