Skip to main content

MotionExpr

Enum MotionExpr 

Source
pub enum MotionExpr {
Show 21 variants Value(MotionValue), IntrinsicWidth, IntrinsicHeight, LayoutX(WidgetId), LayoutY(WidgetId), LayoutWidth(WidgetId), LayoutHeight(WidgetId), PointerLocalX, PointerLocalY, If { predicate: MotionPredicate, then_expr: Box<MotionExpr>, else_expr: Box<MotionExpr>, }, Add(Box<MotionExpr>, Box<MotionExpr>), Sub(Box<MotionExpr>, Box<MotionExpr>), Mul(Box<MotionExpr>, Box<MotionExpr>), Div(Box<MotionExpr>, Box<MotionExpr>), Neg(Box<MotionExpr>), Abs(Box<MotionExpr>), Min(Box<MotionExpr>, Box<MotionExpr>), Max(Box<MotionExpr>, Box<MotionExpr>), Clamp { value: Box<MotionExpr>, min: Box<MotionExpr>, max: Box<MotionExpr>, }, Lerp { from: Box<MotionExpr>, to: Box<MotionExpr>, t: Box<MotionExpr>, }, MapRange { value: Box<MotionExpr>, from_start: f32, from_end: f32, to_start: f32, to_end: f32, clamp: bool, },
}
Expand description

Declarative expression evaluated by the motion runtime.

Expressions are the closed IR for motion targets. They can reference layout snapshots, pointer position, interaction predicates, and numeric operators without requiring arbitrary per-frame callbacks.

use fission::motion::{
    scalar, MotionExpr, MotionPredicate, MotionPropertyId, MotionStartValue, MotionTrack,
};
use fission::WidgetId;

let button_id = WidgetId::explicit("save_button");
let scale = MotionTrack::composite(
    MotionPropertyId::Scale,
    MotionStartValue::Current,
    MotionExpr::If {
        predicate: MotionPredicate::Pressed(button_id),
        then_expr: Box::new(scalar(0.96)),
        else_expr: Box::new(scalar(1.0)),
    },
);

Variants§

§

Value(MotionValue)

Literal typed value.

§

IntrinsicWidth

Current widget intrinsic width.

§

IntrinsicHeight

Current widget intrinsic height.

§

LayoutX(WidgetId)

X position of another widget from the latest layout snapshot.

§

LayoutY(WidgetId)

Y position of another widget from the latest layout snapshot.

§

LayoutWidth(WidgetId)

Width of another widget from the latest layout snapshot.

§

LayoutHeight(WidgetId)

Height of another widget from the latest layout snapshot.

§

PointerLocalX

Pointer x-position local to the tracked widget.

§

PointerLocalY

Pointer y-position local to the tracked widget.

§

If

Conditional expression selected by a runtime predicate.

Fields

§predicate: MotionPredicate

Runtime predicate to test.

§then_expr: Box<MotionExpr>

Expression evaluated when the predicate is true.

§else_expr: Box<MotionExpr>

Expression evaluated when the predicate is false.

§

Add(Box<MotionExpr>, Box<MotionExpr>)

Numeric addition.

§

Sub(Box<MotionExpr>, Box<MotionExpr>)

Numeric subtraction.

§

Mul(Box<MotionExpr>, Box<MotionExpr>)

Numeric multiplication.

§

Div(Box<MotionExpr>, Box<MotionExpr>)

Numeric division. Division by zero leaves the left value unchanged.

§

Neg(Box<MotionExpr>)

Numeric negation.

§

Abs(Box<MotionExpr>)

Absolute value.

§

Min(Box<MotionExpr>, Box<MotionExpr>)

Minimum of two scalar-like expressions.

§

Max(Box<MotionExpr>, Box<MotionExpr>)

Maximum of two scalar-like expressions.

§

Clamp

Clamps a scalar-like expression between min and max.

Fields

§value: Box<MotionExpr>

Value to clamp.

§min: Box<MotionExpr>

Minimum allowed value.

§max: Box<MotionExpr>

Maximum allowed value.

§

Lerp

Interpolates between two values using scalar-like t.

Fields

§from: Box<MotionExpr>

Start expression.

§to: Box<MotionExpr>

End expression.

§t: Box<MotionExpr>

Interpolation progress, normally 0.0..=1.0.

§

MapRange

Maps a scalar-like expression from one range to another.

Fields

§value: Box<MotionExpr>

Source expression.

§from_start: f32

Lower bound of the input range.

§from_end: f32

Upper bound of the input range.

§to_start: f32

Lower bound of the output range.

§to_end: f32

Upper bound of the output range.

§clamp: bool

Whether to clamp the mapped progress to 0.0..=1.0.

Implementations§

Source§

impl MotionExpr

Source

pub fn eval(&self, input: &MotionEvalInput<'_>) -> MotionValue

Evaluates the expression against runtime and layout inputs.

Application code usually does not call this directly; shells and tests use it to turn declarative targets into concrete MotionValues.

Trait Implementations§

Source§

impl Clone for MotionExpr

Source§

fn clone(&self) -> MotionExpr

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MotionExpr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for MotionExpr

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<MotionValue> for MotionExpr

Source§

fn from(value: MotionValue) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for MotionExpr

Source§

fn eq(&self, other: &MotionExpr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for MotionExpr

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for MotionExpr

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.