From ba56a561b254c9a5f3d23cb54d23dc311759ab4c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 21 Nov 2019 18:00:27 +0100 Subject: Implement `iced::Sandbox` trait for simple apps --- src/sandbox.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/sandbox.rs (limited to 'src/sandbox.rs') diff --git a/src/sandbox.rs b/src/sandbox.rs new file mode 100644 index 00000000..8ff374f7 --- /dev/null +++ b/src/sandbox.rs @@ -0,0 +1,45 @@ +use crate::{Application, Command, Element}; + +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(&mut self) -> Element; + + fn run() + where + Self: 'static + Sized, + { + ::run() + } +} + +impl Application for T +where + T: Sandbox, +{ + type Message = T::Message; + + fn new() -> (Self, Command) { + (T::new(), Command::none()) + } + + fn title(&self) -> String { + T::title(self) + } + + fn update(&mut self, message: T::Message) -> Command { + T::update(self, message); + + Command::none() + } + + fn view(&mut self) -> Element { + T::view(self) + } +} -- cgit