Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom futures executor with iced_futures #164

Merged
merged 16 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,24 @@ maintenance = { status = "actively-developed" }
[workspace]
members = [
"core",
"futures",
"native",
"style",
"web",
"wgpu",
"winit",
"examples/bezier_tool",
"examples/counter",
"examples/custom_widget",
"examples/events",
"examples/geometry",
"examples/pokedex",
"examples/progress_bar",
"examples/stopwatch",
"examples/styling",
"examples/svg",
"examples/todos",
"examples/tour",
]

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand All @@ -36,19 +49,3 @@ iced_wgpu = { version = "0.1.0", path = "wgpu" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
iced_web = { version = "0.1.0", path = "web" }

[dev-dependencies]
iced_native = { version = "0.1", path = "./native" }
iced_wgpu = { version = "0.1", path = "./wgpu" }
env_logger = "0.7"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
directories = "2.0"
futures = "0.3"
async-std = { version = "1.3", features = ["unstable"] }
surf = "1.0"
rand = "0.7"
lyon = "0.15"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen = "0.2.51"
7 changes: 0 additions & 7 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,4 @@ description = "The essential concepts of Iced"
license = "MIT"
repository = "https://github.com/hecrj/iced"

[features]
# Exposes a future-based `Command` type
command = ["futures"]
# Exposes a future-based `Subscription` type
subscription = ["futures"]

[dependencies]
futures = { version = "0.3", optional = true }
12 changes: 0 additions & 12 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,3 @@ pub use length::Length;
pub use point::Point;
pub use rectangle::Rectangle;
pub use vector::Vector;

#[cfg(feature = "command")]
mod command;

#[cfg(feature = "command")]
pub use command::Command;

#[cfg(feature = "subscription")]
pub mod subscription;

#[cfg(feature = "subscription")]
pub use subscription::Subscription;
74 changes: 61 additions & 13 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ you want to learn about a specific release, check out [the release list].

[the release list]: https://github.com/hecrj/iced/releases

## [Tour](tour.rs)

## [Tour](tour)
A simple UI tour that can run both on native platforms and the web! It showcases different widgets that can be built using Iced.

The __[`tour`]__ file contains all the code of the example! All the cross-platform GUI is defined in terms of __state__, __messages__, __update logic__ and __view logic__.
The __[`main`](tour/src/main.rs)__ file contains all the code of the example! All the cross-platform GUI is defined in terms of __state__, __messages__, __update logic__ and __view logic__.

<div align="center">
<a href="https://gfycat.com/politeadorableiberianmole">
<img src="https://thumbs.gfycat.com/PoliteAdorableIberianmole-small.gif">
</a>
</div>

[`tour`]: tour.rs
[`iced_winit`]: ../winit
[`iced_native`]: ../native
[`iced_wgpu`]: ../wgpu
Expand All @@ -26,19 +24,17 @@ The __[`tour`]__ file contains all the code of the example! All the cross-platfo

You can run the native version with `cargo run`:
```
cargo run --example tour
cargo run --package tour
```

The web version can be run by following [the usage instructions of `iced_web`] or by accessing [iced.rs](https://iced.rs/)!

[the usage instructions of `iced_web`]: ../web#usage

## [Todos](todos)
A todos tracker inspired by [TodoMVC]. It showcases dynamic layout, text input, checkboxes, scrollables, icons, and async actions! It automatically saves your tasks in the background, even if you did not finish typing them.

## [Todos](todos.rs)

A simple todos tracker inspired by [TodoMVC]. It showcases dynamic layout, text input, checkboxes, scrollables, icons, and async actions! It automatically saves your tasks in the background, even if you did not finish typing them.

All the example code is located in the __[`todos`]__ file.
The example code is located in the __[`main`](todos/src/main.rs)__ file.

<div align="center">
<a href="https://gfycat.com/littlesanehalicore">
Expand All @@ -48,15 +44,67 @@ All the example code is located in the __[`todos`]__ file.

You can run the native version with `cargo run`:
```
cargo run --example todos
cargo run --package todos
```
We have not yet implemented a `LocalStorage` version of the auto-save feature. Therefore, it does not work on web _yet_!

[`todos`]: todos.rs
[TodoMVC]: http://todomvc.com/

## [Coffee]
## [Pokédex](pokedex)
An application that helps you learn about Pokémon! It performs an asynchronous HTTP request to the [PokéAPI] in order to load and display a random Pokédex entry (sprite included!).

The example code can be found in the __[`main`](pokedex/src/main.rs)__ file.

<div align="center">
<a href="https://gfycat.com/aggressivedarkelephantseal-rust-gui">
<img src="https://thumbs.gfycat.com/AggressiveDarkElephantseal-small.gif" height="400px">
</a>
</div>

You can run it on native platforms with `cargo run`:
```
cargo run --package pokedex
```

[PokéAPI]: https://pokeapi.co/

## [Styling](styling)
An example showcasing custom styling with a light and dark theme.

The example code is located in the __[`main`](styling/src/main.rs)__ file.

<div align="center">
<a href="https://user-images.githubusercontent.com/518289/71867993-acff4300-310c-11ea-85a3-d01d8f884346.gif">
<img src="https://user-images.githubusercontent.com/518289/71867993-acff4300-310c-11ea-85a3-d01d8f884346.gif" height="400px">
</a>
</div>

You can run it with `cargo run`:
```
cargo run --package styling
```

## Extras
A bunch of simpler examples exist:

- [`bezier_tool`](bezier_tool), a Paint-like tool for drawing Bezier curves using [`lyon`].
- [`counter`](counter), the classic counter example explained in the [`README`](../README.md).
- [`custom_widget`](custom_widget), a demonstration of how to build a custom widget that draws a circle.
- [`events`](events), a log of native events displayed using a conditional `Subscription`.
- [`geometry`](geometry), a custom widget showcasing how to draw geometry with the `Mesh2D` primitive in [`iced_wgpu`](../wgpu).
- [`progress_bar`](progress_bar), a simple progress bar that can be filled by using a slider.
- [`stopwatch`](stopwatch), a watch with start/stop and reset buttons showcasing how to listen to time.
- [`svg`](svg), an application that renders the [Ghostscript Tiger] by leveraging the `Svg` widget.

All of them are packaged in their own crate and, therefore, can be run using `cargo`:
```
cargo run --package <example>
```

[`lyon`]: https://github.com/nical/lyon
[Ghostscript Tiger]: https://commons.wikimedia.org/wiki/File:Ghostscript_Tiger.svg

## [Coffee]
Since [Iced was born in May], it has been powering the user interfaces in
[Coffee], an experimental 2D game engine.

Expand Down
12 changes: 12 additions & 0 deletions examples/bezier_tool/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "bezier_tool"
version = "0.1.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2018"
publish = false

[dependencies]
iced = { path = "../.." }
iced_native = { path = "../../native" }
iced_wgpu = { path = "../../wgpu" }
lyon = "0.15"
File renamed without changes.
9 changes: 9 additions & 0 deletions examples/counter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "counter"
version = "0.1.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2018"
publish = false

[dependencies]
iced = { path = "../.." }
File renamed without changes.
11 changes: 11 additions & 0 deletions examples/custom_widget/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "custom_widget"
version = "0.1.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2018"
publish = false

[dependencies]
iced = { path = "../.." }
iced_native = { path = "../../native" }
iced_wgpu = { path = "../../wgpu" }
File renamed without changes.
10 changes: 10 additions & 0 deletions examples/events/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "events"
version = "0.1.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2018"
publish = false

[dependencies]
iced = { path = "../.." }
iced_native = { path = "../../native" }
5 changes: 3 additions & 2 deletions examples/events.rs → examples/events/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use iced::{
Align, Application, Checkbox, Column, Command, Container, Element, Length,
Settings, Subscription, Text,
executor, Align, Application, Checkbox, Column, Command, Container,
Element, Length, Settings, Subscription, Text,
};

pub fn main() {
Expand All @@ -20,6 +20,7 @@ enum Message {
}

impl Application for Events {
type Executor = executor::Default;
type Message = Message;

fn new() -> (Events, Command<Message>) {
Expand Down
11 changes: 11 additions & 0 deletions examples/geometry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "geometry"
version = "0.1.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2018"
publish = false

[dependencies]
iced = { path = "../.." }
iced_native = { path = "../../native" }
iced_wgpu = { path = "../../wgpu" }
File renamed without changes.
14 changes: 14 additions & 0 deletions examples/pokedex/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "pokedex"
version = "0.1.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2018"
publish = false

[dependencies]
iced = { path = "../.." }
iced_futures = { path = "../../futures", features = ["async-std"] }
surf = "1.0"
rand = "0.7"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
17 changes: 17 additions & 0 deletions examples/pokedex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Pokédex
An application that loads a random Pokédex entry using the [PokéAPI].

All the example code can be found in the __[`main`](src/main.rs)__ file.

<div align="center">
<a href="https://gfycat.com/aggressivedarkelephantseal-rust-gui">
<img src="https://thumbs.gfycat.com/AggressiveDarkElephantseal-small.gif" height="400px">
</a>
</div>

You can run it on native platforms with `cargo run`:
```
cargo run --package pokedex
```

[PokéAPI]: https://pokeapi.co/
5 changes: 3 additions & 2 deletions examples/pokedex.rs → examples/pokedex/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use iced::{
button, image, Align, Application, Button, Column, Command, Container,
Element, Image, Length, Row, Settings, Text,
button, futures, image, Align, Application, Button, Column, Command,
Container, Element, Image, Length, Row, Settings, Text,
};

pub fn main() {
Expand All @@ -27,6 +27,7 @@ enum Message {
}

impl Application for Pokedex {
type Executor = iced_futures::executor::AsyncStd;
type Message = Message;

fn new() -> (Pokedex, Command<Message>) {
Expand Down
9 changes: 9 additions & 0 deletions examples/progress_bar/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "progress_bar"
version = "0.1.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2018"
publish = false

[dependencies]
iced = { path = "../.." }
File renamed without changes.
12 changes: 12 additions & 0 deletions examples/stopwatch/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "stopwatch"
version = "0.1.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
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"] }
5 changes: 4 additions & 1 deletion examples/stopwatch.rs → examples/stopwatch/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ enum Message {
}

impl Application for Stopwatch {
type Executor = iced_futures::executor::AsyncStd;
type Message = Message;

fn new() -> (Stopwatch, Command<Message>) {
Expand Down Expand Up @@ -142,6 +143,8 @@ impl Application for Stopwatch {
}

mod time {
use iced::futures;

pub fn every(
duration: std::time::Duration,
) -> iced::Subscription<std::time::Instant> {
Expand All @@ -165,7 +168,7 @@ mod time {

fn stream(
self: Box<Self>,
_input: I,
_input: futures::stream::BoxStream<'static, I>,
) -> futures::stream::BoxStream<'static, Self::Output> {
use futures::stream::StreamExt;

Expand Down
9 changes: 9 additions & 0 deletions examples/styling/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "styling"
version = "0.1.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2018"
publish = false

[dependencies]
iced = { path = "../.." }
15 changes: 15 additions & 0 deletions examples/styling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Styling
An example showcasing custom styling with a light and dark theme.

All the example code is located in the __[`main`](src/main.rs)__ file.

<div align="center">
<a href="https://user-images.githubusercontent.com/518289/71867993-acff4300-310c-11ea-85a3-d01d8f884346.gif">
<img src="https://user-images.githubusercontent.com/518289/71867993-acff4300-310c-11ea-85a3-d01d8f884346.gif" height="400px">
</a>
</div>

You can run it with `cargo run`:
```
cargo run --package styling
```
File renamed without changes.
Loading