i_slint_core

Struct Property

Source
#[repr(C)]
pub struct Property<T> { /* private fields */ }
Expand description

A Property that allow binding that track changes

Property van have be assigned value, or bindings. When a binding is assigned, it is lazily evaluated on demand when calling get(). When accessing another property from a binding evaluation, a dependency will be registered, such that when the property change, the binding will automatically be updated

Implementations§

Source§

impl<T: Clone + InterpolatedPropertyValue + 'static> Property<T>

Source

pub fn set_animated_value(&self, value: T, animation_data: PropertyAnimation)

Change the value of this property, by animating (interpolating) from the current property’s value to the specified parameter value. The animation is done according to the parameters described by the PropertyAnimation object.

If other properties have binding depending of this property, these properties will be marked as dirty.

Source

pub fn set_animated_binding( &self, binding: impl Binding<T> + 'static, animation_data: PropertyAnimation, )

Set a binding to this property.

Source

pub fn set_animated_binding_for_transition( &self, binding: impl Binding<T> + 'static, compute_animation_details: impl Fn() -> (PropertyAnimation, Instant) + 'static, )

Set a binding to this property, providing a callback for the transition animation

Source§

impl<T: Clone> Property<T>

Source

pub fn new(value: T) -> Self

Create a new property with this value

Source

pub fn new_named(value: T, _name: &'static str) -> Self

Same as Self::new but with a ’static string use for debugging only

Source

pub fn get(self: Pin<&Self>) -> T

Get the value of the property

This may evaluate the binding if there is a binding and it is dirty

If the function is called directly or indirectly from a binding evaluation of another Property, a dependency will be registered.

Panics if this property is get while evaluating its own binding or cloning the value.

Source

pub fn get_untracked(self: Pin<&Self>) -> T

Same as get() but without registering a dependency

This allow to optimize bindings that know that they might not need to re_evaluate themselves when the property change or that have registered the dependency in another way.

§Example
use std::rc::Rc;
use i_slint_core::Property;
let prop1 = Rc::pin(Property::new(100));
let prop2 = Rc::pin(Property::<i32>::default());
prop2.as_ref().set_binding({
    let prop1 = prop1.clone(); // in order to move it into the closure.
    move || { prop1.as_ref().get_untracked() + 30 }
});
assert_eq!(prop2.as_ref().get(), 130);
prop1.set(200);
// changing prop1 do not affect the prop2 binding because no dependency was registered
assert_eq!(prop2.as_ref().get(), 130);
Source

pub fn set(&self, t: T)
where T: PartialEq,

Change the value of this property

If other properties have binding depending of this property, these properties will be marked as dirty.

Source

pub fn set_binding(&self, binding: impl Binding<T> + 'static)

Set a binding to this property.

Bindings are evaluated lazily from calling get, and the return value of the binding is the new value.

If other properties have bindings depending of this property, these properties will be marked as dirty.

Closures of type Fn()->T implements Binding<T> and can be used as a binding

§Example
use std::rc::Rc;
use i_slint_core::Property;
let prop1 = Rc::pin(Property::new(100));
let prop2 = Rc::pin(Property::<i32>::default());
prop2.as_ref().set_binding({
    let prop1 = prop1.clone(); // in order to move it into the closure.
    move || { prop1.as_ref().get() + 30 }
});
assert_eq!(prop2.as_ref().get(), 130);
prop1.set(200);
// A change in prop1 forced the binding on prop2 to re_evaluate
assert_eq!(prop2.as_ref().get(), 230);
Source

pub fn is_dirty(&self) -> bool

Any of the properties accessed during the last evaluation of the closure called from the last call to evaluate is potentially dirty.

Source

pub fn mark_dirty(&self)

Internal function to mark the property as dirty and notify dependencies, regardless of whether the property value has actually changed or not.

Source

pub fn set_constant(&self)

Mark that this property will never be modified again and that no tracking should be done

Source§

impl<T: PartialEq + Clone + 'static> Property<T>

Link two property such that any change to one property is affecting the other property as if they where, in fact, a single property. The value or binding of prop2 is kept.

Trait Implementations§

Source§

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

Source§

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

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

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

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> !Freeze for Property<T>

§

impl<T> !RefUnwindSafe for Property<T>

§

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

§

impl<T> !Sync for Property<T>

§

impl<T> !Unpin for Property<T>

§

impl<T> UnwindSafe for Property<T>
where T: UnwindSafe,

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> 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, 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.