Remove unnecessary Arc from clock example
This commit is contained in:
parent
f436f20eb8
commit
4777f5d787
1 changed files with 13 additions and 7 deletions
|
|
@ -3,14 +3,12 @@ use iced::{
|
||||||
Point, Settings,
|
Point, Settings,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
Clock::run(Settings::default())
|
Clock::run(Settings::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Clock {
|
struct Clock {
|
||||||
local_time: Arc<LocalTime>,
|
now: LocalTime,
|
||||||
clock: canvas::layer::Cached<LocalTime>,
|
clock: canvas::layer::Cached<LocalTime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -28,7 +26,7 @@ impl Application for Clock {
|
||||||
|
|
||||||
(
|
(
|
||||||
Clock {
|
Clock {
|
||||||
local_time: Arc::new(now),
|
now,
|
||||||
clock: canvas::layer::Cached::new(),
|
clock: canvas::layer::Cached::new(),
|
||||||
},
|
},
|
||||||
Command::none(),
|
Command::none(),
|
||||||
|
|
@ -41,7 +39,15 @@ impl Application for Clock {
|
||||||
|
|
||||||
fn update(&mut self, message: Message) -> Command<Message> {
|
fn update(&mut self, message: Message) -> Command<Message> {
|
||||||
match 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()
|
Command::none()
|
||||||
|
|
@ -51,12 +57,12 @@ impl Application for Clock {
|
||||||
Canvas::new()
|
Canvas::new()
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.height(Length::Fill)
|
.height(Length::Fill)
|
||||||
.push(self.clock.with(&self.local_time))
|
.push(self.clock.with(&self.now))
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
struct LocalTime {
|
struct LocalTime {
|
||||||
hour: u32,
|
hour: u32,
|
||||||
minute: u32,
|
minute: u32,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue