22//!
33//! # Predefined lenses
44//!
5- //! This module contains predefined lenses for common use cases. Those lenses are
6- //! entirely optional. They can be used if they fit your use case, to save some time,
7- //! but are not treated any differently from a custom user-provided lens.
5+ //! This module contains predefined lenses for common use cases. Those lenses
6+ //! are entirely optional. They can be used if they fit your use case, to save
7+ //! some time, but are not treated any differently from a custom user-provided
8+ //! lens.
89//!
910//! # Rotations
1011//!
1112//! Several rotation lenses are provided, with different properties.
1213//!
1314//! ## Shortest-path rotation
1415//!
15- //! The [`TransformRotationLens`] animates the [`rotation`] field of a [`Transform`]
16- //! component using [`Quat::slerp()`]. It inherits the properties of that method, and
17- //! in particular the fact it always finds the "shortest path" from start to end. This
18- //! is well suited for animating a rotation between two given directions, but will
19- //! provide unexpected results if you try to make an entity rotate around a given axis
20- //! for more than half a turn, as [`Quat::slerp()`] will then try to move "the other
21- //! way around".
16+ //! The [`TransformRotationLens`] animates the [`rotation`] field of a
17+ //! [`Transform`] component using [`Quat::slerp()`]. It inherits the properties
18+ //! of that method, and in particular the fact it always finds the "shortest
19+ //! path" from start to end. This is well suited for animating a rotation
20+ //! between two given directions, but will provide unexpected results if you try
21+ //! to make an entity rotate around a given axis for more than half a turn, as
22+ //! [`Quat::slerp()`] will then try to move "the other way around".
2223//!
2324//! ## Angle-focused rotations
2425//!
25- //! Conversely, for cases where the rotation direction is important, like when trying
26- //! to do a full 360-degree turn, a series of angle-based interpolation lenses is
27- //! provided:
26+ //! Conversely, for cases where the rotation direction is important, like when
27+ //! trying to do a full 360-degree turn, a series of angle-based interpolation
28+ //! lenses is provided:
2829//! - [`TransformRotateXLens`]
2930//! - [`TransformRotateYLens`]
3031//! - [`TransformRotateZLens`]
@@ -38,9 +39,10 @@ use bevy::prelude::*;
3839
3940/// A lens over a subset of a component.
4041///
41- /// The lens takes a `target` component or asset from a query, as a mutable reference,
42- /// and animates (tweens) a subset of the fields of the component/asset based on the
43- /// linear ratio `ratio` in \[0:1\], already sampled from the easing curve.
42+ /// The lens takes a `target` component or asset from a query, as a mutable
43+ /// reference, and animates (tweens) a subset of the fields of the
44+ /// component/asset based on the linear ratio `ratio` in \[0:1\], already
45+ /// sampled from the easing curve.
4446///
4547/// # Example
4648///
@@ -63,16 +65,17 @@ use bevy::prelude::*;
6365/// }
6466/// }
6567/// ```
66- ///
6768pub trait Lens < T > {
68- /// Perform a linear interpolation (lerp) over the subset of fields of a component
69- /// or asset the lens focuses on, based on the linear ratio `ratio`. The `target`
70- /// component or asset is mutated in place. The implementation decides which fields
71- /// are interpolated, and performs the animation in-place, overwriting the target.
69+ /// Perform a linear interpolation (lerp) over the subset of fields of a
70+ /// component or asset the lens focuses on, based on the linear ratio
71+ /// `ratio`. The `target` component or asset is mutated in place. The
72+ /// implementation decides which fields are interpolated, and performs
73+ /// the animation in-place, overwriting the target.
7274 fn lerp ( & mut self , target : & mut T , ratio : f32 ) ;
7375}
7476
75- /// A lens to manipulate the [`color`] field of a section of a [`Text`] component.
77+ /// A lens to manipulate the [`color`] field of a section of a [`Text`]
78+ /// component.
7679///
7780/// [`color`]: https://docs.rs/bevy/0.7.0/bevy/text/struct.TextStyle.html#structfield.color
7881/// [`Text`]: https://docs.rs/bevy/0.7.0/bevy/text/struct.Text.html
@@ -90,7 +93,8 @@ pub struct TextColorLens {
9093#[ cfg( feature = "bevy_ui" ) ]
9194impl Lens < Text > for TextColorLens {
9295 fn lerp ( & mut self , target : & mut Text , ratio : f32 ) {
93- // Note: Add<f32> for Color affects alpha, but not Mul<f32>. So use Vec4 for consistency.
96+ // Note: Add<f32> for Color affects alpha, but not Mul<f32>. So use Vec4 for
97+ // consistency.
9498 let start: Vec4 = self . start . into ( ) ;
9599 let end: Vec4 = self . end . into ( ) ;
96100 let value = start. lerp ( end, ratio) ;
@@ -120,13 +124,15 @@ impl Lens<Transform> for TransformPositionLens {
120124/// A lens to manipulate the [`rotation`] field of a [`Transform`] component.
121125///
122126/// This lens interpolates the [`rotation`] field of a [`Transform`] component
123- /// from a `start` value to an `end` value using the spherical linear interpolation
124- /// provided by [`Quat::slerp()`]. This means the rotation always uses the shortest
125- /// path from `start` to `end`. In particular, this means it cannot make entities
126- /// do a full 360 degrees turn. Instead use [`TransformRotateXLens`] and similar
127- /// to interpolate the rotation angle around a given axis.
127+ /// from a `start` value to an `end` value using the spherical linear
128+ /// interpolation provided by [`Quat::slerp()`]. This means the rotation always
129+ /// uses the shortest path from `start` to `end`. In particular, this means it
130+ /// cannot make entities do a full 360 degrees turn. Instead use
131+ /// [`TransformRotateXLens`] and similar to interpolate the rotation angle
132+ /// around a given axis.
128133///
129- /// See the [top-level `lens` module documentation] for a comparison of rotation lenses.
134+ /// See the [top-level `lens` module documentation] for a comparison of rotation
135+ /// lenses.
130136///
131137/// [`rotation`]: https://docs.rs/bevy/0.7.0/bevy/transform/components/struct.Transform.html#structfield.rotation
132138/// [`Transform`]: https://docs.rs/bevy/0.7.0/bevy/transform/components/struct.Transform.html
@@ -150,10 +156,11 @@ impl Lens<Transform> for TransformRotationLens {
150156///
151157/// This lens interpolates the rotation angle of a [`Transform`] component from
152158/// a `start` value to an `end` value, for a rotation around the X axis. Unlike
153- /// [`TransformRotationLens`], it can produce an animation that rotates the entity
154- /// any number of turns around its local X axis.
159+ /// [`TransformRotationLens`], it can produce an animation that rotates the
160+ /// entity any number of turns around its local X axis.
155161///
156- /// See the [top-level `lens` module documentation] for a comparison of rotation lenses.
162+ /// See the [top-level `lens` module documentation] for a comparison of rotation
163+ /// lenses.
157164///
158165/// [`Transform`]: https://docs.rs/bevy/0.7.0/bevy/transform/components/struct.Transform.html
159166/// [top-level `lens` module documentation]: crate::lens
@@ -176,10 +183,11 @@ impl Lens<Transform> for TransformRotateXLens {
176183///
177184/// This lens interpolates the rotation angle of a [`Transform`] component from
178185/// a `start` value to an `end` value, for a rotation around the Y axis. Unlike
179- /// [`TransformRotationLens`], it can produce an animation that rotates the entity
180- /// any number of turns around its local Y axis.
186+ /// [`TransformRotationLens`], it can produce an animation that rotates the
187+ /// entity any number of turns around its local Y axis.
181188///
182- /// See the [top-level `lens` module documentation] for a comparison of rotation lenses.
189+ /// See the [top-level `lens` module documentation] for a comparison of rotation
190+ /// lenses.
183191///
184192/// [`Transform`]: https://docs.rs/bevy/0.7.0/bevy/transform/components/struct.Transform.html
185193/// [top-level `lens` module documentation]: crate::lens
@@ -202,10 +210,11 @@ impl Lens<Transform> for TransformRotateYLens {
202210///
203211/// This lens interpolates the rotation angle of a [`Transform`] component from
204212/// a `start` value to an `end` value, for a rotation around the Z axis. Unlike
205- /// [`TransformRotationLens`], it can produce an animation that rotates the entity
206- /// any number of turns around its local Z axis.
213+ /// [`TransformRotationLens`], it can produce an animation that rotates the
214+ /// entity any number of turns around its local Z axis.
207215///
208- /// See the [top-level `lens` module documentation] for a comparison of rotation lenses.
216+ /// See the [top-level `lens` module documentation] for a comparison of rotation
217+ /// lenses.
209218///
210219/// [`Transform`]: https://docs.rs/bevy/0.7.0/bevy/transform/components/struct.Transform.html
211220/// [top-level `lens` module documentation]: crate::lens
@@ -227,11 +236,12 @@ impl Lens<Transform> for TransformRotateZLens {
227236/// A lens to rotate a [`Transform`] component around a given fixed axis.
228237///
229238/// This lens interpolates the rotation angle of a [`Transform`] component from
230- /// a `start` value to an `end` value, for a rotation around a given axis. Unlike
231- /// [`TransformRotationLens`], it can produce an animation that rotates the entity
232- /// any number of turns around that axis.
239+ /// a `start` value to an `end` value, for a rotation around a given axis.
240+ /// Unlike [`TransformRotationLens`], it can produce an animation that rotates
241+ /// the entity any number of turns around that axis.
233242///
234- /// See the [top-level `lens` module documentation] for a comparison of rotation lenses.
243+ /// See the [top-level `lens` module documentation] for a comparison of rotation
244+ /// lenses.
235245///
236246/// # Panics
237247///
@@ -327,7 +337,8 @@ pub struct ColorMaterialColorLens {
327337#[ cfg( feature = "bevy_sprite" ) ]
328338impl Lens < ColorMaterial > for ColorMaterialColorLens {
329339 fn lerp ( & mut self , target : & mut ColorMaterial , ratio : f32 ) {
330- // Note: Add<f32> for Color affects alpha, but not Mul<f32>. So use Vec4 for consistency.
340+ // Note: Add<f32> for Color affects alpha, but not Mul<f32>. So use Vec4 for
341+ // consistency.
331342 let start: Vec4 = self . start . into ( ) ;
332343 let end: Vec4 = self . end . into ( ) ;
333344 let value = start. lerp ( end, ratio) ;
@@ -351,7 +362,8 @@ pub struct SpriteColorLens {
351362#[ cfg( feature = "bevy_sprite" ) ]
352363impl Lens < Sprite > for SpriteColorLens {
353364 fn lerp ( & mut self , target : & mut Sprite , ratio : f32 ) {
354- // Note: Add<f32> for Color affects alpha, but not Mul<f32>. So use Vec4 for consistency.
365+ // Note: Add<f32> for Color affects alpha, but not Mul<f32>. So use Vec4 for
366+ // consistency.
355367 let start: Vec4 = self . start . into ( ) ;
356368 let end: Vec4 = self . end . into ( ) ;
357369 let value = start. lerp ( end, ratio) ;
0 commit comments