summaryrefslogtreecommitdiffstats
path: root/examples/stopwatch
diff options
context:
space:
mode:
Diffstat (limited to 'examples/stopwatch')
-rw-r--r--examples/stopwatch/Cargo.toml3
-rw-r--r--examples/stopwatch/README.md4
-rw-r--r--examples/stopwatch/src/main.rs20
3 files changed, 22 insertions, 5 deletions
diff --git a/examples/stopwatch/Cargo.toml b/examples/stopwatch/Cargo.toml
index f623feb9..6b1419f6 100644
--- a/examples/stopwatch/Cargo.toml
+++ b/examples/stopwatch/Cargo.toml
@@ -6,4 +6,5 @@ edition = "2021"
publish = false
[dependencies]
-iced = { path = "../..", features = ["smol"] }
+iced.workspace = true
+iced.features = ["smol"]
diff --git a/examples/stopwatch/README.md b/examples/stopwatch/README.md
index 4cf4582e..1cf370bd 100644
--- a/examples/stopwatch/README.md
+++ b/examples/stopwatch/README.md
@@ -5,9 +5,7 @@ A watch with start/stop and reset buttons showcasing how to listen to time.
The __[`main`]__ file contains all the code of the example.
<div align="center">
- <a href="https://gfycat.com/granularenviousgoitered-rust-gui">
- <img src="https://thumbs.gfycat.com/GranularEnviousGoitered-small.gif">
- </a>
+ <img src="https://iced.rs/examples/stopwatch.gif">
</div>
You can run it with `cargo run`:
diff --git a/examples/stopwatch/src/main.rs b/examples/stopwatch/src/main.rs
index 9581a3ce..0b0f0607 100644
--- a/examples/stopwatch/src/main.rs
+++ b/examples/stopwatch/src/main.rs
@@ -1,5 +1,6 @@
use iced::alignment;
use iced::executor;
+use iced::keyboard;
use iced::theme::{self, Theme};
use iced::time;
use iced::widget::{button, column, container, row, text};
@@ -77,12 +78,25 @@ impl Application for Stopwatch {
}
fn subscription(&self) -> Subscription<Message> {
- match self.state {
+ let tick = match self.state {
State::Idle => Subscription::none(),
State::Ticking { .. } => {
time::every(Duration::from_millis(10)).map(Message::Tick)
}
+ };
+
+ fn handle_hotkey(
+ key_code: keyboard::KeyCode,
+ _modifiers: keyboard::Modifiers,
+ ) -> Option<Message> {
+ match key_code {
+ keyboard::KeyCode::Space => Some(Message::Toggle),
+ keyboard::KeyCode::R => Some(Message::Reset),
+ _ => None,
+ }
}
+
+ Subscription::batch(vec![tick, keyboard::on_key_press(handle_hotkey)])
}
fn view(&self) -> Element<Message> {
@@ -134,4 +148,8 @@ impl Application for Stopwatch {
.center_y()
.into()
}
+
+ fn theme(&self) -> Theme {
+ Theme::Dark
+ }
}