use crate::pure;
use crate::{Color, Command, Error, Settings, Subscription};
pub trait Sandbox {
type Message: std::fmt::Debug + Send;
fn new() -> Self;
fn title(&self) -> String;
fn update(&mut self, message: Self::Message);
fn view(&self) -> pure::Element<'_, Self::Message>;
fn background_color(&self) -> Color {
Color::WHITE
}
fn scale_factor(&self) -> f64 {
1.0
}
fn should_exit(&self) -> bool {
false
}
fn run(settings: Settings<()>) -> Result<(), Error>
where
Self: 'static + Sized,
{
<Self as pure::Application>::run(settings)
}
}
impl<T> pure::Application for T
where
T: Sandbox,
{
type Executor = iced_futures::backend::null::Executor;
type Flags = ();
type Message = T::Message;
fn new(_flags: ()) -> (Self, Command<T::Message>) {
(T::new(), Command::none())
}
fn title(&self) -> String {
T::title(self)
}
fn update(&mut self, message: T::Message) -> Command<T::Message> {
T::update(self, message);
Command::none()
}
fn subscription(&self) -> Subscription<T::Message> {
Subscription::none()
}
fn view(&self) -> pure::Element<'_, T::Message> {
T::view(self)
}
fn background_color(&self) -> Color {
T::background_color(self)
}
fn scale_factor(&self) -> f64 {
T::scale_factor(self)
}
fn should_exit(&self) -> bool {
T::should_exit(self)
}
}