Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve some docs #126

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 43 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,23 @@ mod tweenable;
#[cfg(test)]
mod test_utils;

/// How many times to repeat a tween animation. See also: [`RepeatStrategy`].
/// How many times to repeat a tweenable animation.
///
/// See also [`RepeatStrategy`].
///
/// Default: `Finite(1)`
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RepeatCount {
/// Run the animation N times.
/// Run the animation an exact number of times.
///
/// The total playback duration is the tweenable animation duration times
/// this number of iterations.
Finite(u32),
/// Run the animation for some amount of time.
/// Run the animation for some duration.
///
/// If this duration is not a multiple of the tweenable animation duration,
/// then the animation will get stopped midway through its playback,
/// possibly even before finishing a single loop.
For(Duration),
/// Loop the animation indefinitely.
Infinite,
Expand All @@ -257,13 +268,18 @@ impl From<Duration> for RepeatCount {
}
}

/// What to do when a tween animation needs to be repeated. See also
/// [`RepeatCount`].
/// What to do when a tween animation needs to be repeated.
///
/// Only applicable when [`RepeatCount`] is greater than the animation duration.
///
/// Default: `Repeat`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RepeatStrategy {
/// Reset the animation back to its starting position.
///
/// When playback reaches the end of the animation, it jumps directly back
/// to the animation start. This can create discontinuities if the animation
/// is not authored to be looping.
Repeat,
/// Follow a ping-pong pattern, changing the direction each time an endpoint
/// is reached.
Expand All @@ -272,6 +288,9 @@ pub enum RepeatStrategy {
/// iterations for the various operations where looping matters. That
/// is, a 1 second animation will take 2 seconds to end up back where it
/// started.
///
/// This strategy ensures that there's no discontinuity in the animation,
/// since there's no jump.
MirroredRepeat,
}

Expand All @@ -282,6 +301,8 @@ impl Default for RepeatStrategy {
}

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

/// Describe how eased value should be computed.
///
/// This function is applied to the animation fraction `t` representing the
/// playback position over the animation duration. The result is used to
/// interpolate the animator target.
///
/// In general a [`Lens`] should perform a linear interpolation over its target,
/// and the non-linear behavior (for example, bounciness, etc.) comes from this
/// function. This ensures the same [`Lens`] can be reused in multiple contexts,
/// while the "shape" of the animation is controlled independently.
///
/// Default: `Linear`.
#[derive(Clone, Copy)]
pub enum EaseMethod {
/// Follow `EaseFunction`.
/// Follow [`EaseFunction`].
EaseFunction(EaseFunction),
/// Linear interpolation, with no function.
/// Linear interpolation.
Linear,
/// Discrete interpolation, eased value will jump from start to end when
/// stepping over the discrete limit.
/// Discrete interpolation. The eased value will jump from start to end when
/// stepping over the discrete limit, which must be value between 0 and 1.
Discrete(f32),
/// Use a custom function to interpolate the value.
CustomFunction(fn(f32) -> f32),
Expand Down Expand Up @@ -367,6 +399,8 @@ impl From<EaseFunction> for EaseMethod {
/// value set. When using [`RepeatStrategy::MirroredRepeat`], this is either
/// forward (from start to end; ping) or backward (from end to start; pong),
/// depending on the current iteration of the loop.
///
/// Default: `Forward`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TweeningDirection {
/// Animation playing from start to end.
Expand Down