Purify Animation API and introduce application::timed
This commit is contained in:
parent
4334923add
commit
29a19fcde1
9 changed files with 281 additions and 104 deletions
|
|
@ -18,11 +18,15 @@ use std::io;
|
|||
use std::sync::Arc;
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
iced::application(Markdown::new, Markdown::update, Markdown::view)
|
||||
.font(icon::FONT)
|
||||
.subscription(Markdown::subscription)
|
||||
.theme(Markdown::theme)
|
||||
.run()
|
||||
iced::application::timed(
|
||||
Markdown::new,
|
||||
Markdown::update,
|
||||
Markdown::subscription,
|
||||
Markdown::view,
|
||||
)
|
||||
.font(icon::FONT)
|
||||
.theme(Markdown::theme)
|
||||
.run()
|
||||
}
|
||||
|
||||
struct Markdown {
|
||||
|
|
@ -58,7 +62,7 @@ enum Message {
|
|||
ImageDownloaded(markdown::Url, Result<image::Handle, Error>),
|
||||
ToggleStream(bool),
|
||||
NextToken,
|
||||
Animate(Instant),
|
||||
Tick,
|
||||
}
|
||||
|
||||
impl Markdown {
|
||||
|
|
@ -78,7 +82,9 @@ impl Markdown {
|
|||
)
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) -> Task<Message> {
|
||||
fn update(&mut self, message: Message, now: Instant) -> Task<Message> {
|
||||
self.now = now;
|
||||
|
||||
match message {
|
||||
Message::Edit(action) => {
|
||||
let is_edit = action.is_edit();
|
||||
|
|
@ -119,7 +125,7 @@ impl Markdown {
|
|||
fade_in: Animation::new(false)
|
||||
.quick()
|
||||
.easing(animation::Easing::EaseInOut)
|
||||
.go(true),
|
||||
.go(true, self.now),
|
||||
})
|
||||
.unwrap_or_else(Image::Errored),
|
||||
);
|
||||
|
|
@ -164,11 +170,7 @@ impl Markdown {
|
|||
|
||||
Task::none()
|
||||
}
|
||||
Message::Animate(now) => {
|
||||
self.now = now;
|
||||
|
||||
Task::none()
|
||||
}
|
||||
Message::Tick => Task::none(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +232,7 @@ impl Markdown {
|
|||
});
|
||||
|
||||
if is_animating {
|
||||
window::frames().map(Message::Animate)
|
||||
window::frames().map(|_| Message::Tick)
|
||||
} else {
|
||||
Subscription::none()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue