summaryrefslogtreecommitdiffstats
path: root/examples/clock
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-04-30 05:37:44 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-04-30 05:37:44 +0200
commite2076612cb98d04a8a48add14d0068c2974d5653 (patch)
tree83ee2bcd2a0ef675a1eb0a7bc9313884055aee67 /examples/clock
parentbb9ccc4f62ceea08dc1ef0c6c4d3d219897e44a1 (diff)
downloadiced-e2076612cb98d04a8a48add14d0068c2974d5653.tar.gz
iced-e2076612cb98d04a8a48add14d0068c2974d5653.tar.bz2
iced-e2076612cb98d04a8a48add14d0068c2974d5653.zip
Implement `time::every` in `iced_futures`
Diffstat (limited to 'examples/clock')
-rw-r--r--examples/clock/Cargo.toml4
-rw-r--r--examples/clock/src/main.rs46
2 files changed, 6 insertions, 44 deletions
diff --git a/examples/clock/Cargo.toml b/examples/clock/Cargo.toml
index ab771405..c6e32379 100644
--- a/examples/clock/Cargo.toml
+++ b/examples/clock/Cargo.toml
@@ -6,7 +6,5 @@ edition = "2018"
publish = false
[dependencies]
-iced = { path = "../..", features = ["canvas", "async-std", "debug"] }
-iced_native = { path = "../../native" }
+iced = { path = "../..", features = ["canvas", "tokio", "debug"] }
chrono = "0.4"
-async-std = { version = "1.0", features = ["unstable"] }
diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs
index e6b17d8a..9c583c78 100644
--- a/examples/clock/src/main.rs
+++ b/examples/clock/src/main.rs
@@ -1,7 +1,7 @@
use iced::{
canvas::{self, Cache, Canvas, Cursor, Geometry, LineCap, Path, Stroke},
- executor, Application, Color, Command, Container, Element, Length, Point,
- Rectangle, Settings, Subscription, Vector,
+ executor, time, Application, Color, Command, Container, Element, Length,
+ Point, Rectangle, Settings, Subscription, Vector,
};
pub fn main() {
@@ -43,7 +43,7 @@ impl Application for Clock {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::Tick(local_time) => {
- let now = local_time.into();
+ let now = local_time;
if now != self.now {
self.now = now;
@@ -56,7 +56,8 @@ impl Application for Clock {
}
fn subscription(&self) -> Subscription<Message> {
- time::every(std::time::Duration::from_millis(500)).map(Message::Tick)
+ time::every(std::time::Duration::from_millis(500))
+ .map(|_| Message::Tick(chrono::Local::now()))
}
fn view(&mut self) -> Element<Message> {
@@ -130,40 +131,3 @@ fn hand_rotation(n: u32, total: u32) -> f32 {
2.0 * std::f32::consts::PI * turns
}
-
-mod time {
- use iced::futures;
-
- pub fn every(
- duration: std::time::Duration,
- ) -> iced::Subscription<chrono::DateTime<chrono::Local>> {
- iced::Subscription::from_recipe(Every(duration))
- }
-
- struct Every(std::time::Duration);
-
- impl<H, I> iced_native::subscription::Recipe<H, I> for Every
- where
- H: std::hash::Hasher,
- {
- type Output = chrono::DateTime<chrono::Local>;
-
- fn hash(&self, state: &mut H) {
- use std::hash::Hash;
-
- std::any::TypeId::of::<Self>().hash(state);
- self.0.hash(state);
- }
-
- fn stream(
- self: Box<Self>,
- _input: futures::stream::BoxStream<'static, I>,
- ) -> futures::stream::BoxStream<'static, Self::Output> {
- use futures::stream::StreamExt;
-
- async_std::stream::interval(self.0)
- .map(|_| chrono::Local::now())
- .boxed()
- }
- }
-}