Skip to main content

Property

Struct Property 

Source
pub struct Property<T> { /* private fields */ }
Expand description

A reactive value node in Pax’s property graph.

Property<T> is the primary state and binding primitive used by generated components, PAXEL expressions, and Rust component logic.

Implementations§

Source§

impl<T: PropertyValue> Property<T>

Source

pub fn new(val: T) -> Self

Creates a literal property with an initial value.

Source

pub fn new_from_untyped(untyped: UntypedProperty) -> Self

Source

pub fn computed( evaluator: impl Fn() -> T + 'static, dependents: &[UntypedProperty], ) -> Self

Creates a computed property from an evaluator and dependency list.

Source

pub fn computed_with_cutoff( evaluator: impl Fn() -> T + 'static, dependents: &[UntypedProperty], cutoff: impl Fn(&T, &T) -> bool + 'static, ) -> Self

Creates a computed property with a propagation cutoff.

The predicate receives the last accepted value and the newly evaluated candidate. Returning true discards the candidate and stops outbound invalidation at this property; returning false accepts and propagates it. The first evaluation is always accepted.

Source

pub fn new_with_name(val: T, name: &str) -> Self

Creates a named literal property, useful for diagnostics.

Source

pub fn computed_with_name( evaluator: impl Fn() -> T + 'static, dependents: &[UntypedProperty], name: &str, ) -> Self

Creates a named computed property, useful for diagnostics.

Source

pub fn computed_with_cutoff_and_name( evaluator: impl Fn() -> T + 'static, dependents: &[UntypedProperty], cutoff: impl Fn(&T, &T) -> bool + 'static, name: &str, ) -> Self

Creates a named cutoff computed property, useful for diagnostics.

Source

pub fn ease_to<D: Into<Duration>>( &self, end_val: T, duration: D, curve: EasingCurve, )

Immediately starts an ease transition from the current value to end_val, over a duration, following curve.

Numeric arguments preserve the historical frame-based behavior. Use Duration::Milliseconds, Duration::Seconds, or Duration::Frames to select an explicit unit.

Source

pub fn ease_to_later<D: Into<Duration>>( &self, end_val: T, duration: D, curve: EasingCurve, )

Enqueues an ease transition from the current value to end_val, over a duration, following curve, which will start after all currently enqueued transitions finish.

Source

pub fn cancel_transitions(&self)

Stops the active transition and clears every queued transition segment.

The property is left at its current eased value. A subsequent Property::set can therefore take immediate ownership without the cancelled transition overwriting it on the next runtime tick.

Source

pub fn get(&self) -> T

Gets the currently stored value. Might be computationally expensive in a large reactivity network since this triggers re-evaluation of dirty property chains

Source

pub fn set(&self, val: T)

Sets this properties value and sets the dirty bit recursively of all of its dependencies if not already set

Source

pub fn set_if_neq(&self, val: T) -> bool
where T: PartialEq,

Sets the value only when it differs from the current one.

Returns true when the write changed the property and dirtied dependents.

Source

pub fn update(&self, f: impl FnOnce(&mut T))

Get access to a mutable reference to the inner value T. Will trigger updates for dependents of this property, regardless of if the value actually changed

Source

pub fn read<V>(&self, f: impl FnOnce(&T) -> V) -> V

Reads the inner value by reference.

Panics if this property is already borrowed, which can happen if read is called inside a read of the same property.

Source

pub fn replace_with(&self, target: Property<T>)

Replaces this property’s evaluator, dependencies, and value with target, while keeping dependents.

This can introduce circular dependencies if used carelessly. It is intended for changing a property from literal to computed (or vice versa) without severing existing outbound links.

Source

pub fn untyped(&self) -> UntypedProperty

Casts this property to its untyped version.

Trait Implementations§

Source§

impl<T: Clone> Clone for Property<T>

Source§

fn clone(&self) -> Self

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<T: PropertyValue + Debug> Debug for Property<T>

Source§

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

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

impl<T: PropertyValue> Default for Property<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, T: PropertyValue + Deserialize<'de>> Deserialize<'de> for Property<T>

Source§

fn deserialize<D>(deserializer: D) -> Result<Property<T>, D::Error>
where D: Deserializer<'de>,

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

impl<T: PropertyValue> Interpolatable for Property<T>

Source§

fn interpolate(&self, other: &Self, t: f64) -> Self

Interpolates this value toward other at time t on the unit interval. Read more
Source§

impl<T: PropertyValue + Serialize> Serialize for Property<T>

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<T: ToPaxValue + PropertyValue> ToPaxValue for Property<T>

Source§

fn to_pax_value(self) -> PaxValue

Converts this value into a PaxValue.

Auto Trait Implementations§

§

impl<T> Freeze for Property<T>
where PhantomData<T>: Freeze,

§

impl<T> RefUnwindSafe for Property<T>

§

impl<T> Send for Property<T>
where PhantomData<T>: Send,

§

impl<T> Sync for Property<T>
where PhantomData<T>: Sync,

§

impl<T> Unpin for Property<T>
where PhantomData<T>: Unpin,

§

impl<T> UnsafeUnpin for Property<T>

§

impl<T> UnwindSafe for Property<T>

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> 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> PropertyValue for T
where T: Default + Clone + Interpolatable + 'static,

Source§

impl<T> RoundFrom<T> for T

Source§

fn round_from(x: T) -> T

Performs the conversion.
Source§

impl<T, U> RoundInto<U> for T
where U: RoundFrom<T>,

Source§

fn round_into(self) -> U

Performs the conversion.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more