Skip to main content

SpringTarget

Trait SpringTarget 

Source
pub trait SpringTarget: 'static {
    type Output;

    // Required methods
    fn target(&self) -> f32;
    fn resolve(&self, value: f32) -> Self::Output;
}
Expand description

A value that a one-dimensional spring can target.

The spring solver works on one f32 coordinate. A target maps its value into that coordinate and maps the sampled coordinate back into the output consumed by the animator. Built-in targets are f32, Pixels, Rems, AnimationPhase and bool (which maps to 0.0 or 1.0).

§Examples

use gpui::{SpringTarget, px};

assert_eq!(px(12.).target(), 12.0);
assert_eq!(px(12.).resolve(14.0), px(14.));
assert_eq!(true.target(), 1.0);

Required Associated Types§

Source

type Output

The value that the spring animator receives.

Required Methods§

Source

fn target(&self) -> f32

Returns this target as a coordinate for the spring.

Source

fn resolve(&self, value: f32) -> Self::Output

Converts a spring coordinate into the output the animator receives.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl SpringTarget for bool

Source§

type Output = AnimationPhase

Source§

fn target(&self) -> f32

Source§

fn resolve(&self, value: f32) -> Self::Output

Source§

impl SpringTarget for f32

Source§

type Output = f32

Source§

fn target(&self) -> f32

Source§

fn resolve(&self, value: f32) -> Self::Output

Implementors§