Skip to content

Commit e97c200

Browse files
authored
Improve some docs (#126)
1 parent 0ac2851 commit e97c200

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

src/lib.rs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,23 @@ mod tweenable;
228228
#[cfg(test)]
229229
mod test_utils;
230230

231-
/// How many times to repeat a tween animation. See also: [`RepeatStrategy`].
231+
/// How many times to repeat a tweenable animation.
232+
///
233+
/// See also [`RepeatStrategy`].
234+
///
235+
/// Default: `Finite(1)`
232236
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
233237
pub enum RepeatCount {
234-
/// Run the animation N times.
238+
/// Run the animation an exact number of times.
239+
///
240+
/// The total playback duration is the tweenable animation duration times
241+
/// this number of iterations.
235242
Finite(u32),
236-
/// Run the animation for some amount of time.
243+
/// Run the animation for some duration.
244+
///
245+
/// If this duration is not a multiple of the tweenable animation duration,
246+
/// then the animation will get stopped midway through its playback,
247+
/// possibly even before finishing a single loop.
237248
For(Duration),
238249
/// Loop the animation indefinitely.
239250
Infinite,
@@ -257,13 +268,18 @@ impl From<Duration> for RepeatCount {
257268
}
258269
}
259270

260-
/// What to do when a tween animation needs to be repeated. See also
261-
/// [`RepeatCount`].
271+
/// What to do when a tween animation needs to be repeated.
262272
///
263273
/// Only applicable when [`RepeatCount`] is greater than the animation duration.
274+
///
275+
/// Default: `Repeat`.
264276
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
265277
pub enum RepeatStrategy {
266278
/// Reset the animation back to its starting position.
279+
///
280+
/// When playback reaches the end of the animation, it jumps directly back
281+
/// to the animation start. This can create discontinuities if the animation
282+
/// is not authored to be looping.
267283
Repeat,
268284
/// Follow a ping-pong pattern, changing the direction each time an endpoint
269285
/// is reached.
@@ -272,6 +288,9 @@ pub enum RepeatStrategy {
272288
/// iterations for the various operations where looping matters. That
273289
/// is, a 1 second animation will take 2 seconds to end up back where it
274290
/// started.
291+
///
292+
/// This strategy ensures that there's no discontinuity in the animation,
293+
/// since there's no jump.
275294
MirroredRepeat,
276295
}
277296

@@ -282,6 +301,8 @@ impl Default for RepeatStrategy {
282301
}
283302

284303
/// Playback state of an animator.
304+
///
305+
/// Default: `Playing`.
285306
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
286307
pub enum AnimatorState {
287308
/// The animation is playing. This is the default state.
@@ -308,14 +329,25 @@ impl std::ops::Not for AnimatorState {
308329
}
309330

310331
/// Describe how eased value should be computed.
332+
///
333+
/// This function is applied to the animation fraction `t` representing the
334+
/// playback position over the animation duration. The result is used to
335+
/// interpolate the animator target.
336+
///
337+
/// In general a [`Lens`] should perform a linear interpolation over its target,
338+
/// and the non-linear behavior (for example, bounciness, etc.) comes from this
339+
/// function. This ensures the same [`Lens`] can be reused in multiple contexts,
340+
/// while the "shape" of the animation is controlled independently.
341+
///
342+
/// Default: `Linear`.
311343
#[derive(Clone, Copy)]
312344
pub enum EaseMethod {
313-
/// Follow `EaseFunction`.
345+
/// Follow [`EaseFunction`].
314346
EaseFunction(EaseFunction),
315-
/// Linear interpolation, with no function.
347+
/// Linear interpolation.
316348
Linear,
317-
/// Discrete interpolation, eased value will jump from start to end when
318-
/// stepping over the discrete limit.
349+
/// Discrete interpolation. The eased value will jump from start to end when
350+
/// stepping over the discrete limit, which must be value between 0 and 1.
319351
Discrete(f32),
320352
/// Use a custom function to interpolate the value.
321353
CustomFunction(fn(f32) -> f32),
@@ -367,6 +399,8 @@ impl From<EaseFunction> for EaseMethod {
367399
/// value set. When using [`RepeatStrategy::MirroredRepeat`], this is either
368400
/// forward (from start to end; ping) or backward (from end to start; pong),
369401
/// depending on the current iteration of the loop.
402+
///
403+
/// Default: `Forward`.
370404
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
371405
pub enum TweeningDirection {
372406
/// Animation playing from start to end.

0 commit comments

Comments
 (0)