Trait zng_var::Var

source ·
pub trait Var<T: VarValue>: IntoVar<T, Var = Self> + AnyVar + Clone {
    type ReadOnly: Var<T>;
    type ActualVar: Var<T>;
    type Downgrade: WeakVar<T>;
    type Map<O: VarValue>: Var<O>;
    type MapBidi<O: VarValue>: Var<O>;
    type FlatMap<O: VarValue, V: Var<O>>: Var<O>;
    type FilterMap<O: VarValue>: Var<O>;
    type FilterMapBidi<O: VarValue>: Var<O>;
    type MapRef<O: VarValue>: Var<O>;
    type MapRefBidi<O: VarValue>: Var<O>;
    type Easing: Var<T>;

Show 68 methods // Required methods fn with<R, F>(&self, read: F) -> R where F: FnOnce(&T) -> R; fn modify<F>(&self, modify: F) -> Result<(), VarIsReadOnlyError> where F: FnOnce(&mut VarModify<'_, T>) + Send + 'static; fn actual_var(self) -> Self::ActualVar; fn downgrade(&self) -> Self::Downgrade; fn into_value(self) -> T; fn read_only(&self) -> Self::ReadOnly; fn map<O, M>(&self, map: M) -> Self::Map<O> where O: VarValue, M: FnMut(&T) -> O + Send + 'static; fn map_bidi<O, M, B>(&self, map: M, map_back: B) -> Self::MapBidi<O> where O: VarValue, M: FnMut(&T) -> O + Send + 'static, B: FnMut(&O) -> T + Send + 'static; fn flat_map<O, V, M>(&self, map: M) -> Self::FlatMap<O, V> where O: VarValue, V: Var<O>, M: FnMut(&T) -> V + Send + 'static; fn filter_map<O, M, I>(&self, map: M, fallback: I) -> Self::FilterMap<O> where O: VarValue, M: FnMut(&T) -> Option<O> + Send + 'static, I: Fn() -> O + Send + Sync + 'static; fn filter_map_bidi<O, M, B, I>( &self, map: M, map_back: B, fallback: I ) -> Self::FilterMapBidi<O> where O: VarValue, M: FnMut(&T) -> Option<O> + Send + 'static, B: FnMut(&O) -> Option<T> + Send + 'static, I: Fn() -> O + Send + Sync + 'static; fn map_ref<O, M>(&self, map: M) -> Self::MapRef<O> where O: VarValue, M: Fn(&T) -> &O + Send + Sync + 'static; fn map_ref_bidi<O, M, B>(&self, map: M, map_mut: B) -> Self::MapRefBidi<O> where O: VarValue, M: Fn(&T) -> &O + Send + Sync + 'static, B: Fn(&mut T) -> &mut O + Send + Sync + 'static; fn easing<F>(&self, duration: Duration, easing: F) -> Self::Easing where T: Transitionable, F: Fn(EasingTime) -> EasingStep + Send + Sync + 'static; fn easing_with<F, S>( &self, duration: Duration, easing: F, sampler: S ) -> Self::Easing where T: Transitionable, F: Fn(EasingTime) -> EasingStep + Send + Sync + 'static, S: Fn(&Transition<T>, EasingStep) -> T + Send + Sync + 'static; // Provided methods fn boxed(self) -> BoxedVar<T> where Self: Sized { ... } fn boxed_any(self) -> BoxedAnyVar where Self: Sized { ... } fn hook( &self, pos_modify_action: impl Fn(&VarHookArgs<'_, T>) -> bool + Send + Sync + 'static ) -> VarHandle { ... } fn wait_update(&self) -> impl Future<Output = VarUpdateId> + Send + Sync { ... } fn wait_animation(&self) -> impl Future<Output = ()> + Send + Sync { ... } fn wait_value( &self, predicate: impl Fn(&T) -> bool + Send + Sync ) -> impl Future<Output = ()> + Send + Sync { ... } fn with_new<R, F>(&self, read: F) -> Option<R> where F: FnOnce(&T) -> R { ... } fn get(&self) -> T { ... } fn get_text(&self) -> Txt where T: Display { ... } fn get_string(&self) -> String where T: Display { ... } fn get_into(&self, value: &mut T) { ... } fn get_ne(&self, value: &mut T) -> bool { ... } fn get_new(&self) -> Option<T> { ... } fn get_new_into(&self, value: &mut T) -> bool { ... } fn get_new_ne(&self, value: &mut T) -> bool { ... } fn set<I>(&self, value: I) -> Result<(), VarIsReadOnlyError> where I: Into<T> { ... } fn set_from<I>(&self, other: &I) -> Result<(), VarIsReadOnlyError> where I: Var<T> { ... } fn set_from_map<Iv, I, M>( &self, other: &I, map: M ) -> Result<(), VarIsReadOnlyError> where Iv: VarValue, I: Var<Iv>, M: FnOnce(&Iv) -> T + Send + 'static { ... } fn cow(&self) -> ArcCowVar<T, Self> { ... } fn map_into<O>(&self) -> Self::Map<O> where O: VarValue, T: Into<O> { ... } fn map_to_txt(&self) -> Self::Map<Txt> where T: ToTxt { ... } fn map_to_string(&self) -> Self::Map<String> where T: ToString { ... } fn filter_try_into<O, I>(&self, fallback: I) -> Self::FilterMap<O> where O: VarValue, T: TryInto<O>, I: Fn() -> O + Send + Sync + 'static { ... } fn filter_parse<O, I>(&self, fallback: I) -> Self::FilterMap<O> where O: VarValue + FromStr, T: AsRef<str>, I: Fn() -> O + Send + Sync + 'static { ... } fn bind_map<T2, V2, M>(&self, other: &V2, map: M) -> VarHandle where T2: VarValue, V2: Var<T2>, M: FnMut(&T) -> T2 + Send + 'static { ... } fn bind_filter_map<T2, V2, F>(&self, other: &V2, map: F) -> VarHandle where T2: VarValue, V2: Var<T2>, F: FnMut(&T) -> Option<T2> + Send + 'static { ... } fn bind_map_bidi<T2, V2, M, B>( &self, other: &V2, map: M, map_back: B ) -> VarHandles where T2: VarValue, V2: Var<T2>, M: FnMut(&T) -> T2 + Send + 'static, B: FnMut(&T2) -> T + Send + 'static { ... } fn bind_filter_map_bidi<T2, V2, M, B>( &self, other: &V2, map: M, map_back: B ) -> VarHandles where T2: VarValue, V2: Var<T2>, M: FnMut(&T) -> Option<T2> + Send + 'static, B: FnMut(&T2) -> Option<T> + Send + 'static { ... } fn bind<V2>(&self, other: &V2) -> VarHandle where V2: Var<T> { ... } fn set_bind<V2>(&self, other: &V2) -> VarHandle where V2: Var<T> { ... } fn bind_bidi<V2>(&self, other: &V2) -> VarHandles where V2: Var<T> { ... } fn trace_value<E, S>(&self, enter_value: E) -> VarHandle where E: FnMut(&TraceValueArgs<'_, T>) -> S + Send + 'static, S: Send + 'static { ... } fn animate<A>(&self, animate: A) -> AnimationHandle where A: FnMut(&Animation, &mut VarModify<'_, T>) + Send + 'static { ... } fn sequence<A>(&self, animate: A) -> VarHandle where A: FnMut(&<<Self::ActualVar as Var<T>>::Downgrade as WeakVar<T>>::Upgrade) -> AnimationHandle + Send + 'static { ... } fn set_ease<S, E, F>( &self, start_value: S, end_value: E, duration: Duration, easing: F ) -> AnimationHandle where T: Transitionable, S: Into<T>, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static { ... } fn set_ease_oci<S, E, F>( &self, start_value: S, end_value: E, duration: Duration, easing: F ) -> AnimationHandle where T: Transitionable, S: Into<T>, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static { ... } fn set_ease_with<S, E, F, Sa>( &self, start_value: S, end_value: E, duration: Duration, easing: F, sampler: Sa ) -> AnimationHandle where T: Transitionable, S: Into<T>, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static, Sa: Fn(&Transition<T>, EasingStep) -> T + Send + 'static { ... } fn set_ease_oci_with<S, E, F, Sa>( &self, start_value: S, end_value: E, duration: Duration, easing: F, sampler: Sa ) -> AnimationHandle where T: Transitionable, S: Into<T>, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static, Sa: Fn(&Transition<T>, EasingStep) -> T + Send + 'static { ... } fn ease<E, F>( &self, new_value: E, duration: Duration, easing: F ) -> AnimationHandle where T: Transitionable, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static { ... } fn ease_oci<E, F>( &self, new_value: E, duration: Duration, easing: F ) -> AnimationHandle where T: Transitionable, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static { ... } fn ease_with<E, F, S>( &self, new_value: E, duration: Duration, easing: F, sampler: S ) -> AnimationHandle where T: Transitionable, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static, S: Fn(&Transition<T>, EasingStep) -> T + Send + 'static { ... } fn ease_oci_with<E, F, S>( &self, new_value: E, duration: Duration, easing: F, sampler: S ) -> AnimationHandle where T: Transitionable, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static, S: Fn(&Transition<T>, EasingStep) -> T + Send + 'static { ... } fn set_ease_keyed<F>( &self, keys: Vec<(Factor, T)>, duration: Duration, easing: F ) -> AnimationHandle where T: Transitionable, F: Fn(EasingTime) -> EasingStep + Send + 'static { ... } fn set_ease_keyed_with<F, S>( &self, keys: Vec<(Factor, T)>, duration: Duration, easing: F, sampler: S ) -> AnimationHandle where T: Transitionable, F: Fn(EasingTime) -> EasingStep + Send + 'static, S: Fn(&TransitionKeyed<T>, EasingStep) -> T + Send + 'static { ... } fn ease_keyed<F>( &self, keys: Vec<(Factor, T)>, duration: Duration, easing: F ) -> AnimationHandle where T: Transitionable, F: Fn(EasingTime) -> EasingStep + Send + 'static { ... } fn ease_keyed_with<F, S>( &self, keys: Vec<(Factor, T)>, duration: Duration, easing: F, sampler: S ) -> AnimationHandle where T: Transitionable, F: Fn(EasingTime) -> EasingStep + Send + 'static, S: Fn(&TransitionKeyed<T>, EasingStep) -> T + Send + 'static { ... } fn step<N>(&self, new_value: N, delay: Duration) -> AnimationHandle where N: Into<T> { ... } fn step_oci<N>(&self, new_value: N, delay: Duration) -> AnimationHandle where N: Into<T> { ... } fn set_step_oci<V0, V1>( &self, from: V0, to: V1, delay: Duration ) -> AnimationHandle where V0: Into<T>, V1: Into<T> { ... } fn steps<F>( &self, steps: Vec<(Factor, T)>, duration: Duration, easing: F ) -> AnimationHandle where F: Fn(EasingTime) -> EasingStep + Send + 'static { ... } fn chase<N, F>( &self, first_target: N, duration: Duration, easing: F ) -> ChaseAnimation<T> where N: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static, T: Transitionable { ... } fn debug(&self) -> VarDebug<'_, T, Self> { ... } fn display(&self) -> VarDisplay<'_, T, Self> where T: Display { ... }
}
Expand description

