summaryrefslogtreecommitdiffstats
path: root/examples/todos
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-09-10 00:34:21 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-09-10 00:34:21 +0200
commitb8e5693a3089d728b4f8d4b3b0b7197202ebd732 (patch)
tree79a9f84f9920525657fbe03d53ce33bab09053d7 /examples/todos
parent956512338905bac0b156fdaf16fe3c3e07e97a84 (diff)
parenta3489e4af960388e9f73988b88df361022a654a4 (diff)
downloadiced-b8e5693a3089d728b4f8d4b3b0b7197202ebd732.tar.gz
iced-b8e5693a3089d728b4f8d4b3b0b7197202ebd732.tar.bz2
iced-b8e5693a3089d728b4f8d4b3b0b7197202ebd732.zip
Merge branch 'master' into explicit-text-caching
Diffstat (limited to 'examples/todos')
-rw-r--r--examples/todos/Cargo.toml19
-rw-r--r--examples/todos/README.md13
-rw-r--r--examples/todos/src/main.rs40
3 files changed, 34 insertions, 38 deletions
diff --git a/examples/todos/Cargo.toml b/examples/todos/Cargo.toml
index 7292f665..3c62bfbc 100644
--- a/examples/todos/Cargo.toml
+++ b/examples/todos/Cargo.toml
@@ -6,21 +6,26 @@ edition = "2021"
publish = false
[dependencies]
-iced = { path = "../..", features = ["async-std", "debug"] }
-uuid = { version = "1.0", features = ["v4", "fast-rng", "serde"] }
+iced.workspace = true
+iced.features = ["async-std", "debug"]
+
+once_cell.workspace = true
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
-once_cell = "1.0"
-tracing-subscriber = "0.3"
+uuid = { version = "1.0", features = ["v4", "fast-rng", "serde"] }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
-async-std = "1.0"
+async-std.workspace = true
directories-next = "2.0"
+tracing-subscriber = "0.3"
[target.'cfg(target_arch = "wasm32")'.dependencies]
+iced.workspace = true
+iced.features = ["debug", "webgl"]
+
uuid = { version = "1.0", features = ["js"] }
-web-sys = { version = "0.3", features = ["Window", "Storage"] }
-wasm-timer = "0.2"
+web-sys = { workspace = true, features = ["Window", "Storage"] }
+wasm-timer.workspace = true
[package.metadata.deb]
assets = [
diff --git a/examples/todos/README.md b/examples/todos/README.md
index 9c2598b9..5e42f166 100644
--- a/examples/todos/README.md
+++ b/examples/todos/README.md
@@ -5,8 +5,8 @@ A todos tracker inspired by [TodoMVC]. It showcases dynamic layout, text input,
All the example code is located in the __[`main`]__ file.
<div align="center">
- <a href="https://gfycat.com/littlesanehalicore">
- <img src="https://thumbs.gfycat.com/LittleSaneHalicore-small.gif" height="400px">
+ <a href="https://iced.rs/examples/todos.mp4">
+ <img src="https://iced.rs/examples/todos.gif">
</a>
</div>
@@ -14,7 +14,14 @@ You can run the native version with `cargo run`:
```
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_!
+
+The web version can be run with [`trunk`]:
+
+```
+cd examples/todos
+trunk serve
+```
[`main`]: src/main.rs
[TodoMVC]: http://todomvc.com/
+[`trunk`]: https://trunkrs.dev/
diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs
index 1dd8a307..5d8936df 100644
--- a/examples/todos/src/main.rs
+++ b/examples/todos/src/main.rs
@@ -1,8 +1,6 @@
use iced::alignment::{self, Alignment};
-use iced::event::{self, Event};
use iced::font::{self, Font};
-use iced::keyboard::{self, KeyCode, Modifiers};
-use iced::subscription;
+use iced::keyboard;
use iced::theme::{self, Theme};
use iced::widget::{
self, button, checkbox, column, container, keyed_column, row, scrollable,
@@ -55,7 +53,7 @@ enum Message {
FilterChanged(Filter),
TaskMessage(usize, TaskMessage),
TabPressed { shift: bool },
- ToggleFullscreen(window::Mode),
+ ChangeWindowMode(window::Mode),
}
impl Application for Todos {
@@ -166,7 +164,7 @@ impl Application for Todos {
widget::focus_next()
}
}
- Message::ToggleFullscreen(mode) => {
+ Message::ChangeWindowMode(mode) => {
window::change_mode(mode)
}
_ => Command::none(),
@@ -267,33 +265,19 @@ impl Application for Todos {
}
fn subscription(&self) -> Subscription<Message> {
- subscription::events_with(|event, status| match (event, status) {
- (
- Event::Keyboard(keyboard::Event::KeyPressed {
- key_code: keyboard::KeyCode::Tab,
- modifiers,
- ..
+ keyboard::on_key_press(|key_code, modifiers| {
+ match (key_code, modifiers) {
+ (keyboard::KeyCode::Tab, _) => Some(Message::TabPressed {
+ shift: modifiers.shift(),
}),
- event::Status::Ignored,
- ) => Some(Message::TabPressed {
- shift: modifiers.shift(),
- }),
- (
- Event::Keyboard(keyboard::Event::KeyPressed {
- key_code,
- modifiers: Modifiers::SHIFT,
- }),
- event::Status::Ignored,
- ) => match key_code {
- KeyCode::Up => {
- Some(Message::ToggleFullscreen(window::Mode::Fullscreen))
+ (keyboard::KeyCode::Up, keyboard::Modifiers::SHIFT) => {
+ Some(Message::ChangeWindowMode(window::Mode::Fullscreen))
}
- KeyCode::Down => {
- Some(Message::ToggleFullscreen(window::Mode::Windowed))
+ (keyboard::KeyCode::Down, keyboard::Modifiers::SHIFT) => {
+ Some(Message::ChangeWindowMode(window::Mode::Windowed))
}
_ => None,
- },
- _ => None,
+ }
})
}
}