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>
impl<T: PropertyValue> Property<T>
pub fn new_from_untyped(untyped: UntypedProperty) -> Self
Sourcepub fn computed(
evaluator: impl Fn() -> T + 'static,
dependents: &[UntypedProperty],
) -> Self
pub fn computed( evaluator: impl Fn() -> T + 'static, dependents: &[UntypedProperty], ) -> Self
Creates a computed property from an evaluator and dependency list.
Sourcepub fn computed_with_cutoff(
evaluator: impl Fn() -> T + 'static,
dependents: &[UntypedProperty],
cutoff: impl Fn(&T, &T) -> bool + 'static,
) -> Self
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.
Sourcepub fn new_with_name(val: T, name: &str) -> Self
pub fn new_with_name(val: T, name: &str) -> Self
Creates a named literal property, useful for diagnostics.
Sourcepub fn computed_with_name(
evaluator: impl Fn() -> T + 'static,
dependents: &[UntypedProperty],
name: &str,
) -> Self
pub fn computed_with_name( evaluator: impl Fn() -> T + 'static, dependents: &[UntypedProperty], name: &str, ) -> Self
Creates a named computed property, useful for diagnostics.
Sourcepub fn computed_with_cutoff_and_name(
evaluator: impl Fn() -> T + 'static,
dependents: &[UntypedProperty],
cutoff: impl Fn(&T, &T) -> bool + 'static,
name: &str,
) -> Self
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.
Sourcepub fn ease_to<D: Into<Duration>>(
&self,
end_val: T,
duration: D,
curve: EasingCurve,
)
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.
Sourcepub fn ease_to_later<D: Into<Duration>>(
&self,
end_val: T,
duration: D,
curve: EasingCurve,
)
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.
Sourcepub fn cancel_transitions(&self)
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.
Sourcepub fn get(&self) -> T
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
Sourcepub fn set(&self, val: T)
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
Sourcepub fn set_if_neq(&self, val: T) -> boolwhere
T: PartialEq,
pub fn set_if_neq(&self, val: T) -> boolwhere
T: PartialEq,
Sets the value only when it differs from the current one.
Returns true when the write changed the property and dirtied dependents.
Sourcepub fn update(&self, f: impl FnOnce(&mut T))
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
Sourcepub fn read<V>(&self, f: impl FnOnce(&T) -> V) -> V
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.
Sourcepub fn replace_with(&self, target: Property<T>)
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.
Sourcepub fn untyped(&self) -> UntypedProperty
pub fn untyped(&self) -> UntypedProperty
Casts this property to its untyped version.
Trait Implementations§
Source§impl<T: PropertyValue> Default for Property<T>
impl<T: PropertyValue> Default for Property<T>
Source§impl<'de, T: PropertyValue + Deserialize<'de>> Deserialize<'de> for Property<T>
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>,
fn deserialize<D>(deserializer: D) -> Result<Property<T>, D::Error>where
D: Deserializer<'de>,
Source§impl<T: PropertyValue> Interpolatable for Property<T>
impl<T: PropertyValue> Interpolatable for Property<T>
Source§fn interpolate(&self, other: &Self, t: f64) -> Self
fn interpolate(&self, other: &Self, t: f64) -> Self
Source§impl<T: ToPaxValue + PropertyValue> ToPaxValue for Property<T>
impl<T: ToPaxValue + PropertyValue> ToPaxValue for Property<T>
Source§fn to_pax_value(self) -> PaxValue
fn to_pax_value(self) -> PaxValue
PaxValue.