summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/clock/Cargo.toml4
-rw-r--r--examples/clock/src/main.rs46
-rw-r--r--examples/game_of_life/Cargo.toml4
-rw-r--r--examples/game_of_life/src/main.rs3
-rw-r--r--examples/game_of_life/src/time.rs34
-rw-r--r--examples/solar_system/Cargo.toml4
-rw-r--r--examples/solar_system/src/main.rs40
-rw-r--r--examples/stopwatch/Cargo.toml5
-rw-r--r--examples/stopwatch/src/main.rs44
9 files changed, 16 insertions, 168 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()
- }
- }
-}
diff --git a/examples/game_of_life/Cargo.toml b/examples/game_of_life/Cargo.toml
index 8855b3e8..413493ae 100644
--- a/examples/game_of_life/Cargo.toml
+++ b/examples/game_of_life/Cargo.toml
@@ -6,7 +6,5 @@ edition = "2018"
publish = false
[dependencies]
-iced = { path = "../..", features = ["async-std", "canvas", "debug"] }
-iced_native = { path = "../../native" }
-async-std = { version = "1.0", features = ["unstable"] }
+iced = { path = "../..", features = ["canvas", "tokio"] }
itertools = "0.9"
diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs
index 9fb4c3e7..5a58a8cb 100644
--- a/examples/game_of_life/src/main.rs
+++ b/examples/game_of_life/src/main.rs
@@ -1,14 +1,13 @@
//! This example showcases an interactive version of the Game of Life, invented
//! by John Conway. It leverages a `Canvas` together with other widgets.
mod style;
-mod time;
use grid::Grid;
use iced::{
button::{self, Button},
executor,
slider::{self, Slider},
- Align, Application, Column, Command, Container, Element, Length, Row,
+ time, Align, Application, Column, Command, Container, Element, Length, Row,
Settings, Subscription, Text,
};
use std::time::{Duration, Instant};
diff --git a/examples/game_of_life/src/time.rs b/examples/game_of_life/src/time.rs
deleted file mode 100644
index 7b475ecd..00000000
--- a/examples/game_of_life/src/time.rs
+++ /dev/null
@@ -1,34 +0,0 @@
-use iced::futures;
-
-pub fn every(
- duration: std::time::Duration,
-) -> iced::Subscription<std::time::Instant> {
- 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 = std::time::Instant;
-
- 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(|_| std::time::Instant::now())
- .boxed()
- }
-}
diff --git a/examples/solar_system/Cargo.toml b/examples/solar_system/Cargo.toml
index 0555aa96..44ced729 100644
--- a/examples/solar_system/Cargo.toml
+++ b/examples/solar_system/Cargo.toml
@@ -6,7 +6,5 @@ edition = "2018"
publish = false
[dependencies]
-iced = { path = "../..", features = ["canvas", "async-std", "debug"] }
-iced_native = { path = "../../native" }
-async-std = { version = "1.0", features = ["unstable"] }
+iced = { path = "../..", features = ["canvas", "tokio", "debug"] }
rand = "0.7"
diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs
index a25e43df..98bd3b21 100644
--- a/examples/solar_system/src/main.rs
+++ b/examples/solar_system/src/main.rs
@@ -8,8 +8,8 @@
//! [1]: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations#An_animated_solar_system
use iced::{
canvas::{self, Cursor, Path, Stroke},
- executor, window, Application, Canvas, Color, Command, Element, Length,
- Point, Rectangle, Settings, Size, Subscription, Vector,
+ executor, time, window, Application, Canvas, Color, Command, Element,
+ Length, Point, Rectangle, Settings, Size, Subscription, Vector,
};
use std::time::Instant;
@@ -212,39 +212,3 @@ impl<Message> canvas::Program<Message> for State {
vec![background, system]
}
}
-
-mod time {
- use iced::futures;
- use std::time::Instant;
-
- pub fn every(duration: std::time::Duration) -> iced::Subscription<Instant> {
- 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 = Instant;
-
- 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(|_| Instant::now())
- .boxed()
- }
- }
-}
diff --git a/examples/stopwatch/Cargo.toml b/examples/stopwatch/Cargo.toml
index 1dae3b83..075aa111 100644
--- a/examples/stopwatch/Cargo.toml
+++ b/examples/stopwatch/Cargo.toml
@@ -6,7 +6,4 @@ edition = "2018"
publish = false
[dependencies]
-iced = { path = "../.." }
-iced_native = { path = "../../native" }
-iced_futures = { path = "../../futures", features = ["async-std"] }
-async-std = { version = "1.0", features = ["unstable"] }
+iced = { path = "../..", features = ["tokio"] }
diff --git a/examples/stopwatch/src/main.rs b/examples/stopwatch/src/main.rs
index 5a54ed2b..9de6d39e 100644
--- a/examples/stopwatch/src/main.rs
+++ b/examples/stopwatch/src/main.rs
@@ -1,6 +1,7 @@
use iced::{
- button, Align, Application, Button, Column, Command, Container, Element,
- HorizontalAlignment, Length, Row, Settings, Subscription, Text,
+ button, executor, time, Align, Application, Button, Column, Command,
+ Container, Element, HorizontalAlignment, Length, Row, Settings,
+ Subscription, Text,
};
use std::time::{Duration, Instant};
@@ -28,7 +29,7 @@ enum Message {
}
impl Application for Stopwatch {
- type Executor = iced_futures::executor::AsyncStd;
+ type Executor = executor::Default;
type Message = Message;
type Flags = ();
@@ -143,43 +144,6 @@ impl Application for Stopwatch {
}
}
-mod time {
- use iced::futures;
-
- pub fn every(
- duration: std::time::Duration,
- ) -> iced::Subscription<std::time::Instant> {
- 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 = std::time::Instant;
-
- 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(|_| std::time::Instant::now())
- .boxed()
- }
- }
-}
-
mod style {
use iced::{button, Background, Color, Vector};