Expand description
Dioxus Motion - Animation library for Dioxus
Provides smooth animations for web and native applications built with Dioxus. Supports both spring physics and tween-based animations with configurable parameters.
§Features
- Simplified Animatable trait - Uses standard Rust operators (
+,-,*) for math operations - High-performance optimizations - Automatic memory pooling, state machine dispatch, and resource management
- Spring physics animations with optimized integration
- Tween animations with custom easing
- Color interpolation
- Transform animations
- Configurable animation loops
- Animation sequences with atomic step management
- Single default epsilon (0.01) for consistent animation completion
- Automatic resource pool management for maximum performance
§Example
use dioxus_motion::prelude::*;
// Optional: Configure resource pools for optimal performance (recommended for production)
resource_pools::init_high_performance();
let mut value = use_motion(0.0f32);
// Basic animation - automatically uses all optimizations
value.animate_to(100.0, AnimationConfig::new(AnimationMode::Spring(Spring::default())));
// Animation with custom epsilon for fine-tuned performance (optional)
value.animate_to(
100.0,
AnimationConfig::new(AnimationMode::Spring(Spring::default()))
.with_epsilon(0.001) // Tighter threshold for high-precision animations
);
// Check if animation is running
if value.is_running() {
println!("Animation is active with current value: {}", value.get_value());
}§Creating Custom Animatable Types
The simplified Animatable trait requires only two methods and leverages standard Rust traits:
use dioxus_motion::prelude::*;
use dioxus_motion::animations::core::Animatable;
#[derive(Debug, Copy, Clone, PartialEq, Default)]
struct Point { x: f32, y: f32 }
// Implement standard math operators
impl std::ops::Add for Point {
type Output = Self;
fn add(self, other: Self) -> Self {
Self { x: self.x + other.x, y: self.y + other.y }
}
}
impl std::ops::Sub for Point {
type Output = Self;
fn sub(self, other: Self) -> Self {
Self { x: self.x - other.x, y: self.y - other.y }
}
}
impl std::ops::Mul<f32> for Point {
type Output = Self;
fn mul(self, factor: f32) -> Self {
Self { x: self.x * factor, y: self.y * factor }
}
}
// Implement Animatable with just two methods
impl Animatable for Point {
fn interpolate(&self, target: &Self, t: f32) -> Self {
*self + (*target - *self) * t
}
fn magnitude(&self) -> f32 {
(self.x * self.x + self.y * self.y).sqrt()
}
}Re-exports§
pub use animations::platform::MotionTime;pub use animations::platform::TimeProvider;pub use keyframes::Keyframe;pub use keyframes::KeyframeAnimation;pub use manager::AnimationManager;
Modules§
- animations
- keyframes
- manager
- motion
- pool
- Memory pool management for Dioxus Motion optimizations
- prelude
- sequence
AnimationSequence<T>- Optimized animation step sequences
Structs§
- Duration
- A
Durationtype to represent a span of time, typically used for system timeouts.
Functions§
- use_
motion - Creates an animation manager that continuously updates a motion state.