Represents an observable value.

Variable types can have different capabilities, all can provide a value, in some the value can update, some are read-only others allow modifying the value. Variables can also be contextual, meaning they have a different value depending on the context where they are used. This trait covers all these capabilities, together with IntoVar<T> it enables properties to be very flexible on what input they accept.

See AnyVar for the object safe part of variables.

This trait is sealed and cannot be implemented for types outside of this crate.

Required Associated Types§

source

type ReadOnly: Var<T>

Output of Var::read_only.

source

type ActualVar: Var<T>

Output of Var::actual_var.

source

type Downgrade: WeakVar<T>

Output of Var::downgrade.

source

type Map<O: VarValue>: Var<O>

Output of Var::map.

source

type MapBidi<O: VarValue>: Var<O>

Output of Var::map_bidi.

source

type FlatMap<O: VarValue, V: Var<O>>: Var<O>

Output of Var::map_bidi.

source

type FilterMap<O: VarValue>: Var<O>

Output of Var::filter_map.

source

type FilterMapBidi<O: VarValue>: Var<O>

source

type MapRef<O: VarValue>: Var<O>

Output of Var::map_ref.

source

type MapRefBidi<O: VarValue>: Var<O>

Output of Var::map_ref_bidi.

source

type Easing: Var<T>

Output of Var::easing.

