Trait bevy_tweening::lens::Lens

source ·
pub trait Lens<T> {
    // Required method
    fn lerp(&mut self, target: &mut T, ratio: f32);
}
Expand description

A lens over a subset of a component.

The lens takes a target component or asset from a query, as a mutable reference, and animates (tweens) a subset of the fields of the component/asset based on the linear ratio ratio in [0:1], already sampled from the easing curve.

§Example

Implement Lens for a custom type:

struct MyLens {
  start: f32,
  end: f32,
}

#[derive(Component)]
struct MyStruct(f32);

impl Lens<MyStruct> for MyLens {
  fn lerp(&mut self, target: &mut MyStruct, ratio: f32) {
    target.0 = self.start + (self.end - self.start) * ratio;
  }
}

Required Methods§

source

fn lerp(&mut self, target: &mut T, ratio: f32)

Perform a linear interpolation (lerp) over the subset of fields of a component or asset the lens focuses on, based on the linear ratio ratio. The target component or asset is mutated in place. The implementation decides which fields are interpolated, and performs the animation in-place, overwriting the target.

Implementors§

source§

impl Lens<BackgroundColor> for UiBackgroundColorLens

source§

impl Lens<ColorMaterial> for ColorMaterialColorLens

source§

impl Lens<Sprite> for SpriteColorLens

source§

impl Lens<Style> for UiPositionLens

source§

impl Lens<Text> for TextColorLens

source§

impl Lens<Transform> for TransformPositionLens

source§

impl Lens<Transform> for TransformRotateAxisLens

source§

impl Lens<Transform> for TransformRotateXLens

source§

impl Lens<Transform> for TransformRotateYLens

source§

impl Lens<Transform> for TransformRotateZLens

source§

impl Lens<Transform> for TransformRotationLens

source§

impl Lens<Transform> for TransformScaleLens