|
1 | | -//! An animation toolkit for Iced-rs/Iced |
| 1 | +//! An animation toolkit for [Iced](https://github.com/iced-rs/iced) |
2 | 2 | //! |
3 | | -//! The goal of this project is to provide a simple API to build and show |
4 | | -//! complex animations efficiently in applications built with Iced-rs/Iced. |
| 3 | +//! > This Project was build for [Cosmic DE](https://github.com/pop-os/cosmic-epoch). Though this will work for any project that depends on [Iced](https://github.com/iced-rs/iced). |
5 | 4 | //! |
6 | | -//! # Projec Goals: |
7 | | -//! * Full compatibility with Iced and Elm Architechture |
8 | | -//! * Ease of use |
9 | | -//! * No math required for any animation |
| 5 | +//! |
| 6 | +//! The goal of this project is to provide a simple API to build and show |
| 7 | +//! complex animations efficiently in applications built with Iced-rs/Iced. |
| 8 | +//! |
| 9 | +//! # Project Goals: |
| 10 | +//! * Full compatibility with Iced and The Elm Architecture. |
| 11 | +//! * Ease of use. |
| 12 | +//! * No math required for any animation. |
10 | 13 | //! * No heap allocations in render loop. |
11 | | -//! * Provide additional animatable widgets |
12 | | -//! * Custom widget support (create your own!) |
| 14 | +//! * Provide additional animatable widgets. |
| 15 | +//! * Custom widget support (create your own!). |
13 | 16 | //! |
14 | 17 | //! # Overview |
15 | | -//! To wire cosmic-time into Iced there are four steps to do. |
| 18 | +//! To wire cosmic-time into Iced there are five steps to do. |
16 | 19 | //! |
17 | 20 | //! 1. Create a [`Timeline`] This is the type that controls the animations. |
18 | 21 | //! ```ignore |
19 | 22 | //! struct Counter { |
20 | 23 | //! timeline: Timeline |
21 | 24 | //! } |
22 | 25 | //! |
23 | | -//! // SNIP |
| 26 | +//! // ~ SNIP |
24 | 27 | //! |
25 | 28 | //! impl Application for Counter { |
26 | | -//! // SNIP |
| 29 | +//! // ~ SNIP |
27 | 30 | //! fn new(_flags: ()) -> (Self, Command<Message>) { |
28 | 31 | //! (Self { timeline: Timeline::new()}, Command::none()) |
29 | 32 | //! } |
30 | 33 | //! } |
31 | | -//! |
32 | 34 | //! ``` |
33 | 35 | //! 2. Add at least one animation to your timeline. This can be done in your |
34 | 36 | //! Application's `new()` or `update()`, or both! |
|
45 | 47 | //! ``` |
46 | 48 | //! There are some different things here! |
47 | 49 | //! > static CONTAINER: Lazy<id::Container> = Lazy::new(id::Container::unique); |
| 50 | +//! |
48 | 51 | //! Cosmic Time refers to each animation with an Id. We export our own, but they are |
49 | 52 | //! Identical to the widget Id's Iced uses for widget operations. |
50 | 53 | //! Each animatable widget needs an Id. And each Id can only refer to one animation. |
51 | 54 | //! |
52 | 55 | //! > let animation = chain![ |
| 56 | +//! |
53 | 57 | //! Cosmic Time refers to animations as [`Chain`]s because of how we build then. |
54 | 58 | //! Each Keyframe is linked together like a chain. The Cosmic Time API doesn't |
55 | 59 | //! say "change your width from 10 to 100". We define each state we want the |
|
59 | 63 | //! next state without animating though all previous Keyframes. |
60 | 64 | //! |
61 | 65 | //! > self.timeline.set_chain(animation).start(); |
| 66 | +//! |
62 | 67 | //! Then we need to add the animation to the [`Timeline`]. We call this `.set_chain`, |
63 | 68 | //! because there can only be one chain per Id. |
64 | 69 | //! If we `set_chain` with a different animation with the same Id, the first one is |
|
67 | 72 | //! `self.timeline.set_chain(animation1).set_chain(animation2).start()` |
68 | 73 | //! |
69 | 74 | //! > .start() |
| 75 | +//! |
70 | 76 | //! This one function call is important enough that we should look at it specifically. |
71 | 77 | //! Cosmic Time is atomic, given the animation state held in the [`Timeline`] at any |
72 | 78 | //! given time the global animations will be the exact same. The value used to |
|
75 | 81 | //! Say you have two 5 seconds animations running at the same time. They should end |
76 | 82 | //! at the same time right? That all depends on when the widget thinks it's animation |
77 | 83 | //! should start. `.start()` tells all pending animations to start at the moment that |
78 | | -//! `.start()` is called. This guarentees they stay in sync. |
| 84 | +//! `.start()` is called. This guarantees they stay in sync. |
79 | 85 | //! IMPORTANT! Be sure to only call `.start()` once per call to `update()`. |
80 | 86 | //! The below is incorrect! |
81 | 87 | //! ```ignore |
|
93 | 99 | //! |
94 | 100 | //! 4. Map the subscription to update the timeline's state: |
95 | 101 | //! ```ignore |
96 | | -//! use iced::Command; |
97 | 102 | //! fn update(&mut self, message: Message) -> Command<Message> { |
98 | 103 | //! match message { |
99 | 104 | //! Message::Tick(now) => self.timeline.now(now), |
|
108 | 113 | //! ``` |
109 | 114 | //! |
110 | 115 | //! All done! |
111 | | -//! There is a bit of wireing to get Cosmic Time working, but after that it's only |
| 116 | +//! There is a bit of wiring to get Cosmic Time working, but after that it's only |
112 | 117 | //! a few lines to create rather complex animations! |
113 | 118 | //! See the Pong example to see how a full game of pong can be implemented in |
114 | 119 | //! only a few lines! |
|
0 commit comments