Required Methods§

source

fn with<R, F>(&self, read: F) -> R
where F: FnOnce(&T) -> R,

Visit the current value of the variable.

source

fn modify<F>(&self, modify: F) -> Result<(), VarIsReadOnlyError>
where F: FnOnce(&mut VarModify<'_, T>) + Send + 'static,

Schedule a variable update, it will be applied on the end of the current app update.

source

fn actual_var(self) -> Self::ActualVar

Gets the current inner var represented by this var. This can be the same var or a context var.

source

fn downgrade(&self) -> Self::Downgrade

Create a weak reference to this Arc variable.

source

fn into_value(self) -> T

Convert this variable to the value, if possible moves the value, if it is shared clones it.

source

fn read_only(&self) -> Self::ReadOnly

Gets a clone of the var that is always read-only.

The returned variable can still update if self is modified, but it does not have the MODIFY capability.

source

fn map<O, M>(&self, map: M) -> Self::Map<O>
where O: VarValue, M: FnMut(&T) -> O + Send + 'static,

Creates a var that maps from this variable.

The map closure is called once on initialization, and then once every time the source variable updates.

The mapping variable is read-only, you can use map_bidi to map back.

Note that the mapping var can be contextualized for context vars, meaning the map binding will initialize in the fist usage context, not the creation context, so property = CONTEXT_VAR.map(|&b|!b); will bind with the CONTEXT_VAR in the property context, not the property instantiation. The map closure itself runs in the root app context, trying to read other context variables inside it will only read the default value.

For other variables types the map can run once in the caller context.

If self can change the output variable will keep it alive, this is to support chaining maps.

source

fn map_bidi<O, M, B>(&self, map: M, map_back: B) -> Self::MapBidi<O>
where O: VarValue, M: FnMut(&T) -> O + Send + 'static, B: FnMut(&O) -> T + Send + 'static,

Create a var that maps from this variable on read and to it on write.

The map closure is called once on initialization, and then once every time the source variable updates, the map_back closure is called every time the output value is modified directly.

The mapping var can be contextualized, see Var::map for more details.

If self can change the output variable will keep it alive, this is to support chaining maps.

source

fn flat_map<O, V, M>(&self, map: M) -> Self::FlatMap<O, V>
where O: VarValue, V: Var<O>, M: FnMut(&T) -> V + Send + 'static,

Create a var that maps to an inner variable that is found inside the value of this variable.

The mapping var can be contextualized if self is contextual, otherwise map evaluates immediately to start. Note that the “mapped-to” var can be contextual even when the mapping var is not.

The mapping var has the same capabilities of the inner var, plus CAPS_CHANGE, modifying the mapping var modifies the inner var.

If self can change the output variable will keep it alive, this is to support chaining maps.

source

fn filter_map<O, M, I>(&self, map: M, fallback: I) -> Self::FilterMap<O>
where O: VarValue, M: FnMut(&T) -> Option<O> + Send + 'static, I: Fn() -> O + Send + Sync + 'static,

Creates a ref-counted var that maps from this variable, but can retain a previous mapped value.

The map closure is called once on initialization, if it returns None the fallback closure is called to generate a fallback value, after, the map closure is called once every time the mapping variable reads and is out of sync with the source variable, if it returns Some(_) the mapping variable value changes, otherwise the previous value is retained.

The mapping variable is read-only, use filter_map_bidi to map back.

The mapping var can be contextualized, see Var::map for more details.

If self can change the output variable will keep it alive, this is to support chaining maps.

source

fn filter_map_bidi<O, M, B, I>( &self, map: M, map_back: B, fallback: I ) -> Self::FilterMapBidi<O>
where O: VarValue, M: FnMut(&T) -> Option<O> + Send + 'static, B: FnMut(&O) -> Option<T> + Send + 'static, I: Fn() -> O + Send + Sync + 'static,

Create a var that maps from this variable on read and to it on write, mapping in both directions can skip updates, retaining the previous mapped value.

The map closure is called once on initialization, if it returns None the fallback closure is called to generate a fallback value, after, the map closure is called once every time the mapping variable reads and is out of sync with the source variable, if it returns Some(_) the mapping variable value changes, otherwise the previous value is retained. The map_back closure is called every time the output value is modified directly, if it returns Some(_) the source variable is set.

The mapping var can be contextualized, see Var::map for more details.

If self can change the output variable will keep it alive, this is to support chaining maps.

source

fn map_ref<O, M>(&self, map: M) -> Self::MapRef<O>
where O: VarValue, M: Fn(&T) -> &O + Send + Sync + 'static,

Create a mapping wrapper around self. The map closure is called for each value access, it must reference the value O that already exists in T.

source

fn map_ref_bidi<O, M, B>(&self, map: M, map_mut: B) -> Self::MapRefBidi<O>
where O: VarValue, M: Fn(&T) -> &O + Send + Sync + 'static, B: Fn(&mut T) -> &mut O + Send + Sync + 'static,

Create a mapping wrapper around self. The map closure is called for each value access, it must reference the value O that already exists in T, the map_mut closure is called for every modify request, it must do the same as map but with mutable access.

source

fn easing<F>(&self, duration: Duration, easing: F) -> Self::Easing
where T: Transitionable, F: Fn(EasingTime) -> EasingStep + Send + Sync + 'static,

Create a vars that ease to each new value of self.

Note that the mapping var can be contextualized, see map for more details.

If self can change the output variable will keep it alive.

source

fn easing_with<F, S>( &self, duration: Duration, easing: F, sampler: S ) -> Self::Easing
where T: Transitionable, F: Fn(EasingTime) -> EasingStep + Send + Sync + 'static, S: Fn(&Transition<T>, EasingStep) -> T + Send + Sync + 'static,

Create a vars that ease_with to each new value of self.

Note that the mapping var can be contextualized, see map for more details. If self can change the output variable will keep it alive.

Provided Methods§

source

fn boxed(self) -> BoxedVar<T>
where Self: Sized,

Gets the variable as a BoxedVar<T>, does not double box.

source

fn boxed_any(self) -> BoxedAnyVar
where Self: Sized,

Gets the variable as a BoxedAnyVar, does not double box.

source

fn hook( &self, pos_modify_action: impl Fn(&VarHookArgs<'_, T>) -> bool + Send + Sync + 'static ) -> VarHandle

Setups a callback for just after the variable value update is applied, the closure runs in the root app context, just like the modify closure. The closure can return if it is retained after each call. If you modify another variable in a hook the modification applies in the same update, variable mapping and binding is implemented using hooks.

The variable store a weak reference to the callback if it has the MODIFY or CAPS_CHANGE capabilities, otherwise the callback is discarded and VarHandle::dummy returned.

source

fn wait_update(&self) -> impl Future<Output = VarUpdateId> + Send + Sync

Awaits for the last_update to change.

Note that is_new will be true when the future elapses only when polled in sync with the UI, but it will elapse in any thread when the variable updates after the future is instantiated.

Note that outside of the UI tree there is no variable synchronization across multiple var method calls, so a sequence of get(); wait_update().await; get(); can miss a value between get and wait_update. The returned future captures the last_update at the moment this method is called, this can be leveraged by double-checking to avoid race conditions, see the wait_value default implementation for more details.

source

fn wait_animation(&self) -> impl Future<Output = ()> + Send + Sync

Awaits for is_animating to change from true to false.

If the variable is not animating at the moment of this call the future will await until the animation starts and stops.

source

fn wait_value( &self, predicate: impl Fn(&T) -> bool + Send + Sync ) -> impl Future<Output = ()> + Send + Sync

Awaits for a value that passes the predicate.

source

fn with_new<R, F>(&self, read: F) -> Option<R>
where F: FnOnce(&T) -> R,

Visit the current value of the variable, if it is_new.

source

fn get(&self) -> T

Get a clone of the current value.

source

fn get_text(&self) -> Txt
where T: Display,

Gets the value as a display Txt.

source

fn get_string(&self) -> String
where T: Display,

Gets the value as a display String.

source

fn get_into(&self, value: &mut T)

Get a clone of the current value into value.

source

fn get_ne(&self, value: &mut T) -> bool

Get a clone of the current value into value if the current value is not equal to it.

source

fn get_new(&self) -> Option<T>

Get a clone of the current value, if it is_new.

source

fn get_new_into(&self, value: &mut T) -> bool

Get a clone of the current value into value if the current value is_new.

source

fn get_new_ne(&self, value: &mut T) -> bool

Get a clone of the current value into value if the variable value is_new and not equal to the value.

source

fn set<I>(&self, value: I) -> Result<(), VarIsReadOnlyError>
where I: Into<T>,

Schedule a new value for the variable, it will be set in the end of the current app update.

source

fn set_from<I>(&self, other: &I) -> Result<(), VarIsReadOnlyError>
where I: Var<T>,

Schedule a new value for the variable, it will be set in the end of the current app update to the updated value of other, so if the other var has already scheduled an update, the updated value will be used.

This can be used in combination with binding to create a binding that starts with synchronized values.

source

fn set_from_map<Iv, I, M>( &self, other: &I, map: M ) -> Result<(), VarIsReadOnlyError>
where Iv: VarValue, I: Var<Iv>, M: FnOnce(&Iv) -> T + Send + 'static,

Set from other value at the time of update, mapped to the type of self.

source

fn cow(&self) -> ArcCowVar<T, Self>

Create a var that redirects to this variable until the first value update, then it behaves like a ArcVar<T>.

The return variable is clone-on-write and has the MODIFY capability independent of the source capabilities, when a modify request is made the source value is cloned and offered for modification, if modified the source variable is dropped and the cow var behaves like a ArcVar<T>, if the modify closure does not update the cloned value it is dropped and the cow continues to redirect to the source variable.

source

fn map_into<O>(&self) -> Self::Map<O>
where O: VarValue, T: Into<O>,

Creates a map that converts from T to O using Into<O>.

source

fn map_to_txt(&self) -> Self::Map<Txt>
where T: ToTxt,

Creates a map that converts from T to Txt using ToTxt.

source

fn map_to_string(&self) -> Self::Map<String>
where T: ToString,

Create a map that converts from T to String using ToString.

source

fn filter_try_into<O, I>(&self, fallback: I) -> Self::FilterMap<O>
where O: VarValue, T: TryInto<O>, I: Fn() -> O + Send + Sync + 'static,

Create a filter_map that tries to convert from T to O using TryInto<O>.

source

fn filter_parse<O, I>(&self, fallback: I) -> Self::FilterMap<O>
where O: VarValue + FromStr, T: AsRef<str>, I: Fn() -> O + Send + Sync + 'static,

Create a filter_map that tries to convert from T to O using FromStr.

source

fn bind_map<T2, V2, M>(&self, other: &V2, map: M) -> VarHandle
where T2: VarValue, V2: Var<T2>, M: FnMut(&T) -> T2 + Send + 'static,

Setup a hook that assigns other with the new values of self transformed by map.

Only a weak reference to the other variable is held, both variables update in the same app update cycle.

Note that the current value is not assigned, only the subsequent updates, you can use set_from_map to sync the initial value.

source

fn bind_filter_map<T2, V2, F>(&self, other: &V2, map: F) -> VarHandle
where T2: VarValue, V2: Var<T2>, F: FnMut(&T) -> Option<T2> + Send + 'static,

Setup a hook that assigns other with the new values of self transformed by map, if the closure returns a value.

Only a weak reference to the other variable is held, both variables update in the same app update cycle.

Note that the current value is not assigned, only the subsequent updates, you can assign other and then bind to fully sync the variables.

source

fn bind_map_bidi<T2, V2, M, B>( &self, other: &V2, map: M, map_back: B ) -> VarHandles
where T2: VarValue, V2: Var<T2>, M: FnMut(&T) -> T2 + Send + 'static, B: FnMut(&T2) -> T + Send + 'static,

Bind self to other and back without causing an infinite loop.

Only a weak reference to each variable is held by the other, if both variables are scheduled to update in the same cycle both get assigned, but only one bind transfer per app cycle is allowed for each variable. Returns two handles on the the map hook and one for the map-back hook.

Note that the current value is not assigned, only the subsequent updates, you can assign other and self and then bind to fully sync the variables.

source

fn bind_filter_map_bidi<T2, V2, M, B>( &self, other: &V2, map: M, map_back: B ) -> VarHandles
where T2: VarValue, V2: Var<T2>, M: FnMut(&T) -> Option<T2> + Send + 'static, B: FnMut(&T2) -> Option<T> + Send + 'static,

Bind self to other and back with the new values of self transformed by map and the new values of other transformed by map_back, the value is assigned in a update only if the closures returns a value.

Only a weak reference to each variable is held by the other, both variables update in the same app update cycle.

Note that the current value is not assigned, only the subsequent updates, you can assign other and then bind to fully sync the variables.

source

fn bind<V2>(&self, other: &V2) -> VarHandle
where V2: Var<T>,

Setup a hook that assigns other with the new values of self.

Only a weak reference to the other variable is held.

Note that the current value is not assigned, only the subsequent updates, you can use set_from to sync the initial value.

source

fn set_bind<V2>(&self, other: &V2) -> VarHandle
where V2: Var<T>,

Calls other.set_from(self) and self.bind(other).

source

fn bind_bidi<V2>(&self, other: &V2) -> VarHandles
where V2: Var<T>,

Setup two hooks that assigns other with the new values of self and self with the new values of other.

Only a weak reference to each variable is held by the other.

Note that the current value is not assigned, only the subsequent updates, you can assign other using set_from and then bind to fully sync the variables.

source

fn trace_value<E, S>(&self, enter_value: E) -> VarHandle
where E: FnMut(&TraceValueArgs<'_, T>) -> S + Send + 'static, S: Send + 'static,

Debug helper for tracing the lifetime of a value in this variable.

The enter_value closure is called every time the variable updates, it can return an implementation agnostic scope or span S that is only dropped when the variable updates again.

The enter_value is also called immediately when this method is called to start tracking the first value.

Returns a VarHandle that can be used to stop tracing.

If this variable can never update the span is immediately dropped and a dummy handle is returned. Note that the trace is set on the actual_var.

source

fn animate<A>(&self, animate: A) -> AnimationHandle
where A: FnMut(&Animation, &mut VarModify<'_, T>) + Send + 'static,

Schedule an animation that targets this variable.

If the variable is always read-only no animation is created and a dummy handle returned. The animation targets the current actual_var and is stopped if the variable is dropped.

The animate closure is called every frame, starting after next frame, the closure inputs are the Animation args and modify access to the variable value, the args can be used to calculate the new variable value and to control or stop the animation.

source

fn sequence<A>(&self, animate: A) -> VarHandle
where A: FnMut(&<<Self::ActualVar as Var<T>>::Downgrade as WeakVar<T>>::Upgrade) -> AnimationHandle + Send + 'static,

Schedule animations started by animate, the closure is called once at the start to begin, then again every time the variable stops animating.

This can be used to create a sequence of animations or to repeat an animation. The sequence stops when animate returns a dummy handle or the variable is modified outside of animate, or animations are disabled, or the returned handle is dropped.

source

fn set_ease<S, E, F>( &self, start_value: S, end_value: E, duration: Duration, easing: F ) -> AnimationHandle
where T: Transitionable, S: Into<T>, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static,

Schedule an easing transition from the start_value to end_value.

The variable updates every time the EasingStep for each frame changes and a different value is sampled.

See Var::animate for details about animations.

source

fn set_ease_oci<S, E, F>( &self, start_value: S, end_value: E, duration: Duration, easing: F ) -> AnimationHandle
where T: Transitionable, S: Into<T>, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static,

Oscillate between start_value to end_value with an easing transition.

The duration defines the easing duration between the two values.

Note that you can use Var::sequence to create more complex looping animations.

source

fn set_ease_with<S, E, F, Sa>( &self, start_value: S, end_value: E, duration: Duration, easing: F, sampler: Sa ) -> AnimationHandle
where T: Transitionable, S: Into<T>, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static, Sa: Fn(&Transition<T>, EasingStep) -> T + Send + 'static,

Schedule an easing transition from the start_value to end_value using a custom value sampler.

The variable updates every time the EasingStep for each frame changes and a different value is sampled.

See Var::animate for details about animations.

source

fn set_ease_oci_with<S, E, F, Sa>( &self, start_value: S, end_value: E, duration: Duration, easing: F, sampler: Sa ) -> AnimationHandle
where T: Transitionable, S: Into<T>, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static, Sa: Fn(&Transition<T>, EasingStep) -> T + Send + 'static,

Oscillate between start_value to end_value with an easing transition using a custom value sampler.

The duration defines the easing duration between the two values.

Note that you can use Var::sequence to create more complex looping animations.

source

fn ease<E, F>( &self, new_value: E, duration: Duration, easing: F ) -> AnimationHandle
where T: Transitionable, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static,

Schedule an easing transition from the current value to new_value.

The variable updates every time the EasingStep for each frame changes and a different value is sampled.

See Var::animate for details about animations.

source

fn ease_oci<E, F>( &self, new_value: E, duration: Duration, easing: F ) -> AnimationHandle
where T: Transitionable, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static,

Oscillate between the current value and new_value with an easing transition.

The duration defines the easing duration between the two values.

Note that you can use Var::sequence to create more complex looping animations.

source

fn ease_with<E, F, S>( &self, new_value: E, duration: Duration, easing: F, sampler: S ) -> AnimationHandle
where T: Transitionable, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static, S: Fn(&Transition<T>, EasingStep) -> T + Send + 'static,

Schedule an easing transition from the current value to new_value using a custom value sampler.

The variable updates every time the EasingStep for each frame changes and a different value is sampled.

See Var::animate for details about animations.

source

fn ease_oci_with<E, F, S>( &self, new_value: E, duration: Duration, easing: F, sampler: S ) -> AnimationHandle
where T: Transitionable, E: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static, S: Fn(&Transition<T>, EasingStep) -> T + Send + 'static,

Oscillate between the current value and new_value with an easing transition and a custom value sampler.

The duration defines the easing duration between the two values.

Note that you can use Var::sequence to create more complex looping animations.

source

fn set_ease_keyed<F>( &self, keys: Vec<(Factor, T)>, duration: Duration, easing: F ) -> AnimationHandle
where T: Transitionable, F: Fn(EasingTime) -> EasingStep + Send + 'static,

Schedule a keyframed transition animation for the variable, starting from the first key.

The variable will be set to the first keyframe, then animated across all other keys.

See Var::animate for details about animations.

source

fn set_ease_keyed_with<F, S>( &self, keys: Vec<(Factor, T)>, duration: Duration, easing: F, sampler: S ) -> AnimationHandle
where T: Transitionable, F: Fn(EasingTime) -> EasingStep + Send + 'static, S: Fn(&TransitionKeyed<T>, EasingStep) -> T + Send + 'static,

Schedule a keyframed transition animation for the variable, starting from the first key, using a custom value sampler.

The variable will be set to the first keyframe, then animated across all other keys.

See Var::animate for details about animations.

source

fn ease_keyed<F>( &self, keys: Vec<(Factor, T)>, duration: Duration, easing: F ) -> AnimationHandle
where T: Transitionable, F: Fn(EasingTime) -> EasingStep + Send + 'static,

Schedule a keyframed transition animation for the variable, starting from the current value.

The variable will be set to the first keyframe, then animated across all other keys.

See Var::animate for details about animations.

source

fn ease_keyed_with<F, S>( &self, keys: Vec<(Factor, T)>, duration: Duration, easing: F, sampler: S ) -> AnimationHandle
where T: Transitionable, F: Fn(EasingTime) -> EasingStep + Send + 'static, S: Fn(&TransitionKeyed<T>, EasingStep) -> T + Send + 'static,

Schedule a keyframed transition animation for the variable, starting from the current value, using a custom value sampler.

The variable will be set to the first keyframe, then animated across all other keys.

See Var::animate for details about animations.

source

fn step<N>(&self, new_value: N, delay: Duration) -> AnimationHandle
where N: Into<T>,

Set the variable to new_value after a delay.

The variable is_animating until the delay elapses and the value is set.

See Var::animate for details about animations.

source

fn step_oci<N>(&self, new_value: N, delay: Duration) -> AnimationHandle
where N: Into<T>,

Oscillate between the current value and new_value, every time the delay elapses the variable is set to the next value.

source

fn set_step_oci<V0, V1>( &self, from: V0, to: V1, delay: Duration ) -> AnimationHandle
where V0: Into<T>, V1: Into<T>,

Oscillate between from and to, the variable is set to from to start and every time the delay elapses the variable is set to the next value.

source

fn steps<F>( &self, steps: Vec<(Factor, T)>, duration: Duration, easing: F ) -> AnimationHandle
where F: Fn(EasingTime) -> EasingStep + Send + 'static,

Set the variable to a sequence of values as a time duration elapses.

An animation curve is used to find the first factor in steps above or at the curve line at the current time, the variable is set to this step value, continuing animating across the next steps until the last or the animation end. The variable is_animating from the start, even if no step applies and stays animating until the last step applies or the duration is reached.

§Examples

Creates a variable that outputs text every 5% of a 5 seconds animation, advanced linearly.

let steps = (0..=100).step_by(5).map(|i| (i.pct().fct(), formatx!("{i}%"))).collect();
text_var.steps(steps, 5.secs(), easing::linear)

The variable is set to "0%", after 5% of the duration elapses it is set to "5%" and so on until the value is set to "100% at the end of the animation.

Returns an AnimationHandle. See Var::animate for details about animations.

source

fn chase<N, F>( &self, first_target: N, duration: Duration, easing: F ) -> ChaseAnimation<T>
where N: Into<T>, F: Fn(EasingTime) -> EasingStep + Send + 'static, T: Transitionable,

Starts an easing animation that chases a target value that can be changed using the ChaseAnimation<T> handle.

source

fn debug(&self) -> VarDebug<'_, T, Self>

Returns a wrapper that implements fmt::Debug to write the var value.

source

fn display(&self) -> VarDisplay<'_, T, Self>
where T: Display,

Returns a wrapper that implements fmt::Display to write the var value.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<I: VarValue, O: VarValue, S: Var<I>> Var<O> for MapRef<I, O, S>

§

type ReadOnly = MapRef<I, O, S>

§

type ActualVar = MapRef<I, O, <S as Var<I>>::ActualVar>

§

type Downgrade = WeakMapRef<I, O, <S as Var<I>>::Downgrade>

§

type Map<MO: VarValue> = Box<dyn VarBoxed<MO>>

§

type MapBidi<MO: VarValue> = Box<dyn VarBoxed<MO>>

§

type FlatMap<OF: VarValue, V: Var<OF>> = Box<dyn VarBoxed<OF>>

§

type FilterMap<OF: VarValue> = Box<dyn VarBoxed<OF>>

§

type FilterMapBidi<OF: VarValue> = Box<dyn VarBoxed<OF>>

§

type MapRef<OM: VarValue> = MapRef<O, OM, MapRef<I, O, S>>

§

type MapRefBidi<OM: VarValue> = MapRef<O, OM, MapRef<I, O, S>>

§

type Easing = Box<dyn VarBoxed<O>>

source§

impl<I: VarValue, O: VarValue, S: Var<I>> Var<O> for MapRefBidi<I, O, S>

§

type ReadOnly = MapRefBidi<I, O, S>

§

type ActualVar = MapRefBidi<I, O, <S as Var<I>>::ActualVar>

§

type Downgrade = WeakMapRefBidi<I, O, <S as Var<I>>::Downgrade>

§

type Map<MO: VarValue> = ContextualizedVar<MO>

§

type MapBidi<MO: VarValue> = ContextualizedVar<MO>

§

type FlatMap<OF: VarValue, V: Var<OF>> = ContextualizedVar<OF>

§

type FilterMap<OF: VarValue> = ContextualizedVar<OF>

§

type FilterMapBidi<OF: VarValue> = ContextualizedVar<OF>

§

type MapRef<OM: VarValue> = MapRef<O, OM, MapRefBidi<I, O, S>>

§

type MapRefBidi<OM: VarValue> = MapRefBidi<O, OM, MapRefBidi<I, O, S>>

§

type Easing = ContextualizedVar<O>

source§

impl<T, V> Var<T> for ArcFlatMapVar<T, V>
where T: VarValue, V: Var<T>,

source§

impl<T: VarValue> Var<T> for ArcVar<T>

source§

impl<T: VarValue> Var<T> for ContextVar<T>

source§

impl<T: VarValue> Var<T> for LocalVar<T>

source§

impl<T: VarValue> Var<T> for ArcMergeVar<T>

source§

impl<T: VarValue> Var<T> for ArcWhenVar<T>

source§

impl<T: VarValue> Var<T> for ContextualizedVar<T>

source§

impl<T: VarValue> Var<T> for BoxedVar<T>

§

type ReadOnly = Box<dyn VarBoxed<T>>

§

type ActualVar = Box<dyn VarBoxed<T>>

§

type Downgrade = Box<dyn WeakVarBoxed<T>>

§

type Map<O: VarValue> = Box<dyn VarBoxed<O>>

§

type MapBidi<O: VarValue> = Box<dyn VarBoxed<O>>

§

type FlatMap<O: VarValue, V: Var<O>> = Box<dyn VarBoxed<O>>

§

type FilterMap<O: VarValue> = Box<dyn VarBoxed<O>>

§

type FilterMapBidi<O: VarValue> = Box<dyn VarBoxed<O>>

§

type MapRef<O: VarValue> = Box<dyn VarBoxed<O>>

§

type MapRefBidi<O: VarValue> = Box<dyn VarBoxed<O>>

§

type Easing = Box<dyn VarBoxed<T>>

source§

impl<T: VarValue, S: Var<T>> Var<T> for ArcCowVar<T, S>

§

type ReadOnly = ReadOnlyVar<T, ArcCowVar<T, S>>

§

type ActualVar = ArcCowVar<T, S>

§

type Downgrade = WeakCowVar<T, S>

§

type Map<O: VarValue> = ReadOnlyVar<O, ArcVar<O>>

§

type MapBidi<O: VarValue> = ArcVar<O>

§

type FlatMap<O: VarValue, V: Var<O>> = ArcFlatMapVar<O, V>

§

type FilterMap<O: VarValue> = ReadOnlyVar<O, ArcVar<O>>

§

type FilterMapBidi<O: VarValue> = ArcVar<O>

§

type MapRef<O: VarValue> = MapRef<T, O, ArcCowVar<T, S>>

§

type MapRefBidi<O: VarValue> = MapRefBidi<T, O, ArcCowVar<T, S>>

§

type Easing = ReadOnlyVar<T, ArcVar<T>>

source§

impl<T: VarValue, V: Var<T>> Var<T> for ReadOnlyVar<T, V>

§

type ReadOnly = ReadOnlyVar<T, V>

§

type ActualVar = <<V as Var<T>>::ActualVar as Var<T>>::ReadOnly

§

type Downgrade = WeakReadOnlyVar<T, <V as Var<T>>::Downgrade>

§

type Map<O: VarValue> = <V as Var<T>>::Map<O>

§

type MapBidi<O: VarValue> = <V as Var<T>>::Map<O>

§

type FlatMap<O: VarValue, VF: Var<O>> = <V as Var<T>>::FlatMap<O, VF>

§

type FilterMap<O: VarValue> = <V as Var<T>>::FilterMap<O>

§

type FilterMapBidi<O: VarValue> = <V as Var<T>>::FilterMap<O>

§

type MapRef<O: VarValue> = <V as Var<T>>::MapRef<O>

§

type MapRefBidi<O: VarValue> = <V as Var<T>>::MapRef<O>

§

type Easing = <<V as Var<T>>::Easing as Var<T>>::ReadOnly