diff options
author | 2020-02-12 04:00:13 +0100 | |
---|---|---|
committer | 2020-02-12 04:00:13 +0100 | |
commit | 4777f5d787e262aa9093a3099ae62be2b8c0c82f (patch) | |
tree | 667d0a00058eccd4ab445ffecbfba9ee85321714 /examples/clock | |
parent | f436f20eb86b2324126a54d4164b4cedf2134a45 (diff) | |
download | iced-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.rs | 20 |
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, |