summaryrefslogtreecommitdiffstats
path: root/examples/clock
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-12 04:00:13 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-12 04:00:13 +0100
commit4777f5d787e262aa9093a3099ae62be2b8c0c82f (patch)
tree667d0a00058eccd4ab445ffecbfba9ee85321714 /examples/clock
parentf436f20eb86b2324126a54d4164b4cedf2134a45 (diff)
downloadiced-4777f5d787e262aa9093a3099ae62be2b8c0c82f.tar.gz
iced-4777f5d787e262aa9093a3099ae62be2b8c0c82f.tar.bz2
iced-4777f5d787e262aa9093a3099ae62be2b8c0c82f.zip
Remove unnecessary `Arc` from `clock` example
Diffstat (limited to 'examples/clock')
-rw-r--r--examples/clock/src/main.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs
index 958846f4..dc2c06cf 100644
--- a/examples/clock/src/main.rs
+++ b/examples/clock/src/main.rs
@@ -3,14 +3,12 @@ use iced::{
Point, Settings,
};
-use std::sync::Arc;
-
pub fn main() {
Clock::run(Settings::default())
}
struct Clock {
- local_time: Arc<LocalTime>,
+ now: LocalTime,
clock: canvas::layer::Cached<LocalTime>,
}
@@ -28,7 +26,7 @@ impl Application for Clock {
(
Clock {
- local_time: Arc::new(now),
+ now,
clock: canvas::layer::Cached::new(),
},
Command::none(),
@@ -41,7 +39,15 @@ impl Application for Clock {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
- Message::Tick(local_time) => {}
+ Message::Tick(local_time) => {
+ let now = local_time.into();
+
+ if now != self.now {
+ self.now = now;
+
+ self.clock.clear();
+ }
+ }
}
Command::none()
@@ -51,12 +57,12 @@ impl Application for Clock {
Canvas::new()
.width(Length::Fill)
.height(Length::Fill)
- .push(self.clock.with(&self.local_time))
+ .push(self.clock.with(&self.now))
.into()
}
}
-#[derive(Debug)]
+#[derive(Debug, PartialEq, Eq)]
struct LocalTime {
hour: u32,
minute: u32,